-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
165 lines (149 loc) · 4.58 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
SHELL := $(shell which bash)
TF := $(shell command -v terraform 2> /dev/null)
TFVARS_DEV_FILE=tf_dev_tokyo.tfvars
TFVARS_PROD_FILE=tf_prod_seoul.tfvars
.SILENT: ; # no need for @
PHONY: get-tools
get-tools: # Install tools for development: # make get-tools
echo "Installing brew packages.."
HOMEBREW_BUNDLE_NO_LOCK=1 brew bundle
echo "Installing terrafrom.. "
ifdef TF
mv "$(shell which terraform)" "$(shell which terraform)".bak
endif
tfswitch -l
PHONY: init
ifeq (init,$(firstword $(MAKECMDGOALS)))
ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))
$(eval $(ARGS):;@:)
endif
init: # Initialize project: # make init {env}
scripts/init.sh $(ARGS)
PHONY: plan
ifeq (plan,$(firstword $(MAKECMDGOALS)))
ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))
$(eval $(ARGS):;@:)
endif
plan: # Plan project: # make plan {env}
ifeq ($(ARGS),prod)
terraform plan -var-file=config/$(TFVARS_PROD_FILE)
else
terraform plan -var-file=config/$(TFVARS_DEV_FILE)
endif
.PHONY: plan-vpc
ifeq (plan-vpc,$(firstword $(MAKECMDGOALS)))
ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))
$(eval $(ARGS):;@:)
endif
plan-vpc: # Generates an execution plan for vpc : # make plan-vpc dev
ifeq ($(ARGS),prod)
echo "Using $(TFVARS_PROD_FILE).."
terraform plan \
-var-file=config/$(TFVARS_PROD_FILE) \
-target=module.global \
-target=module.vpc_shared \
-target=module.vpc_dev
else
echo "Using $(TFVARS_DEV_FILE).."
terraform plan \
-var-file=config/$(TFVARS_DEV_FILE) \
-target=module.global \
-target=module.vpc_shared \
-target=module.vpc_dev
endif
.PHONY: apply-vpc
ifeq (apply-vpc,$(firstword $(MAKECMDGOALS)))
ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))
$(eval $(ARGS):;@:)
endif
apply-vpc: # Apply an execution plan for vpc : # make apply-vpc dev
ifeq ($(ARGS),prod)
echo "Using $(TFVARS_PROD_FILE).."
terraform apply \
-var-file=config/$(TFVARS_PROD_FILE) \
-target=module.global \
-target=module.vpc_shared \
-target=module.vpc_dev
else
echo "Using $(TFVARS_DEV_FILE).."
terraform apply \
-var-file=config/$(TFVARS_DEV_FILE) \
-target=module.global \
-target=module.vpc_shared \
-target=module.vpc_dev
endif
.PHONY: plan-vpn
ifeq (plan-vpn,$(firstword $(MAKECMDGOALS)))
ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))
$(eval $(ARGS):;@:)
endif
plan-vpn: # Generates an execution plan for vpn : # make plan-vpn dev
ifeq ($(ARGS),prod)
echo "Using $(TFVARS_PROD_FILE).."
terraform plan \
-var-file=config/$(TFVARS_PROD_FILE) \
-target=module.global \
-target=module.vpn_in_shared
else
echo "Using $(TFVARS_DEV_FILE).."
terraform plan \
-var-file=config/$(TFVARS_DEV_FILE) \
-target=module.global \
-target=module.vpn_in_shared
endif
.PHONY: apply-vpn
ifeq (apply-vpn,$(firstword $(MAKECMDGOALS)))
ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))
$(eval $(ARGS):;@:)
endif
apply-vpn: # Apply an execution plan for vpn : # make apply-vpb dev
ifeq ($(ARGS),prod)
echo "Using $(TFVARS_PROD_FILE).."
terraform apply \
-var-file=config/$(TFVARS_PROD_FILE) \
-target=module.global \
-target=module.vpn_in_shared
else
echo "Using $(TFVARS_DEV_FILE).."
terraform apply \
-var-file=config/$(TFVARS_DEV_FILE) \
-target=module.global \
-target=module.vpn_in_shared
endif
PHONY: apply
ifeq (apply,$(firstword $(MAKECMDGOALS)))
ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))
$(eval $(ARGS):;@:)
endif
apply: # Apply project: # make apply {env}
ifeq ($(ARGS),prod)
terraform apply -var-file=config/$(TFVARS_PROD_FILE)
else
terraform apply -var-file=config/$(TFVARS_DEV_FILE)
endif
PHONY: destroy
ifeq (destroy,$(firstword $(MAKECMDGOALS)))
ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))
$(eval $(ARGS):;@:)
endif
destroy: # Destroy project: # make apply {env}
ifeq ($(ARGS),prod)
terraform destroy -var-file=config/$(TFVARS_PROD_FILE)
else
terraform destroy -var-file=config/$(TFVARS_DEV_FILE)
endif
PHONY: clean
clean: # Clean terraform: # make clean
rm -rf .terraform
rm -rf terraform.tfstate.d
PHONY: check-scripts
check-scripts: # Check scripts: # make check-scripts
shellcheck scripts/*.sh
PHONY: show-azs
show-azs: # List availability zones from current region: # make show-azs
aws ec2 describe-availability-zones | jq -c '[.AvailabilityZones[].ZoneName]|join(",")'
PHONY: help
help: # Show this help message: # make help
echo "Usage: make [command] [args]"
grep -E '^[a-zA-Z_-]+:.*?# .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ": # "}; {printf "\t\033[36m%-20s\033[0m \033[33m%-30s\033[0m (e.g. \033[32m%s\033[0m)\n", $$1, $$2, $$3}'
.DEFAULT_GOAL := help