Created
September 14, 2021 08:15
-
-
Save daern91/21de9384b1887a553e848efe87cee5b2 to your computer and use it in GitHub Desktop.
script to move terraform states
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
# Run plan and check how many we can move | |
# then run repeat command with the amount | |
# repeat 27 { sh move_tf_state.sh } | |
tomove=$(terraform plan | grep 'destroyed\|created' | awk 'NR==1 {print $3}' | sed $'s,\x1b\\[[0-9;]*[a-zA-Z],,g') | |
if [ -z "$tomove" ] | |
then | |
echo no state to move | |
else | |
echo found state to move... | |
echo "about to move $tomove" | |
terraform state mv $tomove module.<insert-module-name>.$tomove | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment