From 87cd7d1a203139e072beb048d3eabb4afcffecaf Mon Sep 17 00:00:00 2001 From: Dwight Spencer Date: Mon, 14 Feb 2022 12:04:30 -0600 Subject: [PATCH] (feat) Refactored as a fully fleshed out makefile - Added tflint support - Added procedural steps with dependencies - Added step to install plugins and providers - Added command flag support - Added self documenting code `make help` - Added self execution code `chmod +x Makefile; ./Makefile all` - Set default target to display help --- with-terraform/Makefile | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/with-terraform/Makefile b/with-terraform/Makefile index f9450bc4..3cae72ba 100644 --- a/with-terraform/Makefile +++ b/with-terraform/Makefile @@ -1,8 +1,24 @@ -fmt: - terraform fmt +#!/usr/bin/env -- make -f +######################################## -plan: - terraform plan +TF := $(command -v terraform) +TFLINT := $(command -v tflint) +TF_OPTS := +TFLINT_OPTS := -apply: - terraform apply \ No newline at end of file +######################################## +.DEFAULT: help +PHONY: all help fmt init plan apply + +help: ## Show this help + @egrep -h '\s##\s' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' + +deps: init ## install plugins and providers + +all: deps fmt plan ## install dependancies then format and execute 'terraform plan' + +lint: fmt ## format hcl files and run the linter + $(TFLINT) $(TFLINT_OPTS) . + +init fmt plan apply: ## default rule to execute terrafrom sub commands + $(TF) $(TF_OPTS) $@