-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
74 lines (62 loc) · 1.6 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
71
72
73
74
.ONESHELL:
.SHELL := /bin/bash
.PHONY: apply destroy plan-destroy plan prep
BASE="./roots/$(APP)"
VARS="$(BASE)/env/$(ENV).tfvars"
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)
WORKSPACE="$(APP)"
help:
@echo "$(BOLD)help!$(RESET)"
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
set-env:
@echo "Working with root $(GREEN)$(BASE)$(RESET) env $(GREEN)$(VARS)$(RESET)"
@if [ -z $(ENV) ]; then \
echo "$(BOLD)$(RED)ENV was not set$(RESET)"; \
ERROR=1; \
fi
@if [ ! -z $${ERROR} ] && [ $${ERROR} -eq 1 ]; then \
echo "$(BOLD)Example usage: \`ENV=prod ROOT=roots\app make plan\`$(RESET)"; \
exit 1; \
fi
@if [ ! -f "$(VARS)" ]; then \
echo "$(BOLD)$(RED)Could not find variables file: $(VARS)$(RESET)"; \
exit 1; \
fi
prep: set-env
@echo "$(BOLD)Configuring terraform $(RESET)"
@terraform init \
-upgrade \
-verify-plugins \
"$(BASE)"
@terraform workspace select $(WORKSPACE) || terraform workspace new $(WORKSPACE)
plan: prep
@terraform plan \
-input=false \
-refresh=true \
-var-file="$(VARS)" \
"$(BASE)"
plan-destroy: prep
@terraform plan \
-input=false \
-refresh=true \
-destroy \
-var-file="$(VARS)" \
"$(BASE)"
apply: prep
@terraform apply \
-input=false \
-refresh=true \
-var-file="$(VARS)" \
-auto-approve \
"$(BASE)"
destroy: prep
@terraform destroy \
-input=false \
-refresh=true \
-var-file="$(VARS)" \
"$(BASE)"