microsoft/aspire · error

Could not resolve resource group for AKS cluster

Error message

Could not resolve resource group for AKS cluster '{clusterName}'. Ensure Azure provisioning has completed.

What it means

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.

Solutions

  1. Run `aspire deploy` to completion so the AKS cluster is actually provisioned before operations that need its credentials.
  2. Confirm with `az aks list -o table` (in the resolved subscription) that a cluster with the expected name exists.
  3. Check the subscription ID used (see [520]) - the cluster may exist in a different subscription; set Azure:SubscriptionId explicitly.
  4. If the cluster was deleted intentionally, clear or regenerate the deployment state so the pipeline stops referencing it.

Example fix

// before
dotnet run -- --destroy   // cluster already deleted in Azure

// after
az aks show -g my-rg -n my-cluster   # verify existence
# if gone: remove stale state or redeploy with `aspire deploy`
Defensive patterns

Strategy: validation

Validate before calling

var listed = Process.Start("az", "aks list -o tsv");
// confirm the expected cluster name appears before running destroy/deploy

Try / catch

try { await DestroyAsync(); }
catch (InvalidOperationException ex) when (ex.Message.Contains("Could not resolve resource group"))
{
    // cluster missing: clean up stale state or redeploy instead of retrying
}

Prevention

When it happens

Trigger: 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].

Common situations: 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.

Understand the failure class

Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.

Related errors


AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16). Data as JSON: /api/errors/96295329670de44b. Report an issue: GitHub.

Appendix: source

Thrown at src/Aspire.Hosting.Azure.Kubernetes/AzureKubernetesEnvironmentResource.AksPipeline.cs:924

        if (result.ExitCode != 0)
        {
            throw new InvalidOperationException(
                $"az resource list failed (exit code {result.ExitCode}): {result.StandardError}");
        }

        // With '-o tsv' the query emits one resource group per matching cluster, newline separated:
        //   my-rg
        //   other-rg
        // A cluster name is only unique within a resource group, not within a subscription, so the
        // query can legitimately return several rows. Picking one would silently deploy into, and
        // hand back credentials for, an unrelated cluster.
        var resourceGroups = result.StandardOutput
            .Split('\n', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);

        if (resourceGroups.Length == 0)
        {
            throw new InvalidOperationException(
                $"Could not resolve resource group for AKS cluster '{clusterName}'. " +
                "Ensure Azure provisioning has completed.");
        }

        if (resourceGroups.Length > 1)
        {
            throw new InvalidOperationException(
                $"Found {resourceGroups.Length} AKS clusters named '{clusterName}' in subscription " +
                $"'{subscriptionId}' (resource groups: {string.Join(", ", resourceGroups)}). " +
                "Specify which one to use by calling AsExistingInResourceGroup on the resource.");
        }

        return resourceGroups[0];
    }

    /// <summary>
    /// Fetches the kubeconfig content for the cluster from the Azure CLI.
    /// </summary>

View on GitHub (pinned to 25830f84bd)