Skip to content

Instantly share code, notes, and snippets.

@saurabh-hirani
Last active November 19, 2023 20:15
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save saurabh-hirani/a94046c65f141eb2d7ee666fa2a21c72 to your computer and use it in GitHub Desktop.
Save saurabh-hirani/a94046c65f141eb2d7ee666fa2a21c72 to your computer and use it in GitHub Desktop.
.PHONY: all plan apply destroy
all: help
# Add the following 'help' target to your Makefile
# And add help text after each target name starting with '\#\#'
help: ## Show this help
@fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##//'
get: verify-aws-profile-set ## Get the terraform modules
AWS_PROFILE=${AWS_PROFILE} terraform get
init: verify-aws-profile-set ## Initialize remote S3 backend.
AWS_PROFILE=${AWS_PROFILE} terraform init -backend=true -backend-config="bucket=target-bucket" -backend-config="key=bucket-key.tfstate" -backend-config="region=${AWS_DEFAULT_REGION}"
plan: verify-aws-profile-set ## Plan the changes to infra.
AWS_PROFILE=${AWS_PROFILE} terraform plan -var-file=../../prod/prod.tfvars -var-file=../../common.tfvars
refresh: verify-aws-profile-set ## Refresh the remote state with existing AWS infra.
AWS_PROFILE=${AWS_PROFILE} terraform refresh -var-file=../../prod/prod.tfvars -var-file=../../common.tfvars
apply: verify-aws-profile-set ## Apply the changes in plan.
AWS_PROFILE=${AWS_PROFILE} terraform apply -var-file=../../prod/prod.tfvars -var-file=../../common.tfvars
output: verify-aws-profile-set ## See the output.
AWS_PROFILE=${AWS_PROFILE} terraform output -json
destroy: verify-aws-profile-set ## Destroy the infra.
AWS_PROFILE=${AWS_PROFILE} terraform destroy -var-file=../../prod/prod.tfvars -var-file=../../common.tfvars
verify-aws-profile-set:
ifndef AWS_PROFILE
$(error AWS_PROFILE is not defined. Make sure that you set your AWS profile and region.)
endif
ifndef AWS_DEFAULT_REGION
$(error AWS_DEFAULT_REGION is not defined. Make sure that you set your AWS region.)
endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment