Skip to content

Instantly share code, notes, and snippets.

@jwieringa
Last active July 5, 2018 18:01
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 jwieringa/090841f6a699a7b6628b24f5542a74f0 to your computer and use it in GitHub Desktop.
Save jwieringa/090841f6a699a7b6628b24f5542a74f0 to your computer and use it in GitHub Desktop.
A helper bash script for selectively applying Terraform resources
#!/bin/bash
plan () {
terraform plan \
-out=plan.output \
-target=module.useast1.aws_eip.nateip[3]
}
apply () {
terraform apply plan.output
}
usage () {
echo "Usage: file-sync [-s FILE] [-l FILE]"
echo " -h Help. Display this message and quit."
echo " -p Create Terraform plan in az-plan"
echo " -a Apply plan file"
}
[ $# -eq 0 ] && usage
while getopts ":pah" opt; do
case "${opt}" in
p)
plan
;;
a)
apply
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
:)
echo "Option -$OPTARG requires an argument." >&2
exit 1
;;
h | *)
usage
exit 0
;;
esac
done
shift $((OPTIND -1))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment