-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
75 lines (59 loc) · 1.78 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
# Makefile to interact with terraform
SHELL := /bin/bash
ifndef ACCNAME
$(error ACCNAME is not set)
endif
ifndef ENVNAME
$(error ENVNAME is not set)
endif
ifndef REGION
$(error REGION is not set)
endif
# vars to import
VARS=-var "accname=$(ACCNAME)" \
-var "envname=$(ENVNAME)" \
-var "aws_region=$(REGION)"
# Build tfvars hierarchy for import
VARFILE=
ifneq (,$(wildcard tfvars/default.tfvars))
VARFILE=-var-file=tfvars/default.tfvars
endif
ifneq (,$(wildcard tfvars/$(ACCNAME).tfvars))
VARFILE+= -var-file=tfvars/$(ACCNAME).tfvars
endif
ifneq (,$(wildcard tfvars/$(ACCNAME)_$(REGION).tfvars))
VARFILE+= -var-file=tfvars/$(ACCNAME)_$(REGION).tfvars
endif
ifneq (,$(wildcard tfvars/$(ACCNAME)_$(ENVNAME).tfvars))
VARFILE+= -var-file=tfvars/$(ACCNAME)_$(ENVNAME).tfvars
endif
ifneq (,$(wildcard tfvars/$(ACCNAME)_$(ENVNAME)_$(REGION).tfvars))
VARFILE+= -var-file=tfvars/$(ACCNAME)_$(ENVNAME)_$(REGION).tfvars
endif
GPATH=$(shell git rev-parse --git-dir)
CPATH=$(shell pwd)
APATH=$(subst .git,,$(GPATH))
NPATH=$(subst $(APATH),,$(CPATH))
BASENAME=$(shell basename `git rev-parse --show-toplevel`)
FUNCTION="poc-git-actions"
SF_BUCKET="terraform-states-$(ACCNAME)"
SF_KEY="$(ENVNAME)/services/$(FUNCTION)/$(REGION)/terraform.tfstate"
SF_REGION="us-east-1"
export AWS_DEFAULT_REGION=$(REGION)
begin: plan
clean:
rm -rf .terraform ./modules tfplan
init: clean
terraform get .
terraform init -backend-config="bucket=$(SF_BUCKET)" -backend-config="key=$(SF_KEY)" -backend-config="region=$(SF_REGION)"
refresh: init
terraform refresh $(VARS) $(VARFILE) .
plan: init
terraform plan $(VARS) $(VARFILE) -out tfplan .
apply:
terraform apply tfplan
rm tfplan
terraform taint null_resource.build
destroy: init
terraform plan -destroy $(VARS) $(VARFILE) .
terraform destroy $(VARS) $(VARFILE) .