Rename instead of delete resource?

旧时模样 提交于 2019-12-21 08:45:15

问题


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

Is there any way to force Terraform to rename the resource instead?


回答1:


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).



来源:https://stackoverflow.com/questions/49112142/rename-instead-of-delete-resource

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!