Skip to content

Instantly share code, notes, and snippets.

@kruttik-lab49
Last active January 29, 2021 20:41
Show Gist options
  • Select an option

  • Save kruttik-lab49/2bf1e190e9a90f044995e5e3eea3b4b0 to your computer and use it in GitHub Desktop.

Select an option

Save kruttik-lab49/2bf1e190e9a90f044995e5e3eea3b4b0 to your computer and use it in GitHub Desktop.
TWL-Lab49/Terraform & Terragrunt folder refactoring & state management trick

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 plan should output No 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 plan in 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 plan to ensure that this time it shows No Changes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment