Skip to content

Instantly share code, notes, and snippets.

@sportebois
Created April 13, 2018 01:13
Show Gist options
  • Save sportebois/306f28aad092d8bf9a3b7897abfcbeb9 to your computer and use it in GitHub Desktop.
Save sportebois/306f28aad092d8bf9a3b7897abfcbeb9 to your computer and use it in GitHub Desktop.
Terraform Makefile
.PHONY: all info init refresh plan apply destroy fmt
# use `make plan` to do a dry-run. And same pattern for all other commands
ifndef stack
stack=terraform
endif
# Forcing AWS default region
export AWS_DEFAULT_REGION=us-east-1
info:
@echo Working with $(stack)
@sleep 2
init: info
terraform init -backend-config="$(stack)_config"
cleanplan:
@rm terraform.tfplan 2> /dev/null ||:
refresh: info cleanplan
terraform refresh -var-file=$(stack).tfvars
plan: info fmt cleanplan
terraform plan -var-file=$(stack).tfvars -out terraform.tfplan
apply: info fmt
terraform apply terraform.tfplan
destroy: info
terraform plan -destroy -var-file=$(stack).tfvars -out terraform.tfplan
@echo DESTROY about to happen, you have 30 seconds to cancel...
@sleep 30
terraform apply terraform.tfplan
fmt:
terraform get
terraform validate
terraform fmt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment