published fresh until

Terraform Error acquiring the state lock: what first?

Summary As of October 2026, inspect the lock owner and underlying S3 error before retrying: wait for an active writer, repair lockfile permissions for access failures, and force-unlock only your own abandoned lock (checked 2026-10-28).

Not for Unsupported state file format while reading S3, see terraform-unsupported-state-file-format-s3-shrink-race

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Error: Error acquiring the state lock Terraform cannot acquire the S3 backend lock, so the plan or apply stops before proceeding. First action: inspect use_lockfile and the error's Lock Info, then identify the owning run before retrying. Official documentation establishes locking and permissions requirements; the cited issue demonstrates a leftover lock after migration, not a universal cause or a tested repair for your backend (checked 2026-10-28). Not for: Terraform Unsupported state file format during reads; see the S3 read-race thread.

How to fix it

1. Record the backend bucket, key, workspace, lock ID and owning run from the diagnostic. Check whether that run still exists. For an active writer, let it finish; serialize competing jobs rather than unlocking it. HashiCorp explains why only your own abandoned lock qualifies for force-unlock. 2. Read the underlying service error. A conditional-write failure can mean an existing lock. AccessDenied calls for a permissions investigation instead. For use_lockfile = true, the S3 backend reference requires s3:GetObject, s3:PutObject and s3:DeleteObject on the actual .tflock object. Check the workspace-prefixed path as well. These lockfile rights differ from rights on the state object; do not grant blanket deletion rights to the bucket. 3. When another run is legitimately finishing, use the documented wait flag, for example terraform plan -lock-timeout=3s. The duration is an example, not a service recommendation. A longer wait cannot repair denied permissions. A plan contacts the configured backend and providers; inspect its output without applying it. 4. Only after verifying that your own run has ended and failed to release its lock, use terraform force-unlock LOCK_ID in the matching initialized configuration, replacing LOCK_ID with the diagnostic's ID. Keep the confirmation prompt. The command reference says this releases the lock without changing infrastructure; releasing a live writer's lock still permits unsafe concurrency. 5. Repeat one plan, confirm acquisition and release, then restore normal serialized jobs. If the service error persists, stop and investigate it rather than deleting state.

Diagnostic: Error: Error acquiring the state lock

In ddouglas's issue #36407, migration appeared successful despite missing lockfile deletion permission; the next operation encountered S3 PreconditionFailed and an existing migration lock. That is a specific reported sequence. Do not infer every conditional failure is abandoned, or that every access failure can be fixed by unlocking.

What changed

The current S3 reference, on the Terraform 1.17.x documentation line (checked 2026-10-28), supports use_lockfile and marks DynamoDB locking deprecated. Both mechanisms may coexist during migration. It gives no exact removal date; do not invent a shutdown deadline or remove the old mechanism before coordinating all writers.

What to test

In an isolated backend, demonstrate that two competing plans cannot both hold the lock, the holder releases it normally, and the next plan succeeds. Exercise the same workspace path and execution identity as CI. Successful initialization alone does not establish permission to release locks.

Pitfalls

Do not use -lock=false to make a blocked job green. Do not delete the state object, force-unlock another owner's run, or treat a stale local configuration as proof of the current backend. Locking errors and malformed state diagnostics need different investigations.

Prompt for your agent

Read the linked HashiCorp S3, locking, plan and force-unlock pages before reasoning; your training may predate current backend behavior. Inspect the configuration and redacted diagnostic. Identify the lock owner, active-run evidence, workspace path and underlying service error. Propose either waiting or the narrow permission correction. Do not unlock, change permissions, migrate state, disable locking or apply changes. State what evidence would justify a human releasing an abandoned lock.

Limits

This is documented operational guidance, not a reproduced backend repair. Community evidence is one detailed migration report; independent confirmation is thin. No claim is made that its historical migration behavior persists in the current release. Cross-account policy evaluation and non-AWS S3 implementations need separate investigation.

Started from a post by @ddouglas, packaged by the editor. Original post

Subjects

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Terraform Error acquiring the state lock: what first?
Summary: As of October 2026, inspect the lock owner and underlying S3 error before retrying: wait for an active writer, repair lockfile permissions for access failures, and force-unlock only your own abandoned lock (checked 2026-10-28).
Copy for agent
get the whatworks thread terraform-s3-error-acquiring-state-lock-owner-or-permissions and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread terraform-s3-error-acquiring-state-lock-owner-or-permissions
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp for anonymous reading; sign in via OAuth only to report a trial. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp