-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTerraform.yaml
138 lines (126 loc) · 4.32 KB
/
Terraform.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# yaml-language-server: $schema=https://taskfile.dev/schema.json
version: "3"
run: once
tasks:
tfready:
desc: Runs Terraform validations to ensure configuration is sound.
cmds:
- task: tfchecks
- task: tflint
- task: tflock
tfplan:
desc: Run Terraform plan
deps: [tf-requirements, tf-select-workspace]
requires:
vars: [TF_CONFIGURATION_DIRECTORY, TF_INPUTS_FILE]
dir: "/{{.TF_CONFIGURATION_DIRECTORY}}"
cmds:
- terraform plan -lock=false -var-file={{.TF_INPUTS_FILE}}
tfapply:
desc: Run Terraform apply
deps: [tf-requirements, tf-select-workspace]
requires:
vars: [TF_CONFIGURATION_DIRECTORY, TF_INPUTS_FILE]
dir: "/{{.TF_CONFIGURATION_DIRECTORY}}"
cmds:
- terraform apply -var-file={{.TF_INPUTS_FILE}} -auto-approve
tfclean:
desc: Cleans the Terraform local environment
deps: [tf-requirements]
requires:
vars: [TF_CONFIGURATION_DIRECTORY]
dir: "/{{.TF_CONFIGURATION_DIRECTORY}}"
cmds:
- rm -rf .terraform
- rm -rf terraform.tfstate.d
####################
## utility tasks ###
####################
tfchecks:
desc: Runs Terraform fmt and validate
deps: [tf-requirements, tfinit-offline]
requires:
vars: [TF_CONFIGURATION_DIRECTORY]
dir: "/{{.TF_CONFIGURATION_DIRECTORY}}"
cmds:
- terraform fmt -recursive
- terraform validate
internal: true
tflint:
desc: Run TFLint
deps: [tf-requirements, tfinit-offline]
requires:
vars: [TF_CONFIGURATION_DIRECTORY, TFLINT_CONFIG_FILE]
dir: "/{{.TF_CONFIGURATION_DIRECTORY}}"
cmds:
- tflint --recursive --init --config={{.TFLINT_CONFIG_FILE}}
- tflint --recursive --config={{.TFLINT_CONFIG_FILE}}
status: ["[ '{{.SKIP_TFLINT}}' == 'true' ]"]
internal: true
tf-requirements:
desc: Validates requirements for local development
requires:
vars: [TF_CONFIGURATION_DIRECTORY]
preconditions:
- sh: tflint --version
msg: ✗ tflint not installed. Run 'brew install tflint' to install tflint.
- sh: "[ -d {{.TF_CONFIGURATION_DIRECTORY}} ]"
msg: ✗ directory '{{.TF_CONFIGURATION_DIRECTORY}}' does not exist."
- sh: "[ -f {{.TFLINT_CONFIG_FILE}} ]"
msg: ✗ file '{{.TFLINT_CONFIG_FILE}}' does not exist."
- sh: "[ -f {{.TF_INPUTS_FILE}} ]"
msg: ✗ file '{{.TF_INPUTS_FILE}}' does not exist."
- sh: "[[ '{{.TF_CONFIGURATION_DIRECTORY}}' = /* ]]"
msg: ✗ directory '{{.TF_CONFIGURATION_DIRECTORY}}' must be an absolute path."
- sh: "[[ '{{.TFLINT_CONFIG_FILE}}' = /* ]]"
msg: ✗ file '{{.TFLINT_CONFIG_FILE}}' must be an absolute path."
- sh: "[[ '{{.TF_INPUTS_FILE}}' = /* ]]"
msg: ✗ file '{{.TF_INPUTS_FILE}}' must be an absolute path."
internal: true
tfinit-offline:
desc: Initializes (offline) the Terraform environment
deps: [tf-requirements]
requires:
vars: [TF_CONFIGURATION_DIRECTORY]
dir: "/{{.TF_CONFIGURATION_DIRECTORY}}"
cmds:
- "terraform init -input=false -backend=false"
internal: true
tfinit:
desc: Initializes the Terraform environment
deps: [tf-requirements]
requires:
vars: [TF_CONFIGURATION_DIRECTORY]
dir: "/{{.TF_CONFIGURATION_DIRECTORY}}"
cmds:
- "terraform init -input=false"
internal: true
tf-select-workspace:
desc: Selects the Terraform workspace
deps: [tf-requirements, tf-create-workspace]
requires:
vars: [TF_WORKSPACE, TF_CONFIGURATION_DIRECTORY]
dir: "/{{.TF_CONFIGURATION_DIRECTORY}}"
cmds:
- "terraform workspace select {{.TF_WORKSPACE}}"
internal: true
tf-create-workspace:
desc: Creates the given Terraform workspace
deps: [tf-requirements, tfinit]
requires:
vars: [TF_WORKSPACE, TF_CONFIGURATION_DIRECTORY]
dir: "/{{.TF_CONFIGURATION_DIRECTORY}}"
cmds:
- "terraform workspace new {{.TF_WORKSPACE}}"
status:
- "terraform workspace select {{.TF_WORKSPACE}}"
internal: true
tflock:
desc: (re)generates the .terraform.lock.hcl file
deps: [tf-requirements, tfinit-offline]
requires:
vars: [TF_CONFIGURATION_DIRECTORY]
dir: "/{{.TF_CONFIGURATION_DIRECTORY}}"
cmds:
- terraform providers lock -platform=windows_amd64 -platform=darwin_amd64 -platform=linux_amd64 -platform=linux_arm64
internal: true