-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
58 lines (48 loc) · 1.75 KB
/
Makefile
File metadata and controls
58 lines (48 loc) · 1.75 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
TERRAFORM ?= terraform
TFLINT ?= tflint
DIR ?= .
APP_ID = "" # will be set in GitHub Actions
APP_INSTALLATION_ID = "" # will be set in GitHub Actions
TERRAFORM_VARS = -var-file=pem.tfvars -var-file=users.tfvars
TERRAFORM_PLAN_PATH = .terraform/terraform.plan
GITHUB_ACTIONS ?= false
confirm:
@read -p "Continue? [$(ENVIRONMENT)] : " environment && [ "$$environment" = "$(ENVIRONMENT)" ]
init:
@cd $(DIR) && \
$(TERRAFORM) init
.PHONY: prepare
prepare: init validate
.PHONY: plan
plan: prepare
@cd $(DIR) && \
$(if $(filter true,$(GITHUB_ACTIONS)), export GITHUB_APP_ID=$(APP_ID) && \
export GITHUB_APP_INSTALLATION_ID=$(APP_INSTALLATION_ID) && ,) \
$(TERRAFORM) plan -no-color -lock=false $(TERRAFORM_VARS) -out $(TERRAFORM_PLAN_PATH)
plan-with-lock: prepare
@cd $(DIR) && \
$(if $(filter true,$(GITHUB_ACTIONS)), export GITHUB_APP_ID=$(APP_ID) && \
export GITHUB_APP_INSTALLATION_ID=$(APP_INSTALLATION_ID) && ,) \
$(TERRAFORM) plan -no-color -lock=true $(TERRAFORM_VARS) -out $(TERRAFORM_PLAN_PATH)
.PHONY: apply-force
apply-force: plan-with-lock
@cd $(DIR) && \
$(if $(filter true,$(GITHUB_ACTIONS)), export GITHUB_APP_ID=$(APP_ID) && \
export GITHUB_APP_INSTALLATION_ID=$(APP_INSTALLATION_ID) && ,) \
$(TERRAFORM) apply -no-color -lock=true $(TERRAFORM_PLAN_PATH)
format: # useful in local development
@cd $(DIR) && \
$(TERRAFORM) fmt -diff -recursive
format-check:
@cd $(DIR) && \
$(TERRAFORM) fmt -diff -recursive -check
lint:
@cd $(DIR) && \
$(TERRAFORM) get && $(TFLINT) -c $(PWD)/.tflint.hcl; \
validate:
@cd $(DIR) && \
$(if $(filter true,$(GITHUB_ACTIONS)), export GITHUB_APP_ID=$(APP_ID) && \
export GITHUB_APP_INSTALLATION_ID=$(APP_INSTALLATION_ID) && ,) \
echo $$GITHUB_APP_ID && \
echo $$GITHUB_APP_INSTALLATION_ID && \
$(TERRAFORM) validate