-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTaskfile.defs.yaml
101 lines (87 loc) · 3.25 KB
/
Taskfile.defs.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
96
97
98
99
100
101
version: 3
silent: true
env:
AWS_REGION: "{{.AWS_REGION}}"
AWS_AZ: "{{.AWS_AZ}}"
WORK_ENV: "{{.WORK_ENV}}"
TF_VAR_workspace_aws_role_arn: '{{.AWS_ROLE_ARN}}'
TF_VAR_workspace_aws_config_file: '{{.AWS_CONFIG_FILE}}'
TF_CLI_ARGS_init: >-
-backend-config="region={{.AWS_REGION}}"
-backend-config="bucket=tf-state.{{.AWS_ACCOUNT_NAME}}"
-backend-config="key={{.PROJECT_NAME}}/{{.WORK_ENV}}/terraform.tfstate"
TF_CLI_ARGS_plan: '-var-file=./vars/common.tfvars -var-file=./vars/{{.WORK_ENV}}.tfvars'
TF_CLI_ARGS_apply: '-var-file=./vars/common.tfvars -var-file=./vars/{{.WORK_ENV}}.tfvars'
TF_CLI_ARGS_destroy: '-var-file=./vars/common.tfvars -var-file=./vars/{{.WORK_ENV}}.tfvars'
TF_CLI_ARGS_refresh: '-var-file=./vars/common.tfvars -var-file=./vars/{{.WORK_ENV}}.tfvars'
tasks:
init:
desc: Run Terraform init
cmds:
- '{{.TERRAFORM_BINARY}} init'
delete-state-files:
desc: Delete terraform state
cmds:
- aws s3 rm 's3://tf-state.{{.AWS_ACCOUNT_NAME}}/{{.PROJECT_NAME}}/{{.WORK_ENV}}/terraform.tfstate'
- rm '.terraform/terraform.tfstate'
apply:rancher-infra:
desc: Apply terrafrom infra module
cmds:
- '{{.TERRAFORM_BINARY}} apply -target module.rancher-infra'
apply:rancher-instance:
desc: Apply terrafrom instance module
cmds:
- '{{.TERRAFORM_BINARY}} apply -target module.rancher-instance'
apply:rancher-allowlist:
desc: Apply terrafrom allowlist module
cmds:
- '{{.TERRAFORM_BINARY}} apply -target module.rancher-allowlist'
apply:rancher-bootstrap:
desc: Apply terrafrom bootstrap module
cmds:
- '{{.TERRAFORM_BINARY}} apply -target module.rancher-bootstrap'
preconditions:
- sh: |
echo "Waiting for port ready..."
export FQDN=$(terraform output -raw fqdn)
while ! nc -z "$FQDN" 443 > /dev/null 2>&1; do
sleep 0.1;
done
msg: kubeernetes api not accessible
apply:rancher-config:
desc: Apply terrafrom config module
cmds:
- '{{.TERRAFORM_BINARY}} apply -target module.rancher-config'
preconditions:
- sh: |
echo "Waiting for cluster ready"
export FQDN=$(terraform output -raw fqdn)
export KUBECONFIG="${HOME}/.kube/$FQDN"
while ! kubectl cluster-info > /dev/null 2>&1; do
sleep 0.1 ;
done
msg: "Cluster Not Ready"
destroy:rancher-infra:
desc: Destroy Infrastructure
cmds:
- '{{.TERRAFORM_BINARY}} destroy -target module.rancher-infra'
destroy:rancher-instance:
desc: Destroy instance
cmds:
- '{{.TERRAFORM_BINARY}} destroy -target module.rancher-instance'
destroy:rancher-config:
desc: Destroy configuration
cmds:
- '{{.TERRAFORM_BINARY}} state rm $({{.TERRAFORM_BINARY}} state list module.rancher-bootstrap )'
- '{{.TERRAFORM_BINARY}} state rm $({{.TERRAFORM_BINARY}} state list module.rancher-config )'
preconditions:
- sh: '{{.TERRAFORM_BINARY}} state list module.rancher-config'
msg: "State not found"
apply:
desc: Run Terraform apply
cmds:
- task: apply:rancher-infra
- task: apply:rancher-instance
- task: apply:rancher-bootstrap
- task: apply:rancher-config
- '{{.TERRAFORM_BINARY}} apply'