Suppose you have a terraform/terragrunt directory that you have already applied. Now you want to move the directory to some other destination.
Here's what you can do-
- Ensure the to-be-refactored module has no pending changes
terragrunt planshould outputNo Changes - Pull the current state into a temp file
terragrunt state pull > /tmp/local.tfstate - Move (or Copy) the terragrunt module folder to the desired location
- Run
terragrunt planin the new folder. This should show you all the changes that terragrunt will make to your infrastructure. This makes sense since you haven't yet migrated the terraform state and terraform therefore thinks its a new infrastructure - Upload the state. Run
terragrunt state push /tmp/local.tfstate. you should notice that the command outputs successfully. At this point the state is committed to terraform remote state bucket - Run
terragrunt planto ensure that this time it showsNo Changes