Skip to content

Support OpenTofu

Support OpenTofu #55

name: Test terraform-unlock-state
on:
- pull_request
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
jobs:
default_workspace:
runs-on: ubuntu-latest
name: Default workspace
steps:
- name: Checkout
uses: actions/checkout@v3
#- name: Check state is not locked
# uses: ./terraform-apply
# with:
# path: tests/workflows/test-unlock-state
# auto_approve: true
#- name: Intentionally lock the state
# uses: ./terraform-apply
# id: failed-apply
# continue-on-error: true
# with:
# path: tests/workflows/test-unlock-state
# auto_approve: true
# variables:
# lock=true
# State is now locked
#- name: Check apply-failed
# run: |
# if [[ "${{ steps.failed-apply.outcome }}" != "failure" ]]; then
# echo "Apply did not fail correctly"
# exit 1
# fi
# if [[ "${{ steps.failed-apply.outputs.failure-reason }}" != "apply-failed" ]]; then
# echo "::error:: failure-reason not set correctly"
# exit 1
# fi
# Check state-locked
- name: Try using locked state using terraform-apply
uses: ./terraform-apply
id: locked-state-apply
continue-on-error: true
with:
path: tests/workflows/test-unlock-state
auto_approve: true
- name: Check terraform-apply state locked failure-reason
run: |
if [[ "${{ steps.locked-state-apply.outcome }}" != "failure" ]]; then
echo "Apply did not fail correctly"
exit 1
fi
if [[ "${{ steps.locked-state-apply.outputs.failure-reason }}" != "state-locked" ]]; then
echo "::error:: failure-reason not set correctly"
exit 1
fi
echo '"${{ steps.locked-state-apply.outputs.lock-info }}"'
echo 'Lock id is ${{ fromJson(steps.locked-state-apply.outputs.lock-info).ID }}'
- name: Try using locked state using terraform-destroy
uses: ./terraform-destroy
id: locked-state-destroy
continue-on-error: true
with:
path: tests/workflows/test-unlock-state
- name: Check terraform-destroy state locked failure-reason
run: |
if [[ "${{ steps.locked-state-destroy.outcome }}" != "failure" ]]; then
echo "Apply did not fail correctly"
exit 1
fi
if [[ "${{ steps.locked-state-destroy.outputs.failure-reason }}" != "state-locked" ]]; then
echo "::error:: failure-reason not set correctly"
exit 1
fi
echo '"${{ steps.locked-state-destroy.outputs.lock-info }}"'
echo 'Lock id is ${{ fromJson(steps.locked-state-destroy.outputs.lock-info).ID }}'
- name: Unlock the state
uses: ./terraform-unlock-state
continue-on-error: true
with:
path: tests/workflows/test-unlock-state
lock_id: ${{ fromJson(steps.locked-state-apply.outputs.lock-info).ID }}
- name: Check state is not locked
uses: ./terraform-apply
with:
path: tests/workflows/test-unlock-state
auto_approve: true
nondefault_workspace:
runs-on: ubuntu-latest
name: Non Default workspace
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Create first workspace
uses: ./terraform-new-workspace
with:
path: tests/workflows/test-unlock-state
workspace: hello
#- name: Check state is not locked
# uses: ./terraform-apply
# with:
# path: tests/workflows/test-unlock-state
# workspace: hello
# auto_approve: true
#- name: Intentionally lock the state
# uses: ./terraform-apply
# id: failed-apply-workspace
# continue-on-error: true
# with:
# path: tests/workflows/test-unlock-state
# workspace: hello
# auto_approve: true
# variables:
# lock=true
# State is now locked
#- name: Check apply-failed
# run: |
# if [[ "${{ steps.failed-apply-workspace.outcome }}" != "failure" ]]; then
# echo "Apply did not fail correctly"
# exit 1
# fi
# if [[ "${{ steps.failed-apply-workspace.outputs.failure-reason }}" != "apply-failed" ]]; then
# echo "::error:: failure-reason not set correctly"
# exit 1
# fi
# Check state-locked
- name: Try using locked state
uses: ./terraform-apply
id: locked-state-workspace
continue-on-error: true
with:
path: tests/workflows/test-unlock-state
workspace: hello
auto_approve: true
- name: Check state locked failure-reason
run: |
if [[ "${{ steps.locked-state-workspace.outcome }}" != "failure" ]]; then
echo "Apply did not fail correctly"
exit 1
fi
if [[ "${{ steps.locked-state-workspace.outputs.failure-reason }}" != "state-locked" ]]; then
echo "::error:: failure-reason not set correctly"
exit 1
fi
echo '"${{ steps.locked-state-workspace.outputs.lock-info }}"'
echo 'Lock id is ${{ fromJson(steps.locked-state-workspace.outputs.lock-info).ID }}'
- name: Try using locked state using terraform-destroy-workspace
uses: ./terraform-destroy-workspace
id: locked-state-destroy-workspace
continue-on-error: true
with:
path: tests/workflows/test-unlock-state
workspace: hello
- name: Check terraform-destroy-workspace state locked failure-reason
run: |
if [[ "${{ steps.locked-state-destroy-workspace.outcome }}" != "failure" ]]; then
echo "Apply did not fail correctly"
exit 1
fi
if [[ "${{ steps.locked-state-destroy-workspace.outputs.failure-reason }}" != "state-locked" ]]; then
echo "::error:: failure-reason not set correctly"
exit 1
fi
echo '"${{ steps.locked-state-destroy-workspace.outputs.lock-info }}"'
echo 'Lock id is ${{ fromJson(steps.locked-state-destroy-workspace.outputs.lock-info).ID }}'
- name: Unlock the state
uses: ./terraform-unlock-state
continue-on-error: true
with:
path: tests/workflows/test-unlock-state
workspace: hello
lock_id: ${{ fromJson(steps.locked-state-workspace.outputs.lock-info).ID }}
- name: Check state is not locked
uses: ./terraform-apply
with:
path: tests/workflows/test-unlock-state
workspace: hello
auto_approve: true
- name: Destroy workspace
uses: ./terraform-destroy-workspace
with:
path: tests/workflows/test-unlock-state
workspace: hello