【问题标题】:Terraform destroy error 'Instance cannot be destroyed' and 'Failed getting S3 bucket'Terraform 销毁错误“无法销毁实例”和“获取 S3 存储桶失败”
【发布时间】:2021-02-04 09:41:00
【问题描述】:

我目前正在尝试销毁工作区,我知道有些存储桶应用了“请勿销毁”类型标签,所以当我第一次运行 terraform destroy 时,我得到了 @987654322 @ 两个桶的错误:

Resource module.xxx.aws_s3_bucket.xxx_bucket has
lifecycle.prevent_destroy set, but the plan calls for this resource to be
destroyed. To avoid this error and continue with the plan, either disable
lifecycle.prevent_destroy or reduce the scope of the plan using the -target
flag.

所以我导航到 AWS 控制台并手动删除它们,然后尝试再次运行 terraform destroy,然后它抱怨我手动删除的一个存储桶:Failed getting S3 bucket: NotFound: Not Found,另一个似乎很好。

请问有人知道怎么解决吗?谢谢。

【问题讨论】:

    标签: amazon-web-services amazon-s3 terraform terraform-provider-aws


    【解决方案1】:

    如果您使用 Terraform 状态修改之外的操作删除了资源(在这种情况下,通过控制台手动删除了存储桶),那么您需要相应地更新 Terraform 状态。您可以使用terraform state 子命令执行此操作。鉴于您列出的名为 module.xxx.aws_s3_bucket.xxx_bucket 的资源示例,它看起来像:

    terraform state rm module.xxx.aws_s3_bucket.xxx_bucket
    

    您可以在documentation 中找到更多信息。

    【讨论】:

    • 谢谢。我实际上将lifecycle.prevent_destroy 修改为“false”,然后重新申请,然后尝试销毁,它成功了!
    猜你喜欢
    • 2021-06-07
    • 1970-01-01
    • 2021-10-01
    • 2021-09-08
    • 1970-01-01
    • 2019-02-19
    • 2019-06-16
    • 2021-12-11
    • 1970-01-01
    相关资源
    最近更新 更多