-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
58 lines (48 loc) · 2.5 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
SHELL = /bin/bash
SHELLFLAGS = -ex
# Import configuration as environment variables
include ./configuration/defaults.conf
help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(firstword $(MAKEFILE_LIST)) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
.PHONY: help
####################### Enable storage API and create a bucket #######################
create-artifacts-bucket: ## Create a google cloud storage bucket to store artifacts; also enables versioning
gcloud services enable storage.googleapis.com
# `-` ignores any failures from the command
-gcloud storage buckets create gs://$(BACKEND_BUCKET_NAME) --project=$(GOOGLE_CLOUD_PROJECT_ID) --default-storage-class=$(BACKEND_BUCKET_STORAGE_CLASS) --location=$(GOOGLE_CLOUD_PROJECT_REGION) --uniform-bucket-level-access
gcloud storage buckets update gs://$(BACKEND_BUCKET_NAME) --versioning
.PHONY: create-artifacts-bucket
####################### TERRAFORM #######################
init: ## Initialize terraform's backend and providers
$(info [+] Running terraform init....)
@terraform init \
-backend-config="bucket=$(BACKEND_BUCKET_NAME)" \
-backend-config="prefix=$(BACKEND_BUCKET_TERRAFORM_PREFIX)" \
plan: ## Run terraform pre-flight checks using terraform plan
$(info [+] Running terraform plan....)
@terraform plan \
-var "project_id=$(GOOGLE_CLOUD_PROJECT_ID)" \
-var "region=$(GOOGLE_CLOUD_PROJECT_REGION)" \
-var "zone=$(GOOGLE_CLOUD_PROJECT_ZONE)" \
-var "github_organisation=$(GITHUB_ORGANISATION)" \
-var "github_repository=$(GITHUB_REPOSITORY)" \
-var "artifacts_bucket_name=$(BACKEND_BUCKET_NAME)"
apply: ## Run terraform pre-flight checks using terraform plan
$(info [+] Deploying Xplorers infra resources, standby...)
@terraform apply -auto-approve \
-var "project_id=$(GOOGLE_CLOUD_PROJECT_ID)" \
-var "region=$(GOOGLE_CLOUD_PROJECT_REGION)" \
-var "zone=$(GOOGLE_CLOUD_PROJECT_ZONE)" \
-var "github_organisation=$(GITHUB_ORGANISATION)" \
-var "github_repository=$(GITHUB_REPOSITORY)" \
-var "artifacts_bucket_name=$(BACKEND_BUCKET_NAME)"
destroy: ## Delete all resources deployed via terraform
$(info [+] Deleting all resources, standby...)
@terraform destroy -auto-approve \
-var "project_id=$(GOOGLE_CLOUD_PROJECT_ID)" \
-var "region=$(GOOGLE_CLOUD_PROJECT_REGION)" \
-var "zone=$(GOOGLE_CLOUD_PROJECT_ZONE)" \
-var "github_organisation=$(GITHUB_ORGANISATION)" \
-var "github_repository=$(GITHUB_REPOSITORY)" \
-var "artifacts_bucket_name=$(BACKEND_BUCKET_NAME)"
.PHONY: init plan apply destroy