Rename instead of delete resource?

前端 未结 1 1477
南方客
南方客 2021-02-12 23:21

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 m

1条回答
  •  时光说笑
    2021-02-13 00:00

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

    0 讨论(0)
提交回复
热议问题