Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save pocheptsov/87d9b60dc5296929938069cb11e7b466 to your computer and use it in GitHub Desktop.
Save pocheptsov/87d9b60dc5296929938069cb11e7b466 to your computer and use it in GitHub Desktop.
Migrate multiple terraform resources under module structure
# grab all resources that will be marked for deletion and has [prefix]_[name].[suffix] template
# change module.name with yours naming
terraform plan -no-color awk '$1 == "-" && $2 ~ /.*_.*\..*/ { print "terraform state mv " $2 " module.name." $2 }' > mv_state.sh
# apply state changes
./mv_state.sh
# remove backups after checking state
rm -f terraform.tfstate.*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment