Skip to content

Instantly share code, notes, and snippets.

@daern91
Created September 14, 2021 08:15
Show Gist options
  • Save daern91/21de9384b1887a553e848efe87cee5b2 to your computer and use it in GitHub Desktop.
Save daern91/21de9384b1887a553e848efe87cee5b2 to your computer and use it in GitHub Desktop.
script to move terraform states
# 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