Skip to content

Instantly share code, notes, and snippets.

@ozgurgul
Forked from peterwwillis/Makefile
Created February 9, 2021 00:07
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 ozgurgul/e51808a6ca5ab199650b4a425bdf45e7 to your computer and use it in GitHub Desktop.
Save ozgurgul/e51808a6ca5ab199650b4a425bdf45e7 to your computer and use it in GitHub Desktop.
Makefile samples that I have found useful
# This Makefile allows you to pass arguments to 'make', and have those get passed into commands for a target.
# This also shows how to automatically generate a help menu using specially annotated comments on targets.
#
# Usage:
# - make help
# List of available targets:
#
# help List all available targets (default)
# jenkins-cluster Run terraformctl on the aws-jenkins-cluster root module
# cognito-userpool Run terraformctl for the cognito user pool
# cognito-azuread Run terraformctl for the cognito AzureAD identity pool
# cognito-app Run terraformctl for the cognito Jenkins application
# - make jenkins-cluster plan apply
# ./bin/terraformctl \
# -f /path/to/terraform.tfvars.json \
# -b /path/to/backend.tfvars \
# -C ./terraform/modules/root/aws-jenkins-cluster \
# plan \
# apply
#
# Note that you have to use 'make -- target args [..]' if your args include a "-f" type option.
#
TERRAFORMCTL = ./bin/terraformctl
TFVARS = $(shell readlink -f terraform.tfvars.json)
BACKEND_TFVARS = $(shell readlink -f backend.tfvars)
ROOT_MODS = ./terraform/modules/root/
_TERRAFORMCTL = $(TERRAFORMCTL) -f $(TFVARS) -b $(BACKEND_TFVARS)
.PHONY: help jenkins-cluster cognito-userpool cognito-azuread cognito-app
help: #TARGET List all available targets (default)
@echo "List of available targets:"
@echo ""
@grep -P '^[^#:]+\:.*\s#TARGET' Makefile \
| sed -E 's/^([^#:]+)\:.*\s#TARGET\s(.*)/ \1§\2/' \
| column -s § -t
@echo ""
jenkins-cluster: #TARGET Run terraformctl on the aws-jenkins-cluster root module
@$(_TERRAFORMCTL) -C $(ROOT_MODS)/aws-jenkins-cluster $(filter-out $@,$(MAKECMDGOALS))
cognito-userpool: #TARGET Run terraformctl for the cognito user pool root module
@$(_TERRAFORMCTL) -C $(ROOT_MODS)/aws-infra-cognito-userpool $(filter-out $@,$(MAKECMDGOALS))
cognito-azuread: #TARGET Run terraformctl for the cognito AzureAD identity pool root module
@$(_TERRAFORMCTL) -C $(ROOT_MODS)/aws-infra-cognito-azuread $(filter-out $@,$(MAKECMDGOALS))
cognito-app: #TARGET Run terraformctl for the cognito Jenkins application root module
@$(_TERRAFORMCTL) -C $(ROOT_MODS)/aws-infra-cognito-app $(filter-out $@,$(MAKECMDGOALS))
# Do-nothing target; needed for the 'filter-out' magic above
%:
@:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment