-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile
70 lines (60 loc) · 1.87 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
.PHONY: create-vpc destroy-vpc all destroy-all
.SHELL := $(shell which bash)
CURRENT_FOLDER=$(shell basename "$$(pwd)")
BOLD=$(shell tput bold)
RED=$(shell tput setaf 1)
GREEN=$(shell tput setaf 2)
YELLOW=$(shell tput setaf 3)
RESET=$(shell tput sgr0)
terraform:= $(shell command -v terraform 2> /dev/null)
aws:=$(shell command -v aws 2> /dev/null)
help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
set-env:
@if [ -z $(AWS_PROFILE) ]; then \
echo "$(BOLD)$(RED)AWS_PROFILE was not set$(RESET)"; \
ERROR=1; \
fi
@if [ ! -z $${ERROR} ] && [ $${ERROR} -eq 1 ]; then \
echo "$(BOLD)Example usage: \`AWS_PROFILE=demo make plan\`$(RESET)"; \
exit 1; \
fi
init-demo: cleanup-state set-env ## Init terraform
@echo "Prepare Backend"
@echo "$(BOLD)Configuring the terraform backend$(RESET)"
AWS_PROFILE=$(AWS_PROFILE) terraform init \
-input=false \
-reconfigure \
-lock=true \
terraform/demo
create-stacks: init-demo ## Create stacks
@echo "Create Stacks"
AWS_PROFILE=$(AWS_PROFILE) terraform apply \
-lock=true \
-input=false \
-refresh=true \
terraform/demo
plan-stacks: init-demo ## Plan what will create
AWS_PROFILE=$(AWS_PROFILE) terraform plan \
-lock=true \
-input=false \
-refresh=true \
terraform/demo
plan-destroy-stacks: init-demo ## Plan what to destroy
AWS_PROFILE=$(AWS_PROFILE) terraform plan \
-input=false \
-refresh=true \
-destroy \
terraform/demo
destroy-stacks: init-demo ## Destroy stacks
@echo "Destroy VPC"
AWS_PROFILE=$(AWS_PROFILE) terraform destroy \
-lock=true \
-input=false \
-refresh=true \
terraform/demo
cleanup-state: ## clean up the local state.
@echo "Clean up the terraform local state"
@rm -rf .terraform tf.output
all: create-stacks
destroy-all: destroy-stacks cleanup-state