{"record":{"id":"93085719b69a7005","repo":"hashicorp/terraform","slug":"failed-to-delete-lock-info-from-metadata-s","errorCode":null,"errorMessage":"failed to delete lock info from metadata: %s","messagePattern":"failed to delete lock info from metadata: (.+?)","errorType":"exception","errorClass":"statemgr.LockError","httpStatus":null,"severity":"error","filePath":"internal/backend/remote-state/azure/client.go","lineNumber":289,"sourceCode":"\nfunc (c *RemoteClient) Unlock(id string) error {\n\tlockErr := &statemgr.LockError{}\n\n\tlockInfo, err := c.getLockInfo()\n\tif err != nil {\n\t\tlockErr.Err = fmt.Errorf(\"failed to retrieve lock info: %s\", err)\n\t\treturn lockErr\n\t}\n\tlockErr.Info = lockInfo\n\n\tif lockInfo.ID != id {\n\t\tlockErr.Err = fmt.Errorf(\"lock id %q does not match existing lock\", id)\n\t\treturn lockErr\n\t}\n\n\tc.leaseID = lockInfo.ID\n\tif err := c.writeLockInfo(nil); err != nil {\n\t\tlockErr.Err = fmt.Errorf(\"failed to delete lock info from metadata: %s\", err)\n\t\treturn lockErr\n\t}\n\n\tctx := newCtx()\n\t_, err = c.giovanniBlobClient.ReleaseLease(ctx, c.containerName, c.keyName, blobs.ReleaseLeaseInput{LeaseID: id})\n\tif err != nil {\n\t\tlockErr.Err = err\n\t\treturn lockErr\n\t}\n\n\tc.leaseID = \"\"\n\n\treturn nil\n}\n","sourceCodeStart":271,"sourceCodeEnd":304,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/backend/remote-state/azure/client.go#L271-L304","documentation":"Raised in RemoteClient.Unlock (client.go:288-290). After confirming the lock belongs to the caller, Unlock calls writeLockInfo(nil) which issues a SetMetaData data-plane call to clear the 'terraformlockid' metadata under the lease; if that call fails, this error wraps it in a LockError and the lease is NOT released.","triggerScenarios":"Produced at client.go:288-290 when c.writeLockInfo(nil) returns an error during Unlock — the SetMetaData data-plane call failed (network, auth, or lease-ID mismatch on the metadata write).","commonSituations":"Transient data-plane error during metadata write; the lease expired/break between confirm and metadata clear; data-plane permission lacks 'write' for metadata; a concurrent operation modified the blob.","solutions":["Retry the unlock — transient data-plane errors often clear on the next attempt","If it persists, break the lease: az storage blob lease break --account-name <account> -c <container> -b <key>","Confirm the credential has 'Storage Blob Data Contributor' (write metadata) permission","Re-run 'terraform init' then the command"],"exampleFix":"# retry; if the metadata clear keeps failing, break the lease\naz storage blob lease break \\\n  --account-name mystage --auth-mode login \\\n  -c tfstate -b \"prod.terraform.tfstate\"\n\nterraform init\nterraform apply","handlingStrategy":"retry","validationCode":"# Confirm data-plane write (metadata) permission before relying on clean unlock\naz role assignment list --assignee \"$ARM_CLIENT_ID\" --scope \"$ACCOUNT_ID\" --query \"[].roleDefinitionName\" -o tsv | grep -iE 'Storage Blob Data (Contributor|Owner)' \\\n  && echo \"OK: metadata write permission\" || echo \"WARN: may fail to clear lock metadata (158)\"","typeGuard":null,"tryCatchPattern":"# Retry the metadata-clearing unlock; break lease if it keeps failing\nunlock_with_retry() {\n  for attempt in 1 2 3; do\n    terraform force-unlock -force \"$1\" 2>/dev/null && return 0\n    grep -q \"failed to delete lock info from metadata\" && sleep $((attempt*5)) || return 1\n  done\n  az storage blob lease break --account-name \"$ARM_STORAGE_ACCOUNT_NAME\" -c \"$ARM_CONTAINER_NAME\" -n \"$ARM_KEY\"\n}","preventionTips":["Grant 'Storage Blob Data Contributor' so metadata writes succeed","Retry unlock on transient SetMetaData failures before escalating","Break the lease at the Azure layer if metadata clearing persistently fails"],"tags":["azure","state","locking","unlock","metadata","data-plane"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T21:17:07.882Z"}