{"record":{"id":"6c91cd412aa4f1c6","repo":"microsoft/aspire","slug":"no-azure-deployment-state-was-found-for-aks-environment-name","errorCode":null,"errorMessage":"No Azure deployment state was found for AKS environment '{Name}'. Cluster cleanup cannot run without an isolated kubeconfig.","messagePattern":"No Azure deployment state was found for AKS environment '(.+?)'\\. Cluster cleanup cannot run without an isolated kubeconfig\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Azure.Kubernetes/AzureKubernetesEnvironmentResource.AksPipeline.cs","lineNumber":373,"sourceCode":"            {\n                await getCredsTask.FailAsync(\n                    $\"Failed to fetch AKS credentials: {ex.Message}\",\n                    context.CancellationToken).ConfigureAwait(false);\n                throw;\n            }\n        }\n    }\n\n    private async Task GetAksCredentialsForDestroyAsync(PipelineStepContext context)\n    {\n        var deploymentStateManager = context.Services.GetRequiredService<IDeploymentStateManager>();\n        var deploymentStateSection = await deploymentStateManager\n            .AcquireSectionAsync($\"Azure:Deployments:{Name}\", context.CancellationToken)\n            .ConfigureAwait(false);\n\n        if (deploymentStateSection.Data.Count == 0)\n        {\n            throw new InvalidOperationException(\n                $\"No Azure deployment state was found for AKS environment '{Name}'. \" +\n                \"Cluster cleanup cannot run without an isolated kubeconfig.\");\n        }\n\n        // Azure deployment outputs are persisted as a JSON string with the ARM output shape:\n        //   {\n        //     \"id\": { \"type\": \"String\", \"value\": \"/subscriptions/.../managedClusters/aks-abc123\" },\n        //     \"name\": { \"type\": \"String\", \"value\": \"aks-abc123\" }\n        //   }\n        // Read it directly because the provisioning step that normally populates Outputs is not\n        // part of a fresh destroy process.\n        ResourceIdentifier? clusterResourceId;\n        try\n        {\n            clusterResourceId = GetPersistedAksResourceId(deploymentStateSection.Data);\n        }\n        catch (Exception ex) when (ex is not OperationCanceledException)\n        {","sourceCodeStart":355,"sourceCodeEnd":391,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Azure.Kubernetes/AzureKubernetesEnvironmentResource.AksPipeline.cs#L355-L391","documentation":"During AKS environment destroy, GetAksCredentialsForDestroyAsync reads the persisted 'Azure:Deployments:<Name>' state section to recover the deployed cluster's resource id so it can fetch a kubeconfig and clean up the cluster. This error is thrown when the state store has no deployment outputs for this environment, so cleanup cannot proceed safely with an isolated kubeconfig.","triggerScenarios":"Running aspire destroy / pipeline destroy for an AKS environment whose name has no 'Azure:Deployments:<Name>' section in the deployment state store — e.g. the deployment never completed, the state was deleted, or the environment name doesn't match the one used at deploy time.","commonSituations":"Destroying an environment that was never successfully deployed; a stale or cleared state store (local state files removed, different state backend); renaming the AKS environment resource between deploy and destroy.","solutions":["Deploy the environment at least once successfully before destroying, so the deployment state is persisted","Ensure the destroy command targets the same environment name used during deployment (check 'Azure:Deployments:<Name>' key)","Restore or point the destroy run at the correct deployment state store/backend used by the original deployment","If the cluster exists but state is unrecoverable, delete the resource group/cluster directly in Azure instead of through the pipeline cleanup step"],"exampleFix":"// before (destroy with mismatched name)\nbuilder.AddAzureKubernetesEnvironment(\"prod-aks\"); // deployed as \"aks-env\"\n// after\nbuilder.AddAzureKubernetesEnvironment(\"aks-env\"); // same name as the deployed state","handlingStrategy":"validation","validationCode":"var section = await deploymentStateManager.AcquireSectionAsync($\"Azure:Deployments:{Name}\", ct);\nbool canDestroy = section.Data.Count > 0;","typeGuard":null,"tryCatchPattern":"try\n{\n    await pipeline.DestroyAsync(...);\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"No Azure deployment state\"))\n{\n    // No prior deployment state; clean up in Azure directly (resource group deletion) instead.\n}","preventionTips":["Only run destroy for environments that completed a successful deployment under the same name","Never delete or hand-edit the deployment state store between deploy and destroy","Use the same Aspire CLI/SDK version and state backend for deploy and destroy","Name AKS environment resources stably; renaming invalidates the state key"],"tags":["azure","aks","destroy","deployment-state"],"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-21T04:17:39.646Z"}