重命名而不是删除资源? [英] Rename instead of delete resource?
问题描述
在重新组织/重命名资源时,有没有办法避免资源删除?示例:当我第一次实现 CloudFront Terraform 时,它是我项目中的一个独立子目录,后来我切换到将它用作模块.我的根 Terraform 配置但这导致 Terraform 想要删除旧的 CloudFront 分发并创建一个新的:
Is there any way to avoid resource deletion when reorganizing/renaming resources? Example: when I first implemented CloudFront Terraform it was an independent sub directory in my project, later I switched to using it as a module in. my root Terraform config but this caused Terraform to want to delete the old CloudFront distribution and create a new one:
Terraform will perform the following actions:
- aws_cloudfront_distribution.main_site_distribution
+ module.cloudfront.aws_cloudfront_distribution.main_site_distribution
有什么办法可以强制 Terraform 重命名资源吗?
Is there any way to force Terraform to rename the resource instead?
推荐答案
不幸的是,Terraform 不知道您已经重命名/移动了资源,但您可以使用 terraform state mv
.
Unfortunately Terraform doesn't know that you've renamed/moved the resource around but you could tell it where the resource should be stored in the state by using terraform state mv
.
在你的情况下,如果你跑了:
In your case if you ran:
terraform state mv aws_cloudfront_distribution.main_site_distribution module.cloudfront.aws_cloudfront_distribution.main_site_distribution
然后运行另一个计划,您应该不会看到任何变化(或者只有您对资源所做的更改以及移动).
and then run another plan you should see no changes (or only the changes to the resource you have made as well as the move).
这篇关于重命名而不是删除资源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!