Newer
Older
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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
.tofu-test-base:
image: "$GITLAB_OPENTOFU_IMAGE_NAME"
variables:
TF_STATE_NAME: ci-unit-$CI_JOB_ID
before_script:
- gitlab-tofu version
- jq --version
cache:
key: "$OPENTOFU_VERSION-$CI_COMMIT_REF_SLUG"
paths:
- tests/terraform/.terraform/
.tofu-test:
extends:
- .tofu-test-base
before_script:
- !reference [.tofu-test-base, before_script]
- cd tests/terraform
.test-tofu-root:
extends:
- .tofu-test-base
variables:
TF_ROOT: tests/terraform
tofu-test-init:
extends:
- .tofu-test
- .opentofu-versions
stage: test
script:
- export DEBUG_OUTPUT=true
- gitlab-tofu init
tofu-test-init-with-args:
extends:
- .tofu-test
- .opentofu-versions
stage: test
script:
- export DEBUG_OUTPUT=true
- gitlab-tofu init -get=true -no-color
tofu-test-init-with-flags:
extends:
- .tofu-test
- .opentofu-versions
stage: test
script:
- export DEBUG_OUTPUT=true
- export TF_INIT_FLAGS="-get=true -no-color"
- gitlab-tofu init
tofu-test-init-with-flags-and-args:
extends:
- .tofu-test
- .opentofu-versions
stage: test
script:
- export DEBUG_OUTPUT=true
- export TF_INIT_FLAGS="-get=true"
- gitlab-tofu init -no-color
tofu-test-init-tf-root:
extends:
- .test-tofu-root
- .opentofu-versions
stage: test
script:
- export DEBUG_OUTPUT=true
- gitlab-tofu init
tofu-test-init-tf-root-with-cd:
extends:
- .test-tofu-root
- .opentofu-versions
stage: test
script:
- cd tests/terraform
- export DEBUG_OUTPUT=true
- gitlab-tofu init
tofu-test-init-tf-root-with-args:
extends:
- .test-tofu-root
- .opentofu-versions
stage: test
script:
- export DEBUG_OUTPUT=true
- gitlab-tofu init -get=true -no-color
tofu-test-init-tf-root-with-flags:
extends:
- .test-tofu-root
- .opentofu-versions
stage: test
script:
- export DEBUG_OUTPUT=true
- export TF_INIT_FLAGS="-get=true -no-color"
- gitlab-tofu init
tofu-test-init-tf-root-with-flags-and-args:
extends:
- .test-tofu-root
- .opentofu-versions
stage: test
script:
- export DEBUG_OUTPUT=true
- export TF_INIT_FLAGS="-get=true"
- gitlab-tofu init -no-color
tofu-test-init-without-reconfigure:
extends:
- .test-tofu-root
- .opentofu-versions
stage: test
script:
- gitlab-tofu init
- |
cat <<EOF > $TF_ROOT/backend_override.tf
terraform {
backend "local" {}
}
EOF
- export TF_INIT_NO_RECONFIGURE=true
- FAILED=false
- gitlab-tofu init -no-color >/tmp/output.txt 2>&1 || FAILED=true
- cat /tmp/output.txt
- test $FAILED = true
- 'cat /tmp/output.txt | grep "Error: Backend configuration changed"'
tofu-test-init-with-reconfigure:
extends:
- .test-tofu-root
- .opentofu-versions
stage: test
script:
- gitlab-tofu init
- |
cat <<EOF > $TF_ROOT/backend_override.tf
terraform {
backend "local" {}
}
EOF
- gitlab-tofu init
tofu-test-init-with-prepared-registry-token:
extends:
- .tofu-test
stage: test
variables:
OPENTOFU_VERSION: $STABLE_OPENTOFU_VERSION
script:
- apk add --update $PKG
- |
cat <<'EOF' > test.sh
set -x
export TF_TOKEN_gitlab_com=mysecrettoken
. $(which gitlab-tofu)
terraform_authenticate_private_registry
test "$TF_TOKEN_gitlab_com" = "mysecrettoken"
EOF
- $SHELL test.sh
parallel:
matrix:
- SHELL: "bash"
PKG: "bash"
- SHELL: "zsh"
PKG: "zsh"
- SHELL: "ksh"
PKG: "loksh"
tofu-test-init-without-prepared-registry-token:
extends:
- .tofu-test
stage: test
variables:
OPENTOFU_VERSION: $STABLE_OPENTOFU_VERSION
script:
- apk add --update $PKG
- |
cat <<'EOF' > test.sh
set -x
. $(which gitlab-tofu)
terraform_authenticate_private_registry
test -n "$TF_TOKEN_gitlab_com"
EOF
- $SHELL test.sh
parallel:
matrix:
- SHELL: "bash"
PKG: "bash"
- SHELL: "zsh"
PKG: "zsh"
- SHELL: "ksh"
PKG: "loksh"
tofu-test-fmt:
extends:
- .tofu-test
- .opentofu-versions
stage: test
script:
- gitlab-tofu fmt
tofu-test-validate:
extends:
- .tofu-test
- .opentofu-versions
stage: test
script:
- gitlab-tofu validate
tofu-test-plan:
extends:
- .tofu-test
- .opentofu-versions
stage: test
variables:
TF_PLAN_CACHE: $OPENTOFU_VERSION-plan.cache
script:
- gitlab-tofu plan
- if [[ ! -f "$OPENTOFU_VERSION-plan.cache" ]]; then echo "expected to find a plan.cache file"; exit 1; fi
- gitlab-tofu plan-json
- if [[ ! -f "plan.json" ]]; then echo "expected to find a plan.json file"; exit 1; fi
artifacts:
paths:
- "tests/terraform/*-plan.cache"
tofu-test-apply:
extends:
- .tofu-test
- .opentofu-versions
stage: test
needs: [tofu-test-plan]
variables:
TF_PLAN_CACHE: $OPENTOFU_VERSION-plan.cache
script:
- gitlab-tofu apply
tofu-test-destroy:
extends:
- .tofu-test
- .opentofu-versions
stage: test
needs: [tofu-test-apply]
script:
- gitlab-tofu destroy
tofu-test-source-script:
extends:
- .tofu-test
stage: test
variables:
OPENTOFU_VERSION: $STABLE_OPENTOFU_VERSION
before_script:
- !reference [.tofu-test-base, before_script]
- apk add --update $PKG
script:
- |
cat <<'EOF' > test.sh
set -x
test -z "$TF_GITLAB_SOURCED"
. $(which gitlab-tofu)
test $TF_GITLAB_SOURCED
EOF
- |
mkdir /usr/local/sbin
cat <<'EOF' > /usr/local/sbin/terraform
#/!usr/bin/env sh -e
echo "Called Terraform, but shouldn't have!!"
false
EOF
chmod +x /usr/local/sbin/terraform
- $SHELL test.sh
parallel:
matrix:
- SHELL: "bash"
PKG: "bash"
- SHELL: "zsh"
PKG: "zsh"
- SHELL: "ksh"
PKG: "loksh"
tofu-test-without-implicit-init:
extends:
- .tofu-test
stage: test
cache:
variables:
OPENTOFU_VERSION: $STABLE_OPENTOFU_VERSION
STATE_NAME: $CI_JOB_NAME
script:
- export TF_IMPLICIT_INIT=false
- FAILED=false
- gitlab-tofu $CMD -no-color >/tmp/output.txt 2>&1 || FAILED=true
- cat /tmp/output.txt
- test $FAILED = true
- 'cat /tmp/output.txt | grep "$ERROR"'
parallel:
matrix:
- CMD: apply
ERROR: 'Error: Failed to load "plan.cache" as a plan'
- CMD: destroy
ERROR: 'Error: Backend initialization required, please run "tofu init"'
- CMD: plan
ERROR: 'Error: Backend initialization required, please run "tofu init"'
- CMD: validate
ERROR: 'Run "tofu init" to install all modules'
tofu-test-no-wrapper:
extends:
- .tofu-test
stage: test
cache:
variables:
OPENTOFU_VERSION: $STABLE_OPENTOFU_VERSION
STATE_NAME: $CI_JOB_NAME
script:
# NOTE: running `gitlab-tofu apply` wouldn't fail
# because of the implicit `terraform init`.
- FAILED=false
- gitlab-tofu -- apply -no-color >/tmp/output.txt 2>&1 || FAILED=true
- cat /tmp/output.txt
- test $FAILED = true
- 'cat /tmp/output.txt | grep "Error: Backend initialization required, please run \"tofu init\""'