Skip to content

Commit 192d8da

Browse files
committed
Update test-unlock-state workflow
1 parent cec2b90 commit 192d8da

File tree

1 file changed

+55
-26
lines changed

1 file changed

+55
-26
lines changed

.github/workflows/test-unlock-state.yaml

Lines changed: 55 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,22 @@ name: Test terraform-unlock-state
33
on:
44
- pull_request
55

6+
permissions:
7+
contents: read
8+
69
env:
710
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
811
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
912

1013
jobs:
1114
default_workspace:
12-
runs-on: ubuntu-latest
15+
runs-on: ubuntu-24.04
1316
name: Default workspace
1417
steps:
1518
- name: Checkout
1619
uses: actions/checkout@v4
20+
with:
21+
persist-credentials: false
1722

1823
- name: Check state is not locked
1924
uses: ./terraform-apply
@@ -34,13 +39,16 @@ jobs:
3439
# State is now locked
3540

3641
- name: Check apply-failed
42+
env:
43+
OUTCOME: ${{ steps.failed-apply.outcome }}
44+
FAILURE_REASON: ${{ steps.failed-apply.outputs.failure-reason }}
3745
run: |
38-
if [[ "${{ steps.failed-apply.outcome }}" != "failure" ]]; then
46+
if [[ "$OUTCOME" != "failure" ]]; then
3947
echo "Apply did not fail correctly"
4048
exit 1
4149
fi
4250
43-
if [[ "${{ steps.failed-apply.outputs.failure-reason }}" != "apply-failed" ]]; then
51+
if [[ "$FAILURE_REASON" != "apply-failed" ]]; then
4452
echo "::error:: failure-reason not set correctly"
4553
exit 1
4654
fi
@@ -55,20 +63,24 @@ jobs:
5563
auto_approve: true
5664

5765
- name: Check terraform-apply state locked failure-reason
66+
env:
67+
OUTCOME: ${{ steps.locked-state-apply.outcome }}
68+
FAILURE_REASON: ${{ steps.locked-state-apply.outputs.failure-reason }}
69+
LOCK_INFO: ${{ steps.locked-state-apply.outputs.lock-info }}
70+
LOCK_ID: ${{ fromJson(steps.locked-state-apply.outputs.lock-info).ID }}
5871
run: |
59-
if [[ "${{ steps.locked-state-apply.outcome }}" != "failure" ]]; then
72+
if [[ "$OUTCOME" != "failure" ]]; then
6073
echo "Apply did not fail correctly"
6174
exit 1
6275
fi
6376
64-
if [[ "${{ steps.locked-state-apply.outputs.failure-reason }}" != "state-locked" ]]; then
77+
if [[ "$FAILURE_REASON" != "state-locked" ]]; then
6578
echo "::error:: failure-reason not set correctly"
6679
exit 1
6780
fi
6881
69-
echo '"${{ steps.locked-state-apply.outputs.lock-info }}"'
70-
71-
echo 'Lock id is ${{ fromJson(steps.locked-state-apply.outputs.lock-info).ID }}'
82+
echo "$LOCK_INFO"
83+
echo "Lock id is $LOCK_ID"
7284
7385
- name: Try using locked state using terraform-destroy
7486
uses: ./terraform-destroy
@@ -78,20 +90,24 @@ jobs:
7890
path: tests/workflows/test-unlock-state
7991

8092
- name: Check terraform-destroy state locked failure-reason
93+
env:
94+
OUTCOME: ${{ steps.locked-state-destroy.outcome }}
95+
FAILURE_REASON: ${{ steps.locked-state-destroy.outputs.failure-reason }}
96+
LOCK_INFO: ${{ steps.locked-state-destroy.outputs.lock-info }}
97+
LOCK_ID: ${{ fromJson(steps.locked-state-destroy.outputs.lock-info).ID }}
8198
run: |
82-
if [[ "${{ steps.locked-state-destroy.outcome }}" != "failure" ]]; then
99+
if [[ "$OUTCOME" != "failure" ]]; then
83100
echo "Apply did not fail correctly"
84101
exit 1
85102
fi
86103
87-
if [[ "${{ steps.locked-state-destroy.outputs.failure-reason }}" != "state-locked" ]]; then
104+
if [[ "$FAILURE_REASON}" != "state-locked" ]]; then
88105
echo "::error:: failure-reason not set correctly"
89106
exit 1
90107
fi
91108
92-
echo '"${{ steps.locked-state-destroy.outputs.lock-info }}"'
93-
94-
echo 'Lock id is ${{ fromJson(steps.locked-state-destroy.outputs.lock-info).ID }}'
109+
echo "$LOCK_INFO"
110+
echo "Lock id is $LOCK_ID"
95111
96112
- name: Unlock the state
97113
uses: ./terraform-unlock-state
@@ -107,11 +123,13 @@ jobs:
107123
auto_approve: true
108124

109125
nondefault_workspace:
110-
runs-on: ubuntu-latest
126+
runs-on: ubuntu-24.04
111127
name: Non Default workspace
112128
steps:
113129
- name: Checkout
114130
uses: actions/checkout@v4
131+
with:
132+
persist-credentials: false
115133

116134
- name: Create first workspace
117135
uses: ./terraform-new-workspace
@@ -140,13 +158,16 @@ jobs:
140158
# State is now locked
141159

142160
- name: Check apply-failed
161+
env:
162+
OUTCOME: ${{ steps.failed-apply-workspace.outcome }}
163+
FAILURE_REASON: ${{ steps.failed-apply-workspace.outputs.failure-reason }}
143164
run: |
144-
if [[ "${{ steps.failed-apply-workspace.outcome }}" != "failure" ]]; then
165+
if [[ "$OUTCOME" != "failure" ]]; then
145166
echo "Apply did not fail correctly"
146167
exit 1
147168
fi
148169
149-
if [[ "${{ steps.failed-apply-workspace.outputs.failure-reason }}" != "apply-failed" ]]; then
170+
if [[ "$FAILURE_REASON" != "apply-failed" ]]; then
150171
echo "::error:: failure-reason not set correctly"
151172
exit 1
152173
fi
@@ -162,20 +183,24 @@ jobs:
162183
auto_approve: true
163184

164185
- name: Check state locked failure-reason
186+
env:
187+
OUTCOME: ${{ steps.locked-state-workspace.outcome }}
188+
FAILURE_REASON: ${{ steps.locked-state-workspace.outputs.failure-reason }}
189+
LOCK_INFO: ${{ steps.locked-state-workspace.outputs.lock-info }}
190+
LOCK_ID: ${{ fromJson(steps.locked-state-workspace.outputs.lock-info).ID }}
165191
run: |
166-
if [[ "${{ steps.locked-state-workspace.outcome }}" != "failure" ]]; then
192+
if [[ "$OUTCOME" != "failure" ]]; then
167193
echo "Apply did not fail correctly"
168194
exit 1
169195
fi
170196
171-
if [[ "${{ steps.locked-state-workspace.outputs.failure-reason }}" != "state-locked" ]]; then
197+
if [[ "$FAILURE_REASON" != "state-locked" ]]; then
172198
echo "::error:: failure-reason not set correctly"
173199
exit 1
174200
fi
175201
176-
echo '"${{ steps.locked-state-workspace.outputs.lock-info }}"'
177-
178-
echo 'Lock id is ${{ fromJson(steps.locked-state-workspace.outputs.lock-info).ID }}'
202+
echo "$LOCK_INFO"
203+
echo "Lock id is $LOCK_ID"
179204
180205
- name: Try using locked state using terraform-destroy-workspace
181206
uses: ./terraform-destroy-workspace
@@ -186,20 +211,24 @@ jobs:
186211
workspace: hello
187212

188213
- name: Check terraform-destroy-workspace state locked failure-reason
214+
env:
215+
OUTCOME: ${{ steps.locked-state-destroy-workspace.outcome }}
216+
FAILURE_REASON: ${{ steps.locked-state-destroy-workspace.outputs.failure-reason }}
217+
LOCK_INFO: ${{ steps.locked-state-destroy-workspace.outputs.lock-info }}
218+
LOCK_ID: ${{ fromJson(steps.locked-state-destroy-workspace.outputs.lock-info).ID }}
189219
run: |
190-
if [[ "${{ steps.locked-state-destroy-workspace.outcome }}" != "failure" ]]; then
220+
if [[ "$OUTCOME" != "failure" ]]; then
191221
echo "Apply did not fail correctly"
192222
exit 1
193223
fi
194224
195-
if [[ "${{ steps.locked-state-destroy-workspace.outputs.failure-reason }}" != "state-locked" ]]; then
225+
if [[ "$FAILURE_REASON" != "state-locked" ]]; then
196226
echo "::error:: failure-reason not set correctly"
197227
exit 1
198228
fi
199229
200-
echo '"${{ steps.locked-state-destroy-workspace.outputs.lock-info }}"'
201-
202-
echo 'Lock id is ${{ fromJson(steps.locked-state-destroy-workspace.outputs.lock-info).ID }}'
230+
echo "$LOCK_INFO"
231+
echo "Lock id is $LOCK_ID"
203232
204233
- name: Unlock the state
205234
uses: ./terraform-unlock-state

0 commit comments

Comments
 (0)