【问题标题】:how to handle corrupted terraform tfstate file如何处理损坏的 terraform tfstate 文件
【发布时间】:2019-12-08 13:31:09
【问题描述】:

我正在 aks 中的 pod 内运行一个应用程序,即使用 terraform 配置 aws 服务,如果在配置进行期间该 pod 被删除或停止,则 terraform 状态文件已损坏。

当我尝试使用该状态文件再次配置时,我收到应用错误。一些资源已配置但未在状态文件中更新。我收到以下错误。

Error: Error applying plan:

1 error(s) occurred:

* aws_s3_bucket.examplebucket: 1 error(s) occurred:

* aws_s3_bucket.examplebucket: Error creating S3 bucket: BucketAlreadyOwnedByYou: Your previous request to create the named bucket succeeded and you already own it.
        status code: 409

那么如何更新状态文件以便我可以再次使用它?

【问题讨论】:

  • 尝试 terraform refresh -h

标签: terraform


【解决方案1】:

不确定该错误是否与 Kubernetes 资源和 Pod 有关。

但是如果你需要刷新/重新创建存储桶,你可以taint它。

terraform taint aws_s3_bucket.examplebucket
terraform plan
terraform apply

让我知道这是否有帮助。

【讨论】:

  • 谢谢,我会检查的。
  • 在模块根目录中找不到资源 aws_s3_bucket.examplebucket。我从 terraform 收到此错误
【解决方案2】:

如果 terraform 尝试创建已经存在的东西,您需要将资源导入到 terraform。

每种 terraform 资源,在本例中为 aws_s3_bucket,都在其文档底部列出了如何导入它。

在这种情况下,以下命令应该可以解决问题:

terraform import aws_s3_bucket.bucket **BUCKETNAME**

用您的存储桶替换 BUCKETNAME

【讨论】:

  • 谢谢,我试过了,它有效,但我必须导入自动化难以实现的每一个资源。
  • 这确实只是第一次,如果您在现有环境中使用 TF 开始
  • 你能解释一下解决方案吗:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-06-26
  • 2021-06-26
  • 2019-05-16
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多