{"record":{"id":"96295329670de44b","repo":"microsoft/aspire","slug":"could-not-resolve-resource-group-for-aks-cluster-clustername","errorCode":null,"errorMessage":"Could not resolve resource group for AKS cluster '{clusterName}'. Ensure Azure provisioning has completed.","messagePattern":"Could not resolve resource group for AKS cluster '(.+?)'\\. Ensure Azure provisioning has completed\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Azure.Kubernetes/AzureKubernetesEnvironmentResource.AksPipeline.cs","lineNumber":924,"sourceCode":"\n        if (result.ExitCode != 0)\n        {\n            throw new InvalidOperationException(\n                $\"az resource list failed (exit code {result.ExitCode}): {result.StandardError}\");\n        }\n\n        // With '-o tsv' the query emits one resource group per matching cluster, newline separated:\n        //   my-rg\n        //   other-rg\n        // A cluster name is only unique within a resource group, not within a subscription, so the\n        // query can legitimately return several rows. Picking one would silently deploy into, and\n        // hand back credentials for, an unrelated cluster.\n        var resourceGroups = result.StandardOutput\n            .Split('\\n', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);\n\n        if (resourceGroups.Length == 0)\n        {\n            throw new InvalidOperationException(\n                $\"Could not resolve resource group for AKS cluster '{clusterName}'. \" +\n                \"Ensure Azure provisioning has completed.\");\n        }\n\n        if (resourceGroups.Length > 1)\n        {\n            throw new InvalidOperationException(\n                $\"Found {resourceGroups.Length} AKS clusters named '{clusterName}' in subscription \" +\n                $\"'{subscriptionId}' (resource groups: {string.Join(\", \", resourceGroups)}). \" +\n                \"Specify which one to use by calling AsExistingInResourceGroup on the resource.\");\n        }\n\n        return resourceGroups[0];\n    }\n\n    /// <summary>\n    /// Fetches the kubeconfig content for the cluster from the Azure CLI.\n    /// </summary>","sourceCodeStart":906,"sourceCodeEnd":942,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Azure.Kubernetes/AzureKubernetesEnvironmentResource.AksPipeline.cs#L906-L942","documentation":"After `az resource list` succeeds but returns zero rows for the AKS cluster name in the subscription, Aspire cannot map the cluster to any resource group. It throws rather than guessing, because a wrong resource group would yield unusable credentials. This mirrors [520]: the cluster the pipeline expects simply does not exist (yet) in Azure.","triggerScenarios":"resourceGroup property queried when the AKS cluster named {clusterName} does not exist in the subscription - typically because Azure provisioning (the AzureEnvironmentResource deploy step) has not completed, was deleted, or the cluster lives in a different subscription than resolved in [520].","commonSituations":"Running destroy after state was manually recreated pointing at a cluster that was deleted in the portal; provisioning failed partway; typos or subscription switches between environments; cluster created under a different name than persisted.","solutions":["Run `aspire deploy` to completion so the AKS cluster is actually provisioned before operations that need its credentials.","Confirm with `az aks list -o table` (in the resolved subscription) that a cluster with the expected name exists.","Check the subscription ID used (see [520]) - the cluster may exist in a different subscription; set Azure:SubscriptionId explicitly.","If the cluster was deleted intentionally, clear or regenerate the deployment state so the pipeline stops referencing it."],"exampleFix":"// before\ndotnet run -- --destroy   // cluster already deleted in Azure\n\n// after\naz aks show -g my-rg -n my-cluster   # verify existence\n# if gone: remove stale state or redeploy with `aspire deploy`","handlingStrategy":"validation","validationCode":"var listed = Process.Start(\"az\", \"aks list -o tsv\");\n// confirm the expected cluster name appears before running destroy/deploy","typeGuard":null,"tryCatchPattern":"try { await DestroyAsync(); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"Could not resolve resource group\"))\n{\n    // cluster missing: clean up stale state or redeploy instead of retrying\n}","preventionTips":["Verify cluster existence with az aks list before destroy operations","Keep deploy and destroy against the same subscription","Do not hand-edit deployment state"],"tags":["azure","aks","resource-group","not-found"],"backgroundTag":"record-not-found","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}