forked from firecracker-microvm/firecracker
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
56 lines (48 loc) · 1.7 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
ENV := $(shell cat .last_used_env || echo "not-set")
-include .env.${ENV}
tf_vars := TF_VAR_gcp_project_id=$(GCP_PROJECT_ID) \
TF_VAR_gcp_region=$(GCP_REGION) \
TF_VAR_gcp_zone=$(GCP_ZONE) \
TF_VAR_prefix=$(PREFIX) \
TF_VAR_terraform_state_bucket=$(TERRAFORM_STATE_BUCKET)
# Login for Packer and Docker (uses gcloud user creds)
# Login for Terraform (uses application default creds)
.PHONY: login-gcloud
login-gcloud:
gcloud auth login
gcloud config set project "$(GCP_PROJECT_ID)"
gcloud --quiet auth configure-docker "$(GCP_REGION)-docker.pkg.dev"
gcloud auth application-default login
.PHONY: init
init:
@ printf "Initializing Terraform for env: `tput setaf 2``tput bold`$(ENV)`tput sgr0`\n\n"
terraform init -input=false -backend-config="bucket=${TERRAFORM_STATE_BUCKET}"
.PHONY: plan
plan:
@ printf "Planning Terraform for env: `tput setaf 2``tput bold`$(ENV)`tput sgr0`\n\n"
terraform fmt -recursive
$(tf_vars) terraform plan -compact-warnings -detailed-exitcode
.PHONY: apply
apply:
@ printf "Applying Terraform for env: `tput setaf 2``tput bold`$(ENV)`tput sgr0`\n\n"
$(tf_vars) \
terraform apply \
-auto-approve \
-input=false \
-compact-warnings \
-parallelism=20
.PHONY: destroy
destroy:
@ printf "Destroying Terraform for env: `tput setaf 2``tput bold`$(ENV)`tput sgr0`\n\n"
$(tf_vars) \
terraform destroy \
-input=false \
-compact-warnings \
-parallelism=20
.PHONY: switch-env
switch-env:
@ touch .last_used_env
@ printf "Switching from `tput setaf 1``tput bold`$(shell cat .last_used_env)`tput sgr0` to `tput setaf 2``tput bold`$(ENV)`tput sgr0`\n\n"
@ echo $(ENV) > .last_used_env
@ . .env.${ENV}
terraform init -input=false -reconfigure -backend-config="bucket=${TERRAFORM_STATE_BUCKET}"