-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathMakefile
More file actions
64 lines (47 loc) · 1.64 KB
/
Makefile
File metadata and controls
64 lines (47 loc) · 1.64 KB
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
-include .env
interactionId=$(ENVIRONMENT)
tf_cmd = AWS_PROFILE=$(AWS_PROFILE) terraform
tf_state= -backend-config="bucket=$(BUCKET_NAME)"
tf_vars= -var-file=environments/$(ENVIRONMENT)/variables.tfvars
define require_bucket_name
@if [ -z "$(strip $(BUCKET_NAME))" ]; then \
echo "BUCKET_NAME variable not set. Use 'make init ENVIRONMENT=... BUCKET_NAME=...'"; \
exit 1; \
fi
endef
.PHONY: lock-provider workspace init plan apply clean destroy output tf-%
lock-provider:
# Run this only when you install a new terraform provider. This will generate sha code in lock file for all platform
echo "This may take a while. Be patient!"
$(tf_cmd) providers lock -platform=darwin_arm64 -platform=darwin_amd64 -platform=linux_amd64 -platform=windows_amd64
workspace:
$(tf_cmd) workspace select -or-create $(ENVIRONMENT) && echo "Switched to workspace/environment: $(ENVIRONMENT)"
init:
$(require_bucket_name)
$(tf_cmd) init $(tf_state) -upgrade $(tf_vars)
init-reconfigure:
$(require_bucket_name)
$(tf_cmd) init $(tf_state) -upgrade $(tf_vars) -reconfigure
plan: workspace
$(tf_cmd) plan $(tf_vars)
plan-ci: workspace
$(tf_cmd) plan $(tf_vars) -out=tfplan -input=false
apply: workspace
$(tf_cmd) apply $(tf_vars) -auto-approve
apply-ci: workspace
$(tf_cmd) apply -input=false tfplan
clean:
rm -rf build .terraform upload-key
destroy: workspace
$(tf_cmd) destroy $(tf_vars) -auto-approve
$(tf_cmd) workspace select default
$(tf_cmd) workspace delete $(ENVIRONMENT)
output:
ifndef name
$(error name variable not set. Use 'make output name=...')
endif
$(tf_cmd) output -raw $(name)
import:
$(tf_cmd) import $(tf_vars) $(to) $(id)
tf-%:
$(tf_cmd) $*