terraform resource_error ai_generated true

错误:加载状态失败:S3 存储桶 "my-terraform-state" 不存在

Error: Failed to load state: S3 bucket "my-terraform-state" does not exist

ID: terraform/s3-backend-bucket-not-found

其他格式: JSON · Markdown 中文 · English
90%修复率
87%置信度
1证据数
2024-03-10首次发现

版本兼容性

版本状态引入弃用备注
Terraform v1.5.0 active
Terraform v1.6.0 active
Terraform v1.7.0 active

根因分析

后端配置中指定的用于状态存储的S3存储桶尚未创建或已被删除。

English

The S3 bucket specified in the backend configuration for state storage has not been created or has been deleted.

generic

官方文档

https://developer.hashicorp.com/terraform/language/settings/backends/s3

解决方案

  1. Create the S3 bucket manually with the correct name and region: `aws s3api create-bucket --bucket my-terraform-state --region us-east-1 --create-bucket-configuration LocationConstraint=us-east-1`
  2. Update the backend configuration to point to an existing bucket, then run 'terraform init -reconfigure'

无效尝试

常见但无效的做法:

  1. Run 'terraform init' with -migrate-state flag 95% 失败

    The bucket still doesn't exist; migrate requires an existing bucket.

  2. Change the bucket name in the backend block to a random new name 80% 失败

    The new bucket also doesn't exist unless created manually.

  3. Use local backend by removing the backend block 70% 失败

    This changes the state location and may lose remote state history.