Created
July 17, 2023 15:09
-
-
Save greyhoundforty/822fe17bd522390a37810751ef4493a6 to your computer and use it in GitHub Desktop.
Simple Terraform makefile
This file contains 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
UNAME:= $(shell uname) | |
ifeq ($(UNAME),Darwin) | |
OS_X := true | |
SHELL := /bin/zsh | |
else | |
OS_DEB := true | |
SHELL := /bin/bash | |
endif | |
.PHONY: initialize | |
initialize: ## Initialize Terraform configuration, format HCL and run validate | |
terraform fmt -recursive | |
terraform init -upgrade=true | |
terraform validate | |
.PHONY: validate | |
validate: ## Runs a format and validation check on the configuration files in a directory | |
terraform fmt -recursive | |
terraform validate | |
.PHONY: fmt | |
fmt: ## Rewrites config to canonical format | |
terraform fmt -recursive | |
.PHONY: plan | |
plan: ## Run a terraform plan against current workspace and save it to a file | |
terraform plan -out "$$(terraform workspace show).tfplan" | |
.PHONY: apply | |
apply: ## Run a terraform apply on previously saved plan file | |
terraform apply "$$(terraform workspace show).tfplan" | |
.PHONY: reset | |
reset: ## Clean up the local state and destroy the infrastructure | |
terraform destroy -auto-approve | |
rm -rf .terraform | |
rm -rf .terraform.lock.hcl | |
rm -rf terraform.tfstate | |
rm -rf terraform.tfstate.backup | |
rm -rf *.tfplan | |
.PHONY: all | |
all: initialize plan apply ## Initialize, plan and apply the infrastructure | |
help: | |
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' | |
.DEFAULT_GOAL := help |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment