terraform - 错误刷新状态 : state data in S3 does not have the expected content

标签 terraform terraform-provider-aws

当我们尝试运行带有远程状态处理的 terraform 脚本时,我们会遇到以下问题:

Error refreshing state: state data in S3 does not have the expected content. This may be caused by unusually long delays in S3 processing a previous state update. Please wait for a minute or two and try again. If this problem persists, and neither S3 nor DynamoDB are experiencing an outage, you may need to manually verify the remote state and update the Digest value stored in the DynamoDB table to the following value

最佳答案

根据您的具体情况,有 3 种可能的解决方法来解决它:
情况1
如果您有 备份 您的 AWS S3 terrform.tfstate您可以恢复状态后端的文件 "s3" {key = "path/to/terraform.tfstate"}到旧版本。重试terraform init并验证它是否运行良好。

案例二
删除 AWS DynamoDB 表中的不同步条目。会有LockID包含状态和预期校验和的表中的条目,您应该删除这些条目,并在重新运行后重新生成 terraform init .
重要注意事项:

  • 在此过程中,您将失去锁状态保护,这会阻止其他人获取锁,并且可能有两个人同时更新破坏您状态的相同资源。
  • 请考虑使用 terraform refresh命令 ( https://www.terraform.io/docs/commands/refresh.html ),用于协调 Terraform 知道的状态(通过其状态文件)与现实世界的基础设施。这可用于检测与上次已知状态的任何漂移,并更新状态文件。
  • 删除 DynamoDB LockID 表条目 -> 屏幕截图:

  • enter image description here

    案例3
    如果在 terraform destroy 之后您已手动删除您的 AWS S3 terraform.tfstate文件,然后可能尝试启动所有 tf​​state 声明资源的新实例,这意味着您正在从头开始工作,您只需更新您的 AWS S3 terrform.tfstate状态后端 key "s3" {key = "path/to/terraform.tfstate"}到一个新的 "s3" {key = "new-path/to/terraform.tfstate"} .重试 terraform init并验证这应该运行良好。此解决方法的局限性在于您还没有真正解决根本原因,您只是使用 S3 tfstate 的新 key 绕过问题。

    关于terraform - 错误刷新状态 : state data in S3 does not have the expected content,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57984714/

    相关文章:

    amazon-web-services - Terraform:特定于 ubuntu 20.08 LTS AWS 的 AMI 列表

    amazon-s3 - 来自 Terraform 的格式错误的 S3 策略

    postgresql - 通过 Terraform 创建 RDS 实例后向数据库添加 Postgresql 角色

    google-cloud-platform - Bitbucket 使用 terraform 进行源 repo 镜像

    linux - Terraform VM 创建然后删除

    terraform - 使用启动模板滚动更新 ASG

    terraform - 过滤 terraform 列表中的特定值

    指定模块时 terraform init 不起作用

    amazon-web-services - 地形错误 : Invalid value for module argument

    amazon-web-services - 如何使用 local_file 资源将由 Terraform 中的 tls_private_key 资源创建的 pem 文件保存到磁盘?