-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathTaskfile.yml
219 lines (195 loc) · 7.11 KB
/
Taskfile.yml
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# https://taskfile.dev/
version: '3'
env:
TF_CLI_ARGS_test: -compact-warnings
vars:
TEST_DIR: "tests"
WORKSPACE_DIR: "workspace"
includes:
debug:
taskfile: ./taskfiles/Debug.yml
internal: true
go:
taskfile: ./taskfiles/Golang.yml
install:
taskfile: ./taskfiles/Install.yml
internal: true
terraform:
taskfile: ./taskfiles/Terraform.yml
internal: true
tasks:
ci:
desc: Workflow to run in CI
deps:
- install:brew-install-jq
- install:go-install-gofumpt
- install:go-install-golangci-lint
cmds:
- task: go:workspace
- task: lint
- task: test
docs:
desc: Generate docs
aliases: ["doc"]
cmds:
- go get github.com/hashicorp/[email protected]
- go get github.com/hashicorp/terraform-plugin-docs/internal/[email protected]
- go generate
- go mod tidy
fix:
desc: Fix formatting, linting, go.mod, and update submodule
deps:
- install:brew-install-terraform
- install:go-install-golangci-lint
cmds:
- task: go:update-opslevel-go
- gofumpt -w .
- go get -u
- go mod tidy
- golangci-lint run --fix
- task: terraform:terraform-format-fix
lint:
desc: Formatting and linting
deps:
- install:brew-install-terraform
- install:go-install-golangci-lint
cmds:
- test -z "$(gofumpt -d -e . | tee /dev/stderr)"
- golangci-lint run
- task: terraform:terraform-command
vars: { TF_COMMAND: "validate -no-tests", TF_CMD_DIR: "{{.ROOT_DIR}}" }
- task: terraform:terraform-format-check
setup:
desc: Setup linter, formatter, Terraform, and Terraform workspace
deps:
- install:brew-install-terraform
- install:go-install-changie
- install:go-install-gofumpt
- install:go-install-golangci-lint
cmds:
- task: go:workspace
- task: terraform:setup-terraform-from
vars: { SETUP_DIR: "{{.WORKSPACE_DIR}}" }
terraform-apply:
desc: Rebuild and run "terraform apply -auto-approve" in "{{.WORKSPACE_DIR}}"
aliases: ["apply"]
requires:
vars: [OPSLEVEL_API_TOKEN]
cmds:
- task: terraform:setup-terraform-from
vars: { SETUP_DIR: "{{.WORKSPACE_DIR}}" }
- task: terraform:terraform-command
vars: { TF_COMMAND: 'apply -auto-approve', TF_CMD_DIR: "{{.WORKSPACE_DIR}}" }
debug-start:
desc: First, start headless debug
aliases: ["dbg-start", "dbg1", "debug1"]
cmds:
- task: debug:do-debug-start
debug-attach:
desc: Second, attach to headless debug sessions
aliases: ["dbg-attach", "dbg2", "debug2"]
cmds:
- task: debug:do-debug-attach
debug-apply:
desc: After debug-start and debug-attach, run "terraform apply" with 'TF_REATTACH_PROVIDERS'
aliases: ["dbg-apply"]
cmds:
- task: debug:do-debug-apply
debug-plan:
desc: After debug-start and debug-attach, run "terraform plan" with 'TF_REATTACH_PROVIDERS'
aliases: ["dbg-plan"]
cmds:
- task: debug:do-debug-plan
debug-validate:
desc: After debug-start and debug-attach, run "terraform validate" with 'TF_REATTACH_PROVIDERS'
aliases: ["dbg-validate"]
cmds:
- task: debug:do-debug-validate
debug-test:
desc: After debug-start and debug-attach, run "terraform test" with 'TF_REATTACH_PROVIDERS'
aliases: ["dbg-test"]
cmds:
- task: debug:do-debug-test
terraform-clean:
desc: Completely wipe terraform state, terraform generated files, and local OpsLevel provider binaries
aliases: ["clean"]
prompt: Remove all '*.tfstate .terraform.lock.hcl ./terraform.* .terraform/**' and OpsLevel binaries from plugins directory?
cmds:
- task: terraform:clean-terraform-plugin-directory
- cmd: rm -rf {{.WORKSPACE_DIR}}/.terraform.lock.hcl {{.WORKSPACE_DIR}}/.terraform/ {{.WORKSPACE_DIR}}/*.tfstate*
ignore_error: true
- cmd: rm -rf {{.TEST_DIR}}/.terraform.lock.hcl {{.TEST_DIR}}/.terraform/ {{.TEST_DIR}}/*.tfstate*
ignore_error: true
- cmd: rm -rf {{.TEST_DIR}}/local/.terraform.lock.hcl {{.TEST_DIR}}/local/.terraform/ {{.TEST_DIR}}/local/*.tfstate*
ignore_error: true
- cmd: rm -rf {{.TEST_DIR}}/remote/.terraform.lock.hcl {{.TEST_DIR}}/remote/.terraform/ {{.TEST_DIR}}/remote/*.tfstate*
ignore_error: true
terraform-destroy:
desc: Rebuild and run "terraform destroy -auto-approve" in "{{.WORKSPACE_DIR}}"
aliases: ["destroy"]
cmds:
- task: terraform:setup-terraform-from
vars: { SETUP_DIR: "{{.WORKSPACE_DIR}}" }
- task: terraform:terraform-command
vars: { TF_COMMAND: 'destroy -auto-approve', TF_CMD_DIR: "{{.WORKSPACE_DIR}}" }
terraform-build:
desc: Rebuild provider
aliases: ["build"]
cmds:
- task: terraform:setup-terraform-from
vars: { SETUP_DIR: "{{.WORKSPACE_DIR}}" }
terraform-plan:
desc: Rebuild and run "terraform plan" in "{{.WORKSPACE_DIR}}"
aliases: ["plan"]
requires:
vars: [OPSLEVEL_API_TOKEN]
cmds:
- task: terraform:setup-terraform-from
vars: { SETUP_DIR: "{{.WORKSPACE_DIR}}" }
- task: terraform:terraform-command
vars: { TF_COMMAND: 'plan', TF_CMD_DIR: "{{.WORKSPACE_DIR}}" }
terraform-validate:
desc: Rebuild and run "terraform validate" in "{{.WORKSPACE_DIR}}"
aliases: ["validate"]
cmds:
- task: terraform:setup-terraform-from
vars: { SETUP_DIR: "{{.WORKSPACE_DIR}}" }
- task: terraform:terraform-command
vars: { TF_COMMAND: 'validate', TF_CMD_DIR: "{{.WORKSPACE_DIR}}" }
test:
desc: Run tests
cmds:
- task: terraform:setup-terraform-from
vars: { SETUP_DIR: "{{.TEST_DIR}}/local" }
- task: terraform:terraform-command
vars: { TF_COMMAND: "test", TF_CMD_DIR: "{{.TEST_DIR}}/local" }
- task: go:run-unit-tests
test-release:
desc: Run integration tests using latest release of OpsLevel Terraform provider
requires:
vars: [OPSLEVEL_API_TOKEN]
cmds:
- task: terraform:clean-terraform-plugin-directory
- cmd: rm -rf {{.TEST_DIR}}/.terraform.lock.hcl {{.TEST_DIR}}/.terraform/ {{.TEST_DIR}}/*.tfstate*
ignore_error: true
- echo "Testing with latest OpsLevel Terraform provider release..."
- task: terraform:run-tests-against-submodule
test-unreleased:
desc: Run integration tests with local changes to OpsLevel Terraform provider
requires:
vars: [OPSLEVEL_API_TOKEN]
cmds:
- echo "Testing with local changes to OpsLevel Terraform provider..."
- cmd: rm -rf {{.TEST_DIR}}/.terraform.lock.hcl {{.TEST_DIR}}/.terraform/ {{.TEST_DIR}}/*.tfstate*
ignore_error: true
- task: terraform:terraform-build
- task: terraform:run-tests-against-submodule
test-integration:
desc: Run integration tests - placeholder until submodule complete
requires:
vars: [OPSLEVEL_API_TOKEN]
cmds:
- task: terraform:setup-terraform-from
vars: { SETUP_DIR: "{{.TEST_DIR}}/remote" }
- task: terraform:terraform-command
vars: { TF_COMMAND: 'test -var-file=test.tfvars -var="api_token=$OPSLEVEL_API_TOKEN" {{.CLI_ARGS}}', TF_CMD_DIR: "{{.TEST_DIR}}/remote" }