-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
40 lines (30 loc) · 991 Bytes
/
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
tofu_dir:=tofu
tofu_cmd:=tofu -chdir=${tofu_dir}
CLUSTER?=pve-talos
VAR_FILE=vars/$(CLUSTER).tfvars
cluster:
$(MAKE) plan
$(MAKE) apply
$(MAKE) write-confs
down:
${tofu_cmd} destroy -var-file="$(VAR_FILE)"
rm $(KUBECONFIG) $(TALOSCONFIG)
rm -rf ${tofu_dir}/.terraform ${tofu_dir}/*.tfstate
validate-varfile:
@if [ ! -f "${tofu_dir}/$(VAR_FILE)" ]; then echo "File '$(VAR_FILE)' does not exist. Use CLUSTER=<your-cluster> make $(MAKECMDGOALS)"; exit 1; fi
init:
${tofu_cmd} init -upgrade
plan: init plan-fast
plan-fast: validate-varfile
${tofu_cmd} workspace select -or-create=true "$(CLUSTER)"
${tofu_cmd} plan -var-file="$(VAR_FILE)" -out "$(CLUSTER).tfplan"
apply:
${tofu_cmd} apply "$(CLUSTER).tfplan"
write-confs: $(KUBECONFIG) $(TALOSCONFIG)
${tofu_cmd} output -raw kubeconfig > $(KUBECONFIG)
${tofu_cmd} output -raw talosconfig > $(TALOSCONFIG)
chmod 600 $(KUBECONFIG)
chmod 600 $(TALOSCONFIG)
.PHONY: tofu
tofu:
${tofu_cmd} $(filter-out $@, $(MAKECMDGOALS))