Skip to content

Add terraform-test and tofu-test actions #660

Add terraform-test and tofu-test actions

Add terraform-test and tofu-test actions #660

name: Test terraform-new/destroy-workspace
on:
- pull_request
jobs:
workspace_management:
runs-on: ubuntu-latest
name: Workspace management
strategy:
fail-fast: false
matrix:
tf_version: ['~> 0.12.0', '~> 0.13.0', '~> 0.14.0', '~> 1.0.0', '~> 1.1.0']
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup remote backend
run: |
cat >tests/workflows/test-new-workspace/backend.tf <<EOF
terraform {
backend "s3" {
bucket = "terraform-github-actions"
key = "terraform-new-workspace-${{ matrix.tf_version }}"
region = "eu-west-2"
}
required_version = "${{ matrix.tf_version }}"
}
EOF
- name: Create first workspace
uses: ./terraform-new-workspace
with:
path: tests/workflows/test-new-workspace
workspace: test-workspace
- name: Create first workspace again
uses: ./terraform-new-workspace
with:
path: tests/workflows/test-new-workspace
workspace: test-workspace
- name: Apply in first workspace
uses: ./terraform-apply
with:
path: tests/workflows/test-new-workspace
workspace: test-workspace
variables: my_string="hello"
auto_approve: true
- name: Create a second workspace
uses: ./terraform-new-workspace
with:
path: tests/workflows/test-new-workspace
workspace: ${{ github.head_ref }}
- name: Apply in second workspace
uses: ./terraform-apply
with:
path: tests/workflows/test-new-workspace
workspace: ${{ github.head_ref }}
variables: my_string="world"
auto_approve: true
- name: Get first workspace outputs
uses: ./terraform-output
id: first
with:
path: tests/workflows/test-new-workspace
workspace: test-workspace
- name: Get second workspace outputs
uses: ./terraform-output
id: second
with:
path: tests/workflows/test-new-workspace
workspace: ${{ github.head_ref }}
- name: Verify outputs
run: |
if [[ "${{ steps.first.outputs.my_string }}" != "hello" ]]; then
echo "::error:: output my_string not set correctly for first workspace"
exit 1
fi
if [[ "${{ steps.second.outputs.my_string }}" != "world" ]]; then
echo "::error:: output my_string not set correctly for second workspace"
exit 1
fi
- name: Destroy first workspace
uses: ./terraform-destroy-workspace
with:
path: tests/workflows/test-new-workspace
workspace: test-workspace
variables: my_string="hello"
- name: Destroy second workspace
uses: ./terraform-destroy-workspace
with:
path: tests/workflows/test-new-workspace
workspace: ${{ github.head_ref }}
variables: my_string="world"