Skip to content

Instantly share code, notes, and snippets.

@immanuelpotter
Last active August 15, 2020 05:39
Show Gist options
  • Select an option

  • Save immanuelpotter/3fae4d15150dc5f094ca69454b18d333 to your computer and use it in GitHub Desktop.

Select an option

Save immanuelpotter/3fae4d15150dc5f094ca69454b18d333 to your computer and use it in GitHub Desktop.
If you only want to perform actions on resources in one terraform file, this will do that for you
#!/bin/bash
COMMAND="$1"
TF_FILE="$2"
usage(){
echo "Usage: $0 (plan|apply|destroy) [tf-filename]"
}
main(){
if [[ -z $COMMAND || -z $TF_FILE ]] ; then
usage
else
for i in $(awk '/resource/{print $2,$3}' $TF_FILE | tr -d '"' | tr ' ' '.') ; do $(which terraform) $COMMAND -target="${i}" ; done
fi
}
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment