{"record":{"id":"a42f74aaa28cebe4","repo":"hashicorp/terraform","slug":"lock-id-q-does-not-match-existing-lock","errorCode":null,"errorMessage":"lock id %q does not match existing lock","messagePattern":"lock id %q does not match existing lock","errorType":"exception","errorClass":"statemgr.LockError","httpStatus":null,"severity":"error","filePath":"internal/backend/remote-state/azure/client.go","lineNumber":283,"sourceCode":"\t\tMetaData: blob.MetaData,\n\t}\n\n\t_, err = c.giovanniBlobClient.SetMetaData(ctx, c.containerName, c.keyName, opts)\n\treturn err\n}\n\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","sourceCodeStart":265,"sourceCodeEnd":301,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/backend/remote-state/azure/client.go#L265-L301","documentation":"Raised in RemoteClient.Unlock (client.go:282-284). For safety, Unlock compares the lock ID passed in against the ID stored in the blob lock metadata; if they differ, it refuses to release someone else's lease and returns a LockError. This prevents one Terraform run from unlocking state held by a different run.","triggerScenarios":"Produced at client.go:282-283 when lockInfo.ID != id during Unlock. Happens when a stale or wrong lock ID is passed to 'terraform force-unlock', or when Terraform's recorded lock ID no longer matches the actual lease holder.","commonSituations":"Running 'terraform force-unlock' with the wrong ID (a typo, or an old ID from a previous run); two runs interfering; the lease ID changed because someone already broke/reacquired the lease.","solutions":["Use the correct lock ID shown by the current 'terraform' error or by querying the blob lock metadata","If you are certain the lock is stale, break the lease directly: az storage blob lease break --account-name <account> -c <container> -b <key>","Inspect current lock info: az storage blob metadata show / az storage blob lease show"],"exampleFix":"# before: wrong/stale lock id\nterraform force-unlock 00000000-0000-0000-0000-000000000000\n# -> 'lock id does not match existing lock'\n\n# after: read the actual stored lock id from metadata, or break the lease\naz storage blob lease break \\\n  --account-name mystage --auth-mode login \\\n  -c tfstate -b \"prod.terraform.tfstate\"\nterraform init","handlingStrategy":"validation","validationCode":"# Validate the lock id matches the stored metadata before force-unlock\nSTORED=$(az storage blob metadata show --account-name \"$ARM_STORAGE_ACCOUNT_NAME\" -c \"$ARM_CONTAINER_NAME\" -n \"$ARM_KEY\" --query 'terraformlockid' -o tsv 2>/dev/null | base64 -d 2>/dev/null | grep -oE '\"ID\":\"[0-9a-f-]{36}\"' | grep -oE '[0-9a-f-]{36}')\n[ \"$STORED\" = \"$1\" ] && echo \"OK: id matches\" || echo \"FAIL: id mismatch (157); stored=$STORED supplied=$1\"\n# usage: validate_lock_id \"$PROPOSED_LOCK_ID\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always copy the lock ID from the current Terraform error, not an old log","If you cannot recover the correct ID, break the lease at the Azure layer","Avoid force-unlocking state you do not own to prevent unlocking another run's lock"],"tags":["azure","state","locking","unlock","lock-id","validation"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T20:17:04.800Z"}