forked from rhythmictech/sample-aws-project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
72 lines (58 loc) · 1.85 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
SHELL := /bin/bash
TF_WORKSPACE := $(shell terraform workspace show)
WORKSPACE ?= $(TF_WORKSPACE)
NEW= := $(NEW)
FOLDER_NAME := $(shell pwd | xargs basename)
.PHONY: setup init list apply destroy new help
ALL: help
define _help_message
cat <<EOF
aws-terraform GNUMakefiles - convenience wrapper for terraform
usage:
make TARGET
Targets:
help this message
clean get rid of .terraform directories
init initialize a new terraform context (.terraform directory)*
list list workspaces
plan produce a plan
apply apply changes
destroy destroy resources
new new workspace
The current workspace is set to: $(WORKSPACE)
* if running init for the first time
specify the workspace you'd like to connect to like so:
WORKSPACE=staging make init
EOF
endef
export help_message = $(_help_message)
help:
@eval "$$help_message"
clean:
@echo WARNING - removing local terraform dirs
rm -rf .terraform
init:
@echo Installing correct version of terraform
tfenv install
@echo sourcing environmental variables
terraform init -backend-config backend.auto.tfvars -backend-config "key=$(FOLDER_NAME).tfstate"
list:
@echo listing terraform workspaces:
terraform workspace list
plan: init
@echo planning changes to the $(WORKSPACE) workspace
terraform workspace select $(WORKSPACE)
terraform plan -var-file $(WORKSPACE).tfvars
apply: init
@echo applying changes to the $(WORKSPACE) workspace
terraform workspace select $(WORKSPACE)
terraform apply -var-file $(WORKSPACE).tfvars
destroy: init
@echo applying changes to the $(WORKSPACE) workspace
terraform workspace select $(WORKSPACE)
terraform destroy -var-file $(WORKSPACE).tfvars
new: init
@echo "create a new terraform workspace by running 'make NEW=my-new-name new'"
$(shell [ -z $(NEW) ] && echo 'please define the NEW env var'; exit 1;)
terraform workspace new $(NEW)
echo "env = \"$(NEW)\"" >> $(NEW).tfvars