-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMakefile
50 lines (38 loc) · 1.94 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
TF_CMD ?= docker compose run --rm terraform
TF_WS ?= test
TF_AUTOAPPROVE ?= false
terraform_folderpath ?= deployment
environment_folderpath = env/${TF_WS}
override TF_AUTOAPPROVE := $(if $(filter true,$(TF_AUTOAPPROVE)),-auto-approve,)
envset:
@cat /dev/null > .env
echo "TF_WS=$(TF_WS)" >> .env
ifdef AWS_PROFILE
echo "AWS_PROFILE=$(AWS_PROFILE)" >> .env
endif
@echo AWS_ACCESS_KEY_ID=$(value AWS_ACCESS_KEY_ID) >> .env
@echo AWS_SECRET_ACCESS_KEY=$(value AWS_SECRET_ACCESS_KEY) >> .env
@echo AWS_SESSION_TOKEN=$(value AWS_SESSION_TOKEN) >> .env
check:
ifndef TF_WS
$(error TF_WS is undefined)
endif
shell: envset
$(TF_CMD) /bin/bash
init: envset check
$(TF_CMD) terraform -chdir=${terraform_folderpath} init --var-file=../${environment_folderpath}/variables.tfvars --backend-config=../${environment_folderpath}/backend.hcl --reconfigure
fmt:
$(TF_CMD) terraform fmt --recursive
sync: envset check
$(TF_CMD) terraform apply --refresh-only
validate: envset
$(TF_CMD) terraform validate
plan: envset check
$(TF_CMD) terraform -chdir=${terraform_folderpath} workspace select $(TF_WS) || $(TF_CMD) terraform -chdir=${terraform_folderpath} workspace new $(TF_WS)
$(TF_CMD) terraform -chdir=${terraform_folderpath} plan -out=$(TF_WS).tfplan -var-file=../${environment_folderpath}/variables.tfvars
apply: envset check
$(TF_CMD) terraform -chdir=${terraform_folderpath} workspace select $(TF_WS) || $(TF_CMD) terraform -chdir=${terraform_folderpath} workspace new $(TF_WS)
$(TF_CMD) terraform -chdir=${terraform_folderpath} apply -var-file=../${environment_folderpath}/variables.tfvars $(TF_AUTOAPPROVE)
destroy: envset check
$(TF_CMD) terraform -chdir=${terraform_folderpath} workspace select $(TF_WS) || $(TF_CMD) terraform -chdir=${terraform_folderpath} workspace new $(TF_WS)
$(TF_CMD) terraform -chdir=${terraform_folderpath} destroy -var-file=../${environment_folderpath}/variables.tfvars $(TF_AUTOAPPROVE)