# 错误：获取状态锁时出错：ResourceNotFoundException：请求的资源未找到

- **ID:** `terraform/state-lock-dynamodb-table-not-found`
- **领域:** terraform
- **类别:** resource_error
- **错误码:** `ResourceNotFoundException`
- **验证级别:** ai_generated
- **修复率:** 92%

## 根因

为状态锁定指定的 DynamoDB 表在 AWS 账户或区域中不存在，阻止了锁的获取。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 1.3.0 | active | — | — |
| 1.4.0 | active | — | — |
| 1.5.0 | active | — | — |

## 解决方案

1. ```
   使用 AWS CLI 手动创建 DynamoDB 表：aws dynamodb create-table --table-name terraform-lock --attribute-definitions AttributeName=LockID,AttributeType=S --key-schema AttributeName=LockID,KeyType=HASH --billing-mode PAY_PER_REQUEST
   ```
2. ```
   在单独的配置中使用 Terraform 创建 DynamoDB 表，然后迁移后端。
   ```

## 无效尝试

- **** — Running terraform init again does not create the DynamoDB table; it only configures the backend. (95% 失败率)
- **** — Setting the lock table to an empty string or removing it from the backend config causes Terraform to skip locking, but this can lead to state corruption. (60% 失败率)
