-
Notifications
You must be signed in to change notification settings - Fork 0
/
Taskfile.yaml
95 lines (85 loc) · 3.39 KB
/
Taskfile.yaml
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
version: 3
dotenv:
- ./configuration/defaults.conf
tasks:
terraform-providers-lock:
desc: Lock terraform providers for all platforms
cmds:
- |
terraform providers lock -platform=windows_amd64 -platform=darwin_amd64 -platform=linux_amd64
terraform-fmt:
desc: Format terraform files
cmds:
- |
terraform fmt
terraform-init:
desc: Initialize terraform backend, providers, plugins and modules
deps:
- terraform-providers-lock
cmds:
- |
terraform init \
-backend-config="bucket=${ARTIFACTS_BUCKET_NAME}" \
-backend-config="prefix=${ARTIFACTS_BUCKET_TERRAFORM_PREFIX}"
switch-to-terraform-workspace:
dir: terraform
desc: Switch to the terraform workspace
silent: true
cmds:
- |
GREEN='\033[0;32m'
if [ "${TERRAFORM_WORKSPACE}" == "prod" ]; then
RED='\033[0;31m'
NC='\033[0m' # No Color
echo -e "${RED}###############################################################"
echo -e "# WARNING: You are about to make changes to the production #"
echo -e "# environment. #"
echo -e "# #"
echo -e "# If creating a feature branch, update 'TERRAFORM_WORKSPACE' #"
echo -e "# in 'configuration/defaults.conf' and run this command #"
echo -e "# again. #"
echo -e "# #"
echo -e "# Please confirm to proceed. #"
echo -e "###############################################################${NC}\n"
read -p "Are you sure you want to proceed? (yes/no): " confirmation
if [ "$confirmation" != "yes" ]; then
echo "Operation aborted."
exit 1
fi
fi
terraform workspace new ${TERRAFORM_WORKSPACE} > /dev/null 2>&1 || true
terraform workspace select ${TERRAFORM_WORKSPACE}
echo -e "Successfully switched to terraform workspace: ${GREEN}${TERRAFORM_WORKSPACE}${NC}"
terraform-plan:
desc: Creates an execution plan, which lets you preview the changes that Terraform plans to make to your infrastructure.
cmds:
- task: switch-to-terraform-workspace
- task: terraform-init
- |
terraform plan \
-var "project_id=${GOOGLE_CLOUD_PROJECT_ID}" \
-var "project_number=${GOOGLE_PROJECT_NUMBER}" \
-var "region=${GOOGLE_CLOUD_PROJECT_REGION}" \
terraform-apply:
desc: Apply the planned changes to the target infrastructure
deps: [terraform-plan]
cmds:
- task: switch-to-terraform-workspace
- |
terraform apply -auto-approve \
-var "project_id=${GOOGLE_CLOUD_PROJECT_ID}" \
-var "project_number=${GOOGLE_PROJECT_NUMBER}" \
-var "region=${GOOGLE_CLOUD_PROJECT_REGION}"
terraform-destroy:
desc: Destroy the target infrastructure
cmds:
- |
terraform destroy -auto-approve \
-var "project_id=${GOOGLE_CLOUD_PROJECT_ID}" \
-var "project_number=${GOOGLE_PROJECT_NUMBER}" \
-var "region=${GOOGLE_CLOUD_PROJECT_REGION}"
terraform-upgrade-providers:
desc: Upgrade terraform providers
cmds:
- |
terraform init -upgrade