-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTerraform.yaml
More file actions
106 lines (94 loc) · 4 KB
/
Terraform.yaml
File metadata and controls
106 lines (94 loc) · 4 KB
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
102
103
104
105
106
# yaml-language-server: $schema=https://taskfile.dev/schema.json
version: "3"
run: once
vars:
SKIP_TFLINT: '{{.SKIP_TFLINT | default "false" }}'
TF_CONFIG_DIR_ABSPATH: { sh: "realpath {{.TF_CONFIG_DIR}}" }
tasks:
ready:
deps: [requirements]
desc: run Terraform validations to ensure configuration is healthy.
cmds:
- task: checks
- task: lint
lock-providers:
desc: update .terraform.lock.hcl with the latest providers versions
deps: [init]
requires: { vars: [TF_CONFIG_DIR] }
cmd: terraform -chdir="{{.TF_CONFIG_DIR_ABSPATH}}" providers lock -platform=windows_amd64 -platform=darwin_amd64 -platform=linux_amd64 -platform=linux_arm64
plan:
desc: run Terraform plan
deps: [requirements, init, select-workspace]
requires: { vars: [TF_CONFIG_DIR, TF_INPUTS_FILE] }
vars:
TF_VARS_FILE_ABSPATH: { sh: "realpath {{.TF_INPUTS_FILE}}" }
TF_VARS_FILE_GENERATED: "{{.TF_CONFIG_DIR_ABSPATH}}/taskfile_generated.auto.tfvars"
cmds:
- '[ -f "{{.TF_VARS_FILE_ABSPATH}}" ] && cp "{{.TF_VARS_FILE_ABSPATH}}" "{{.TF_VARS_FILE_GENERATED}}" || true'
- defer: "rm -f {{.TF_VARS_FILE_GENERATED}}"
- terraform -chdir="{{.TF_CONFIG_DIR_ABSPATH}}" plan -lock=false
apply:
desc: run Terraform apply
deps: [requirements, init, select-workspace]
requires: { vars: [TF_CONFIG_DIR, TF_INPUTS_FILE] }
vars:
TF_VARS_FILE_ABSPATH: { sh: "realpath {{.TF_INPUTS_FILE}}" }
TF_VARS_FILE_GENERATED: "{{.TF_CONFIG_DIR_ABSPATH}}/taskfile_generated.auto.tfvars"
cmds:
- '[ -f "{{.TF_VARS_FILE_ABSPATH}}" ] && cp "{{.TF_VARS_FILE_ABSPATH}}" "{{.TF_VARS_FILE_GENERATED}}" || true'
- defer: "rm -f {{.TF_VARS_FILE_GENERATED}}"
- terraform -chdir="{{.TF_CONFIG_DIR_ABSPATH}}" apply -auto-approve
##################################################
############# internal tasks #####################
##################################################
checks:
internal: true
deps: [init-offline]
requires: { vars: [TF_CONFIG_DIR] }
cmds:
- terraform -chdir="{{.TF_CONFIG_DIR_ABSPATH}}" fmt -recursive
- terraform -chdir="{{.TF_CONFIG_DIR_ABSPATH}}" validate
lint:
internal: true
deps: [init-offline]
requires: { vars: [TF_CONFIG_DIR] }
vars:
TFLINT_CONFIG_ABSPATH: { sh: "realpath {{.TFLINT_CONFIG_FILE}}" }
cmds:
- tflint --recursive --init --config={{.TFLINT_CONFIG_ABSPATH}}
- tflint --recursive --config={{.TFLINT_CONFIG_ABSPATH}}
status: ["[ '{{.SKIP_TFLINT}}' == 'true' ]"]
requirements:
internal: true
requires: { vars: [TF_CONFIG_DIR] }
preconditions:
- sh: tflint --version
msg: ✗ tflint not installed. Run 'brew install tflint' to install tflint.
- sh: "which realpath"
msg: ✗ realpath binary not found"
- sh: "[ -d {{.TF_CONFIG_DIR}} ]"
msg: ✗ directory '{{.TF_CONFIG_DIR}}' does not exist."
init-offline:
internal: true
requires: { vars: [TF_CONFIG_DIR] }
vars: { TF_CONFIG_DIR_ABSPATH: { sh: "realpath {{.TF_CONFIG_DIR}}" } }
cmd: terraform -chdir="{{.TF_CONFIG_DIR_ABSPATH}}" init -input=false -backend=false -upgrade
init:
internal: true
requires: { vars: [TF_CONFIG_DIR] }
vars: { TF_CONFIG_DIR_ABSPATH: { sh: "realpath {{.TF_CONFIG_DIR}}" } }
cmd: terraform -chdir="{{.TF_CONFIG_DIR_ABSPATH}}" init -input=false -upgrade
select-workspace:
internal: true
deps: [create-workspace]
requires: { vars: [TF_WORKSPACE, TF_CONFIG_DIR] }
vars: { TF_CONFIG_DIR_ABSPATH: { sh: "realpath {{.TF_CONFIG_DIR}}" } }
cmd: terraform -chdir="{{.TF_CONFIG_DIR_ABSPATH}}" workspace select {{.TF_WORKSPACE}}
create-workspace:
internal: true
deps: [init]
requires: { vars: [TF_WORKSPACE, TF_CONFIG_DIR] }
vars: { TF_CONFIG_DIR_ABSPATH: { sh: "realpath {{.TF_CONFIG_DIR}}" } }
cmd: terraform -chdir="{{.TF_CONFIG_DIR_ABSPATH}}" workspace new {{.TF_WORKSPACE}}
status:
- terraform -chdir="{{.TF_CONFIG_DIR_ABSPATH}}" workspace select {{.TF_WORKSPACE}}