-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
288 lines (258 loc) · 14 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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
ONESHELL:
SHELL := /bin/bash
.PHONY: help
validate: ## Runs `terraform validate` against all the .tf files
@for i in $$(find -type f -name "*.tf" -exec dirname {} \;); do \
terraform validate "$$i"; \
if [ $$? -ne 0 ]; then \
echo "Failed Terraform file validation on file $${i}"; \
echo; \
exit 1; \
fi; \
done
update:
@terraform get -update=true
format:
@terraform fmt
fmt:
@terraform fmt
get: ## Get the terraform modules
@terraform get
init: ## Initialize remote S3 backend.
# @terraform init -backend=true -backend-config="bucket=target-bucket" -backend-config="key=bucket-key.tfstate" -backend-config="region=${AWS_DEFAULT_REGION}"
@terraform init
plan:
@terraform plan \
-input=false \
-refresh=true \
-module-depth=-1
plan-target:
@tput setaf 3; tput bold; echo -n "[INFO] "; tput sgr0; echo "Example to type for the following question: module.rds.aws_route53_record.rds-master"
@read -p "PLAN target: " DATA &&\
terraform plan \
-input=true \
-refresh=true \
-target=$$DATA
plan-destroy: init update ## Creates a destruction plan.
@terraform plan \
-input=false \
-refresh=true \
-module-depth=-1 \
-destroy
show: init
@terraform show -module-depth=-1
graph: ## Output the `dot` graph of all the built Terraform resources
@rm -f graph.png
@terraform graph -draw-cycles -module-depth=-1 | dot -Tpng > graph.png
#@shotwell graph.png
apply: init update
@terraform apply \
-input=true \
-refresh=true
cryptotracker-destroy: init update elasticsearch-destroy app-destroy kibana-destroy
cryptotracker-plan: init update elasticsearch-plan app-plan kibana-plan
cryptotracker: init update elasticsearch app kibana
cpt-plan: init update
@terraform plan \
-refresh=true \
-target=module.crypto_pricetracker.aws_ecs_task_definition.crypto_pricetracker \
-target=module.crypto_pricetracker.aws_ecs_service.crypto_pricetracker \
-target=module.crypto_pricetracker.aws_cloudwatch_log_group.crypto_pricetracker \
-target=module.crypto_pricetracker.aws_alb_listener.crypto_pricetracker \
-target=module.crypto_pricetracker.aws_alb_listener_rule.crypto_pricetracker \
-target=module.crypto_pricetracker.aws_alb_target_group.crypto_pricetracker \
-target=module.crypto_pricetracker.aws_alb.crypto_pricetracker \
-target=module.crypto_pricetracker.aws_route53_record.crypto_pricetracker \
-target=module.crypto_pricetracker.aws_route53_record.crypto_pricetracker_public \
-target=module.crypto_pricetracker.aws_security_group.crypto_pricetracker \
-target=module.crypto_pricetracker.aws_security_group.crypto_pricetracker_external \
-target=module.crypto_pricetracker.aws_security_group_rule.allow_crypto_pricetracker_allow_outbound \
-target=module.crypto_pricetracker.aws_security_group_rule.allow_crypto_pricetracker_allow_outbound_external \
-target=module.crypto_pricetracker.aws_security_group_rule.allow_crypto_pricetracker_5000 \
-target=module.crypto_pricetracker.aws_security_group_rule.allow_crypto_pricetracker_5000_sg \
-target=module.crypto_pricetracker.aws_security_group_rule.allow_crypto_pricetracker_5000_external
cpt-destroy: init update
@terraform destroy \
-refresh=true \
-target=module.crypto_pricetracker.aws_ecs_task_definition.crypto_pricetracker \
-target=module.crypto_pricetracker.aws_ecs_service.crypto_pricetracker \
-target=module.crypto_pricetracker.aws_cloudwatch_log_group.crypto_pricetracker \
-target=module.crypto_pricetracker.aws_alb_listener.crypto_pricetracker \
-target=module.crypto_pricetracker.aws_alb_listener_rule.crypto_pricetracker \
-target=module.crypto_pricetracker.aws_alb_target_group.crypto_pricetracker \
-target=module.crypto_pricetracker.aws_alb.crypto_pricetracker \
-target=module.crypto_pricetracker.aws_route53_record.crypto_pricetracker \
-target=module.crypto_pricetracker.aws_route53_record.crypto_pricetracker_public \
-target=module.crypto_pricetracker.aws_security_group.crypto_pricetracker \
-target=module.crypto_pricetracker.aws_security_group.crypto_pricetracker_external \
-target=module.crypto_pricetracker.aws_security_group_rule.allow_crypto_pricetracker_allow_outbound \
-target=module.crypto_pricetracker.aws_security_group_rule.allow_crypto_pricetracker_allow_outbound_external \
-target=module.crypto_pricetracker.aws_security_group_rule.allow_crypto_pricetracker_5000 \
-target=module.crypto_pricetracker.aws_security_group_rule.allow_crypto_pricetracker_5000_sg \
-target=module.crypto_pricetracker.aws_security_group_rule.allow_crypto_pricetracker_5000_external
cpt: init update
@terraform apply \
-refresh=true \
-target=module.crypto_pricetracker.aws_ecs_task_definition.crypto_pricetracker \
-target=module.crypto_pricetracker.aws_ecs_service.crypto_pricetracker \
-target=module.crypto_pricetracker.aws_cloudwatch_log_group.crypto_pricetracker \
-target=module.crypto_pricetracker.aws_alb_listener.crypto_pricetracker \
-target=module.crypto_pricetracker.aws_alb_listener_rule.crypto_pricetracker \
-target=module.crypto_pricetracker.aws_alb_target_group.crypto_pricetracker \
-target=module.crypto_pricetracker.aws_alb.crypto_pricetracker \
-target=module.crypto_pricetracker.aws_route53_record.crypto_pricetracker \
-target=module.crypto_pricetracker.aws_route53_record.crypto_pricetracker_public \
-target=module.crypto_pricetracker.aws_security_group.crypto_pricetracker \
-target=module.crypto_pricetracker.aws_security_group.crypto_pricetracker_external \
-target=module.crypto_pricetracker.aws_security_group_rule.allow_crypto_pricetracker_allow_outbound \
-target=module.crypto_pricetracker.aws_security_group_rule.allow_crypto_pricetracker_allow_outbound_external \
-target=module.crypto_pricetracker.aws_security_group_rule.allow_crypto_pricetracker_5000 \
-target=module.crypto_pricetracker.aws_security_group_rule.allow_crypto_pricetracker_5000_sg \
-target=module.crypto_pricetracker.aws_security_group_rule.allow_crypto_pricetracker_5000_external
kibana-plan: init update
@terraform plan \
-refresh=true \
-target=module.cryptotracker.aws_security_group.cryptotracker \
-target=module.cryptotracker.aws_security_group_rule.allow_outbound \
-target=module.cryptotracker.aws_security_group_rule.allow_kibana_5601 \
-target=module.cryptotracker.aws_security_group_rule.allow_kibana_5601_sg \
-target=module.cryptotracker.aws_alb.cryptotracker \
-target=module.cryptotracker.aws_alb_listener.cryptotracker_kibana \
-target=module.cryptotracker.aws_alb_listener_rule.cryptotracker_kibana \
-target=module.cryptotracker.aws_alb_target_group.cryptotracker_kibana \
-target=module.cryptotracker.aws_ecs_service.cryptotracker_kibana \
-target=module.cryptotracker.aws_ecs_task_definition.cryptotracker_kibana \
-target=module.cryptotracker.aws_route53_record.cryptotracker
kibana-destroy: init update
@terraform destroy \
-refresh=true \
-target=module.cryptotracker.aws_ecs_service.cryptotracker_kibana \
-target=module.cryptotracker.aws_ecs_task_definition.cryptotracker_kibana \
-target=module.cryptotracker.aws_alb_target_group.cryptotracker_kibana \
-target=module.cryptotracker.aws_route53_record.cryptotracker
kibana: init update
@terraform apply \
-refresh=true \
-target=module.cryptotracker.aws_security_group.cryptotracker \
-target=module.cryptotracker.aws_security_group_rule.allow_outbound \
-target=module.cryptotracker.aws_security_group_rule.allow_kibana_5601 \
-target=module.cryptotracker.aws_security_group_rule.allow_kibana_5601_sg \
-target=module.cryptotracker.aws_security_group_rule.allow_kibana_external_5601 \
-target=module.cryptotracker.aws_security_group_rule.allow_elasticsearch_external_9200 \
-target=module.cryptotracker.aws_alb.cryptotracker \
-target=module.cryptotracker.aws_alb_listener.cryptotracker_kibana \
-target=module.cryptotracker.aws_alb_listener_rule.cryptotracker_kibana \
-target=module.cryptotracker.aws_alb_target_group.cryptotracker_kibana \
-target=module.cryptotracker.aws_ecs_service.cryptotracker_kibana \
-target=module.cryptotracker.aws_ecs_task_definition.cryptotracker_kibana \
-target=module.cryptotracker.aws_route53_record.cryptotracker
app-plan: init update
@terraform plan \
-input=true \
-refresh=true \
-target=module.cryptotracker.aws_ecs_task_definition.cryptotracker_app \
-target=module.cryptotracker.aws_ecs_service.cryptotracker_app
app: init update
@terraform apply \
-input=true \
-refresh=true \
-target=module.cryptotracker.aws_ecs_task_definition.cryptotracker_app \
-target=module.cryptotracker.aws_ecs_service.cryptotracker_app
elasticsearch-plan: init update
@terraform plan \
-input=true \
-refresh=true \
-target=module.cryptotracker.aws_security_group.cryptotracker \
-target=module.cryptotracker.aws_security_group_rule.allow_outbound \
-target=module.cryptotracker.aws_security_group_rule.allow_elasticsearch_9200 \
-target=module.cryptotracker.aws_security_group_rule.allow_elasticsearch_9200_sg \
-target=module.cryptotracker.aws_security_group_rule.allow_elasticsearch_9300 \
-target=module.cryptotracker.aws_security_group_rule.allow_elasticsearch_9300_sg \
-target=module.cryptotracker.aws_alb.cryptotracker \
-target=module.cryptotracker.aws_alb_listener.cryptotracker_elasticsearch \
-target=module.cryptotracker.aws_alb_listener_rule.cryptotracker_elasticsearch \
-target=module.cryptotracker.aws_alb_target_group.cryptotracker_elasticsearch \
-target=module.cryptotracker.aws_route53_record.elasticsearch \
-target=module.cryptotracker.aws_route53_record.cryptotracker \
-target=module.cryptotracker.aws_ecs_service.cryptotracker_elasticsearch \
-target=module.cryptotracker.aws_ecs_task_definition.cryptotracker_elasticsearch \
-target=module.cryptotracker.aws_cloudwatch_log_group.elasticsearch
elasticsearch: init update
@terraform apply \
-input=true \
-refresh=true \
-target=module.cryptotracker.aws_security_group.cryptotracker \
-target=module.cryptotracker.aws_security_group_rule.allow_outbound \
-target=module.cryptotracker.aws_security_group_rule.allow_elasticsearch_9200 \
-target=module.cryptotracker.aws_security_group_rule.allow_elasticsearch_9200_sg \
-target=module.cryptotracker.aws_security_group_rule.allow_elasticsearch_9300 \
-target=module.cryptotracker.aws_security_group_rule.allow_elasticsearch_9300_sg \
-target=module.cryptotracker.aws_alb.cryptotracker \
-target=module.cryptotracker.aws_alb_listener.cryptotracker_elasticsearch \
-target=module.cryptotracker.aws_alb_listener_rule.cryptotracker_elasticsearch \
-target=module.cryptotracker.aws_alb_target_group.cryptotracker_elasticsearch \
-target=module.cryptotracker.aws_route53_record.elasticsearch \
-target=module.cryptotracker.aws_route53_record.cryptotracker \
-target=module.cryptotracker.aws_ecs_service.cryptotracker_elasticsearch \
-target=module.cryptotracker.aws_ecs_task_definition.cryptotracker_elasticsearch \
-target=module.cryptotracker.aws_ecs_task_definition.cryptotracker_elasticsearch \
-target=module.cryptotracker.aws_cloudwatch_log_group.elasticsearch
elasticsearch-destroy: init update
@terraform destroy \
-input=true \
-refresh=true \
-target=module.cryptotracker.aws_security_group.cryptotracker \
-target=module.cryptotracker.aws_security_group_rule.allow_outbound \
-target=module.cryptotracker.aws_security_group_rule.allow_elasticsearch_9200 \
-target=module.cryptotracker.aws_security_group_rule.allow_elasticsearch_9200_sg \
-target=module.cryptotracker.aws_security_group_rule.allow_elasticsearch_9300 \
-target=module.cryptotracker.aws_security_group_rule.allow_elasticsearch_9300_sg \
-target=module.cryptotracker.aws_alb.cryptotracker \
-target=module.cryptotracker.aws_alb_listener.cryptotracker_elasticsearch \
-target=module.cryptotracker.aws_alb_listener_rule.cryptotracker_elasticsearch \
-target=module.cryptotracker.aws_alb_target_group.cryptotracker_elasticsearch \
-target=module.cryptotracker.aws_route53_record.elasticsearch \
-target=module.cryptotracker.aws_route53_record.cryptotracker \
-target=module.cryptotracker.aws_ecs_service.cryptotracker_elasticsearch \
-target=module.cryptotracker.aws_ecs_task_definition.cryptotracker_elasticsearch \
-target=module.cryptotracker.aws_ecs_task_definition.cryptotracker_elasticsearch \
-target=module.cryptotracker.aws_cloudwatch_log_group.elasticsearch
apply-target: init update ## Apply a specific resource and any chained resources.
@tput setaf 3; tput bold; echo -n "[INFO] "; tput sgr0; echo "Specifically APPLY a piece of Terraform data."
@tput setaf 3; tput bold; echo -n "[INFO] "; tput sgr0; echo "Example to type for the following question: module.rds.aws_route53_record.rds-master"
@tput setaf 1; tput bold; echo -n "[DANGER] "; tput sgr0; echo "You are about to apply a new state."
@tput setaf 1; tput bold; echo -n "[DANGER] "; tput sgr0; echo "This has the potential to break your infrastructure."
@read -p "APPLY target: " DATA &&\
terraform apply \
-input=true \
-refresh=true \
-target=$$DATA
output: init update ## Display all outputs from the remote state file.
@echo "Example to type for the module: MODULE=module.rds.aws_route53_record.rds-master"
@echo
@if [ -z $(MODULE) ]; then\
terraform output;\
else\
terraform output -module=$(MODULE);\
fi
taint: init update ## Taint a resource for destruction upon next `apply`
@echo "Tainting involves specifying a module and a resource"
@read -p "Module: " MODULE && \
read -p "Resource: " RESOURCE && \
terraform taint \
-module=$$MODULE $$RESOURCE
@echo "You will now want to run a plan to see what changes will take place"
destroy: init update ## Destroys everything. There is a prompt before destruction.
@terraform destroy \
-var-file=environments/$(ENVIRONMENT)/$(ENVIRONMENT).tfvars \
-var-file=$(ENVIRONMENT).tfvars
destroy-target: init update ## Destroy a specific resource. Caution though, this destroys chained resources.
@echo "Specifically destroy a piece of Terraform data."
@echo
@echo "Example to type for the following question: module.rds.aws_route53_record.rds-master"
@echo
@read -p "Destroy target: " DATA &&\
terraform destroy \
-var-file=environments/$(ENVIRONMENT)/$(ENVIRONMENT).tfvars \
-var-file=$(ENVIRONMENT).tfvars \
-target=$$DATA