Created
February 1, 2021 20:18
-
-
Save peterwwillis/fe932ffdc6840ce30c5a5ad59a2775b9 to your computer and use it in GitHub Desktop.
Makefile samples that I have found useful
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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