AKS Recreation Fails After Deletion: FailedIdentityOperation 409 and Identity Cleanup
A test Azure Kubernetes Service (AKS) cluster was deleted and recreated with the same name, but the create request failed with 409 Conflict. The error was FailedIdentityOperation. Its message said that a new resource had been requested but already existed, possibly because a delete operation was still pending.
A recreation procedure that bundles deletion and creation into one operation can miss this boundary. This article examines how AKS deletion checks were separated from a delay for possible identity cleanup. It focuses on the deletion and recreation conflict rather than Terraform state recovery.
Symptom: a new resource reportedly already exists
Section titled “Symptom: a new resource reportedly already exists”The relevant part of the recreation error follows. Resource identifiers have been omitted.
performing CreateOrUpdate: unexpected status 409 (409 Conflict)FailedIdentityOperationFailed to perform resource identity operation.Status: 'Conflict'.Request specified that resource '…' is new, but resource already exists.This may be due to a pending delete operation, try again later.Start with the last two sentences. This is not a message about a duplicate filename or Terraform resource address. An Azure resource identity operation conflicted, and the error itself identifies a pending deletion as a possible cause.
Other errors can share the name FailedIdentityOperation. Read the HTTP status and inner message together so that permission failures or unrelated conflicts are not mistaken for the same waiting problem.
Interpreting the cause: deletion and identity cleanup boundaries
Section titled “Interpreting the cause: deletion and identity cleanup boundaries”A managed identity is an identity AKS uses to access Azure resources. It is distinct from Workload Identity used by applications running in pods.
The lifecycle depends on the identity type. According to Microsoft’s managed identity overview, a system-assigned identity is deleted with its parent resource, while a user-assigned identity is managed independently.
| Type | Lifecycle | Meaning when investigating deletion |
|---|---|---|
| System-assigned identity | Tied to its parent Azure resource | Identity deletion is linked to parent resource deletion. |
| User-assigned identity | Independent of its parent resource | Deleting AKS does not by itself delete that identity. |
| Workload Identity | Federation for pod access to Azure | Do not interpret this resource creation failure as a pod authentication configuration issue. |
In this case, recreation was rejected during an identity operation for the same AKS resource. Activity Log records around the incident included both a failed creation and a successful deletion. The creation error mentioned a pending delete operation.
These records prompted an investigation into whether identity cleanup had not finished between deletion and recreation. The recovery procedure was therefore changed to distinguish two conditions.
- Has deletion of the AKS resource been confirmed?
- Is recreation immediately afterward rejected with the same identity conflict?
Why retries and sequential processing were not enough
Section titled “Why retries and sequential processing were not enough”The earlier procedure used Terraform’s -replace option to replace AKS. This option requests a replacement plan for the specified resource. The procedure in this case had no separate cleanup delay after deletion.
Adding retries around kubeconfig retrieval or API readiness checks after creation does not address a 409 from the earlier create request. Processing two clusters one at a time reduces concurrent work across clusters, but does not insert a delay between deleting and creating the same cluster.
| Attempt | What it addresses | Remaining problem |
|---|---|---|
| Retry API checks after creation | Readiness of an already-created AKS cluster | These checks are never reached if creation fails. |
| Recreate clusters sequentially | Ordering between two clusters | Immediate deletion and recreation of each cluster can still conflict. |
| Restart the entire procedure after failure | The complete recreation operation | A cluster that already succeeded may be deleted again. |
Recovery procedure: separate deletion checks, delay, and creation
Section titled “Recovery procedure: separate deletion checks, delay, and creation”The change was to make deletion and creation separate stages. The revised script introduced a configurable delay after confirming deletion, then classified any subsequent creation error.
Figure 1. Original recovery flow based on the incident error and the revised procedure. It does not depict Azure’s internal identity processing state. The following sections explain the scope and stop conditions of each stage.
1. Confirm AKS deletion first
Section titled “1. Confirm AKS deletion first”First, make the subscription and resource group explicit. The following names are examples.
SUBSCRIPTION_ID="<subscription-id>"RESOURCE_GROUP="rg-aks-lab"AKS_NAME="aks-lab"
az aks list \ --subscription "$SUBSCRIPTION_ID" \ --resource-group "$RESOURCE_GROUP" \ --query "[?name=='${AKS_NAME}'].{name:name,state:provisioningState}" \ --output tableDeleting AKS removes its workloads. Use the following command only when recreation is intended and the deletion target has been confirmed. Without --no-wait, it waits for the deletion operation to finish.
az aks delete \ --subscription "$SUBSCRIPTION_ID" \ --resource-group "$RESOURCE_GROUP" \ --name "$AKS_NAME" \ --yesIf asynchronous deletion has already started, confirm completion with a wait command rather than issuing another deletion.
az aks wait \ --subscription "$SUBSCRIPTION_ID" \ --resource-group "$RESOURCE_GROUP" \ --name "$AKS_NAME" \ --deleted \ --interval 15 \ --timeout 1800--interval sets the polling interval and --timeout sets the maximum wait. Do not proceed to creation if the command fails. It checks AKS deletion, not a dedicated completion signal for internal identity cleanup.
2. Make the additional delay configurable
Section titled “2. Make the additional delay configurable”The revised script used a default delay of 120 seconds after confirming deletion. IDENTITY_COOLDOWN_SECONDS allowed that value to be changed.
This number was a buffer chosen for the case. The important change was not the value 120, but the separation between deletion checks and creation, followed by classification of the create result. Increasing the delay is not a response to every kind of failure.
3. Retry only the matching conflict, within a limit
Section titled “3. Retry only the matching conflict, within a limit”The creation stage was changed to create the missing cluster rather than requesting another forced replacement. If it failed, the procedure checked for both FailedIdentityOperation and pending delete operation in the error.
The limit in this case was three creation attempts in total. A different error or exhaustion of the attempts stops the procedure so that the create output and Activity Log can be retained.
Before trying again, check whether AKS has reappeared. A failed request can leave a Failed resource behind, causing a simple creation retry to fail with “already exists.” At that point, compare the remaining resource with the management tool’s registration state before choosing a recovery action. Do not delete a healthy resource by treating it as failed residue.
4. Exclude successful clusters when resuming
Section titled “4. Exclude successful clusters when resuming”When processing multiple clusters, do not repeat every replacement because one cluster failed. The revised resume behavior skips clusters that are both Succeeded and tracked in Terraform, refreshing only their kubeconfig and API checks.
Verification: separate provisioning success from API readiness
Section titled “Verification: separate provisioning success from API readiness”Check provisioningState using the earlier listing command, then verify the API with the target cluster’s kubeconfig.
kubectl --kubeconfig ./aks-lab-admin.yaml \ --request-timeout=10s get --raw=/readyz
kubectl --kubeconfig ./aks-lab-admin.yaml \ --request-timeout=10s get nodesAn API response of ok is not the same as every node and workload being ready. Review the node output and required workload status afterward.
To correlate deletion and creation, query Activity Log for the UTC window containing the failure. Replace the example times with the actual error window.
az monitor activity-log list \ --subscription "$SUBSCRIPTION_ID" \ --resource-group "$RESOURCE_GROUP" \ --start-time "2026-11-12T00:00:00Z" \ --end-time "2026-11-12T01:00:00Z" \ --query "[].{time:eventTimestamp,operation:operationName.value,status:status.value,correlationId:correlationId}" \ --output tableRetaining operation names, statuses, timestamps, and correlationId makes it easier to follow separate requests without mixing their results.
Limits and prevention
Section titled “Limits and prevention”The observed facts are that recreation with the same AKS name was rejected with a 409 during an identity operation, and that the error mentioned a possible pending deletion. The internal identity state was not directly observed. This case does not establish a permanently orphaned identity or a confirmed Azure internal root cause.
Later records showed both clusters as Succeeded. However, the final revised recreation procedure had only passed mock tests; no record showed a complete real deletion and recreation using that revision. The default 120-second delay is neither an official recommendation nor a proven time to resolution.
The prevention criteria to retain are these.
- Separate deletion confirmation, an additional delay, and creation result handling.
- Do not handle creation failures and post-creation readiness delays in the same retry loop.
- Resume from the failed stage while preserving healthy clusters.
- Retain the original error and operation records instead of retrying the same conflict indefinitely.
- Do not manually delete a separate managed identity without checking its type and consumers.