【问题标题】:Rename instead of delete resource?重命名而不是删除资源?
【发布时间】:2018-08-13 04:58:52
【问题描述】:

在重组/重命名资源时,有什么方法可以避免资源删除?示例:当我第一次实现 CloudFront Terraform 时,它是我项目中的一个独立子目录,后来我切换到将它用作我的根 Terraform 配置中的一个模块,但这导致 Terraform 想要删除旧的 CloudFront 分配并创建一个新的:

Terraform will perform the following actions:
    - aws_cloudfront_distribution.main_site_distribution
    + module.cloudfront.aws_cloudfront_distribution.main_site_distribution

有没有办法强制 Terraform 重命名资源?

【问题讨论】:

    标签: terraform terraform-provider-aws


    【解决方案1】:

    不幸的是,Terraform 不知道您已经重命名/移动了资源,但您可以使用 terraform state mv 告诉它资源应该存储在状态中的哪个位置。

    如果你跑了,你的情况:

    terraform state mv aws_cloudfront_distribution.main_site_distribution module.cloudfront.aws_cloudfront_distribution.main_site_distribution
    

    然后运行另一个计划,您应该看不到任何更改(或只看到您对资源所做的更改以及移动)。

    【讨论】:

      猜你喜欢
      • 2022-01-21
      • 2020-12-23
      • 2023-01-26
      • 1970-01-01
      • 2012-07-23
      • 1970-01-01
      • 2020-09-16
      • 2020-08-25
      • 2018-02-20
      相关资源
      最近更新 更多