Skip to content

Instantly share code, notes, and snippets.

@Laxman-SM
Forked from immanuelpotter/tfonly
Created August 15, 2020 05:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Laxman-SM/7dd4aaaa0b8457310f868200e1788d53 to your computer and use it in GitHub Desktop.
Save Laxman-SM/7dd4aaaa0b8457310f868200e1788d53 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