In my case, it was an S3 bucket, containing several big files. It would have been a long process to backup the files, destroy them from the bucket, then restore them on the destination bucket. So here is the way to move a resource between stacks without destroying it.
First, you have to pull your destination state file locally. Say you want to move your module my_bucket from a stack in folderA to another stack in folderB:
cd folderB
terraform state pull > folderB.state
Second step, you have to move your resource to its new destination:
cd ../folderA
terraform state mv -state-out ../folderB/folderB.state module.my_bucket module.my_bucket
The mv command takes the source and destination name of your resource as parameters, so it is possible to rename your resource as you move it. As the final step, you push your destination state file to its remote location:
cd ../folderB
terraform state push folderB.state
No comments:
Post a Comment