Created
July 9, 2018 17:40
-
-
Save pocheptsov/87d9b60dc5296929938069cb11e7b466 to your computer and use it in GitHub Desktop.
Migrate multiple terraform resources under module structure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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