-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
71 lines (57 loc) · 2.36 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
ENV = $(filter-out $(firstword $(MAKECMDGOALS)), $(MAKECMDGOALS))
TERRAFORM_GLOBAL_OPTIONS= "-chdir=terraform"
.PHONY: help
help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
.PHONY: apply
apply: init ## Applies a new state.
@tofu $(TERRAFORM_GLOBAL_OPTIONS) apply -input=true -refresh=true "terraform.tfplan"
.PHONY: graph
graph: ## Runs the terraform grapher
@rm -f terraform/graph.png
@tofu $(TERRAFORM_GLOBAL_OPTIONS) graph -draw-cycles | dot -Tpng > graph.png
@open graph.png
.PHONY: get-kubeconfig
get-kubeconfig: ## Gets the kubeconfig for the environment if it doesn't exist.
@mkdir -p ~/.kube/config-files
@test -s ~/.kube/config-files/$(ENV).yaml || \
curl -s -H "X-Vault-Request: true" \
-H "X-Vault-Token: $(VAULT_TOKEN)" \
$(VAULT_ADDR)/v1/kv/data/$(ENV)/k3s \
| jq -r '.data.data.kubeconfig' \
| base64 -d > ~/.kube/config-files/$(ENV).yaml
.PHONY: init
init: get-kubeconfig ## Initializes the terraform remote state backend and pulls the correct environments state.
@./terraform/helper.sh $(ENV) $(TERRAFORM_GLOBAL_OPTIONS)
.PHONY: output
output: init ## Show outputs of the entire state.
@tofu $(TERRAFORM_GLOBAL_OPTIONS) output -json
.PHONY: plan
plan: init ## Runs a plan.
@tofu $(TERRAFORM_GLOBAL_OPTIONS) plan -out=terraform.tfplan
.PHONY: plan-custom
plan-custom: init ## Runs a plan with custom options.
@tofu $(TERRAFORM_GLOBAL_OPTIONS) plan -out=terraform.tfplan $(OPTIONS)
.PHONY: comment-pr
comment-pr: ## Posts the terraform plan as a PR comment.
@./terraform/comment-pr.sh $(TERRAFORM_GLOBAL_OPTIONS)
.PHONY: plan-destroy
plan-destroy: init ## Shows what a destroy would do.
@tofu $(TERRAFORM_GLOBAL_OPTIONS) plan -input=false -refresh=true -destroy -out=terraform.tfplan
.PHONY: show
show: init ## Shows resources
@tofu $(TERRAFORM_GLOBAL_OPTIONS) show
.PHONY: upgrade
upgrade: ## Gets any provider updates
@tofu $(TERRAFORM_GLOBAL_OPTIONS) init -upgrade
.PHONY: upgrade-kubernetes-version
upgrade-kubernetes-version: ## Checks and upgrades k3s version if necessary
@python latest_k3s_version.py
.PHONY: FORCE
%: FORCE
@if [ "$(MAKECMDGOALS)" != "help" ] \
&& [ "$(MAKECMDGOALS)" != "upgrade-kubernetes-version" ] \
&& [ "$(ENV)" = "" ]; then \
echo "Environment was not set properly, check README.md"; \
exit 1; \
fi