ResourceNotFoundException terraform resource_error ai_generated true

Error: Error acquiring the state lock: ResourceNotFoundException: Requested resource not found

ID: terraform/state-lock-dynamodb-table-not-found

Also available as: JSON · Markdown · 中文
92%Fix Rate
87%Confidence
1Evidence
2023-07-10First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
1.3.0 active
1.4.0 active
1.5.0 active

Root Cause

The DynamoDB table specified for state locking does not exist in the AWS account or region, preventing lock acquisition.

generic

中文

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

Official Documentation

https://developer.hashicorp.com/terraform/language/settings/backends/s3#dynamodb-state-locking

Workarounds

  1. 95% success Create the DynamoDB table manually using AWS CLI: 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
    Create the DynamoDB table manually using AWS CLI: 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. 85% success Use Terraform itself to create the DynamoDB table in a separate configuration, then migrate the backend.
    Use Terraform itself to create the DynamoDB table in a separate configuration, then migrate the backend.

中文步骤

  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 表,然后迁移后端。

Dead Ends

Common approaches that don't work:

  1. 95% fail

    Running terraform init again does not create the DynamoDB table; it only configures the backend.

  2. 60% fail

    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.