{
  "id": "policy/terraform-state-lock-timeout-dynamodb",
  "signature": "Error: Error acquiring the state lock. Lock Info: Lock ID: <id>. Error: ConditionalCheckFailedException: The conditional request failed",
  "signature_zh": "错误：获取状态锁失败。锁信息：锁 ID：<id>。错误：ConditionalCheckFailedException：条件请求失败",
  "regex": "Error acquiring the state lock.*ConditionalCheckFailedException",
  "domain": "policy",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "Terraform state locking via DynamoDB fails when another process holds the lock longer than the default retry timeout, often due to long-running applies or stale locks.",
  "root_cause_type": "generic",
  "root_cause_zh": "Terraform 通过 DynamoDB 的状态锁定在另一个进程持有锁超过默认重试超时时失败，通常是由于长时间运行的 apply 或过时的锁。",
  "versions": [
    {
      "version": "Terraform v1.5.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Terraform v1.6.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "DynamoDB standard table",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Running terraform force-unlock without verifying the lock holder can corrupt the state if the original process is still running.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Deleting the DynamoDB lock table entirely loses all lock state and requires reinitialization.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Manually editing the DynamoDB item with incorrect permissions may cause AccessDenied errors.",
      "fail_rate": 0.5,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Identify the lock holder via AWS CLI: aws dynamodb get-item --table-name terraform-locks --key '{\"LockID\": {\"S\": \"<lock-id>\"}}'. If the holder is stale, run terraform force-unlock -force <lock-id>.",
      "success_rate": 0.85,
      "how": "Identify the lock holder via AWS CLI: aws dynamodb get-item --table-name terraform-locks --key '{\"LockID\": {\"S\": \"<lock-id>\"}}'. If the holder is stale, run terraform force-unlock -force <lock-id>.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Increase the lock retry timeout in terraform block: terraform { backend \"s3\" { lock_timeout = \"5m\" } } to allow longer waits.",
      "success_rate": 0.75,
      "how": "Increase the lock retry timeout in terraform block: terraform { backend \"s3\" { lock_timeout = \"5m\" } } to allow longer waits.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Implement a pre-apply check script that verifies no other CI pipeline is running using the same state file.",
      "success_rate": 0.7,
      "how": "Implement a pre-apply check script that verifies no other CI pipeline is running using the same state file.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "通过 AWS CLI 识别锁持有者：aws dynamodb get-item --table-name terraform-locks --key '{\"LockID\": {\"S\": \"<lock-id>\"}}'。如果持有者已过期，运行 terraform force-unlock -force <lock-id>。",
    "在 terraform 块中增加锁重试超时：terraform { backend \"s3\" { lock_timeout = \"5m\" } } 以允许更长的等待。",
    "实施预 apply 检查脚本，验证没有其他 CI 管道使用相同状态文件运行。"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://developer.hashicorp.com/terraform/language/settings/backends/s3#dynamodb-state-locking",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.85,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2023-08-15",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}