Skip to content

style: Capitalise Terraform where product name is meant #256

style: Capitalise Terraform where product name is meant

style: Capitalise Terraform where product name is meant #256

Workflow file for this run

name: Test Terraform cloud
on:
- pull_request
jobs:
workspaces:
runs-on: ubuntu-latest
name: Terraform Cloud
strategy:
fail-fast: false
matrix:
tf_version: ['0.13', '1.0']
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Create a new workspace with no existing workspaces
uses: ./terraform-new-workspace
with:
path: tests/workflows/test-cloud/${{ matrix.tf_version }}
workspace: ${{ github.head_ref }}-1
backend_config: token=${{ secrets.TF_API_TOKEN }}
- name: Create a new workspace when it doesn't exist
uses: ./terraform-new-workspace
with:
path: tests/workflows/test-cloud/${{ matrix.tf_version }}
workspace: ${{ github.head_ref }}-2
backend_config: token=${{ secrets.TF_API_TOKEN }}
- name: Create a new workspace when it already exists
uses: ./terraform-new-workspace
with:
path: tests/workflows/test-cloud/${{ matrix.tf_version }}
workspace: ${{ github.head_ref }}-2
backend_config: token=${{ secrets.TF_API_TOKEN }}
- name: Auto apply workspace
uses: ./terraform-apply
id: auto_apply
with:
path: tests/workflows/test-cloud/${{ matrix.tf_version }}
workspace: ${{ github.head_ref }}-1
backend_config: token=${{ secrets.TF_API_TOKEN }}
auto_approve: true
var_file: |
tests/workflows/test-cloud/${{ matrix.tf_version }}/my_variable.tfvars
variables: |
from_variables="from_variables"
- name: Verify auto_apply terraform outputs
run: |
if [[ "${{ steps.auto_apply.outputs.default }}" != "default" ]]; then
echo "::error:: Variables not set correctly"
exit 1
fi
if [[ "${{ steps.auto_apply.outputs.from_tfvars }}" != "from_tfvars" ]]; then
echo "::error:: Variables not set correctly"
exit 1
fi
if [[ "${{ steps.auto_apply.outputs.from_variables }}" != "from_variables" ]]; then
echo "::error:: Variables not set correctly"
exit 1
fi
if [[ -n "${{ steps.auto_apply.outputs.text_plan_path }}" ]]; then
echo "::error:: text_plan_path should not be set"
exit 1
fi
if [[ -n "${{ steps.auto_apply.outputs.json_plan_path }}" ]]; then
echo "::error:: json_plan_path should not be set"
exit 1
fi
echo '${{ steps.auto_apply.outputs.run_id }}'
if [[ "${{ steps.auto_apply.outputs.run_id }}" != "run-"* ]]; then
echo "::error:: output run_id not set correctly"
exit 1
fi
- name: Get outputs
uses: ./terraform-output
id: output
with:
path: tests/workflows/test-cloud/${{ matrix.tf_version }}
workspace: ${{ github.head_ref }}-1
backend_config: token=${{ secrets.TF_API_TOKEN }}
- name: Verify auto_apply terraform outputs with workspace prefix
run: |
if [[ "${{ steps.output.outputs.default }}" != "default" ]]; then
echo "::error:: Variables not set correctly"
exit 1
fi
- name: Setup terraform with workspace name
run: |
mkdir fixed-workspace-name
if [[ "${{ matrix.tf_version }}" == "0.13" ]]; then
sed -e 's/prefix.*/name = "github-actions-0-13-${{ github.head_ref }}-1"/' tests/workflows/test-cloud/${{ matrix.tf_version }}/main.tf > fixed-workspace-name/main.tf
else
sed -e 's/prefix.*/name = "github-actions-1-1-${{ github.head_ref }}-1"/' tests/workflows/test-cloud/${{ matrix.tf_version }}/main.tf > fixed-workspace-name/main.tf
fi
- name: Get outputs
uses: ./terraform-output
id: name-output
with:
path: fixed-workspace-name
backend_config: token=${{ secrets.TF_API_TOKEN }}
- name: Verify auto_apply terraform outputs with workspace name
run: |
if [[ "${{ steps.name-output.outputs.default }}" != "default" ]]; then
echo "::error:: Variables not set correctly"
exit 1
fi
- name: Check no changes
uses: ./terraform-check
with:
path: tests/workflows/test-cloud/${{ matrix.tf_version }}
workspace: ${{ github.head_ref }}-1
backend_config: token=${{ secrets.TF_API_TOKEN }}
var_file: |
tests/workflows/test-cloud/${{ matrix.tf_version }}/my_variable.tfvars
variables: |
from_variables="from_variables"
- name: Check changes
uses: ./terraform-check
id: check
continue-on-error: true
with:
path: tests/workflows/test-cloud/${{ matrix.tf_version }}
workspace: ${{ github.head_ref }}-1
backend_config: token=${{ secrets.TF_API_TOKEN }}
var_file: |
tests/workflows/test-cloud/${{ matrix.tf_version }}/my_variable.tfvars
variables: |
from_variables="Changed!"
- name: Verify changes detected
run: |
if [[ "${{ steps.check.outcome }}" != "failure" ]]; then
echo "Check didn't fail correctly"
exit 1
fi
if [[ "${{ steps.check.outputs.failure-reason }}" != "changes-to-apply" ]]; then
echo "failure-reason not set correctly"
exit 1
fi
- name: Destroy workspace
uses: ./terraform-destroy-workspace
with:
path: tests/workflows/test-cloud/${{ matrix.tf_version }}
workspace: ${{ github.head_ref }}-1
backend_config: token=${{ secrets.TF_API_TOKEN }}
- name: Plan workspace
uses: ./terraform-plan
id: plan
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
path: tests/workflows/test-cloud/${{ matrix.tf_version }}
workspace: ${{ github.head_ref }}-2
backend_config: token=${{ secrets.TF_API_TOKEN }}
var_file: |
tests/workflows/test-cloud/${{ matrix.tf_version }}/my_variable.tfvars
variables: |
from_variables="from_variables"
- name: Verify plan outputs
run: |
if [[ "${{ steps.plan.outputs.changes }}" != "true" ]]; then
echo "::error:: output changes not set correctly"
exit 1
fi
if ! grep -q "Terraform will perform the following actions" '${{ steps.plan.outputs.text_plan_path }}'; then
echo "::error:: text_plan_path not set correctly"
exit 1
fi
echo '${{ steps.plan.outputs.run_id }}'
if [[ "${{ steps.plan.outputs.run_id }}" != "run-"* ]]; then
echo "::error:: output run_id not set correctly"
exit 1
fi
echo '${{ steps.plan.outputs.json_plan_path }}'
jq .output_changes.from_variables.actions[0] "${{ steps.plan.outputs.json_plan_path }}"
if [[ $(jq -r .output_changes.from_variables.actions[0] "${{ steps.plan.outputs.json_plan_path }}") != "create" ]]; then
echo "::error:: json_plan_path not set correctly"
exit 1
fi
- name: Apply workspace
uses: ./terraform-apply
id: apply
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
path: tests/workflows/test-cloud/${{ matrix.tf_version }}
workspace: ${{ github.head_ref }}-2
backend_config: token=${{ secrets.TF_API_TOKEN }}
var_file: |
tests/workflows/test-cloud/${{ matrix.tf_version }}/my_variable.tfvars
variables: |
from_variables="from_variables"
- name: Verify apply terraform outputs
run: |
if [[ "${{ steps.apply.outputs.default }}" != "default" ]]; then
echo "::error:: Variables not set correctly"
exit 1
fi
if [[ "${{ steps.apply.outputs.from_tfvars }}" != "from_tfvars" ]]; then
echo "::error:: Variables not set correctly"
exit 1
fi
if [[ "${{ steps.apply.outputs.from_variables }}" != "from_variables" ]]; then
echo "::error:: Variables not set correctly"
exit 1
fi
if ! grep -q "Terraform will perform the following actions" '${{ steps.apply.outputs.text_plan_path }}'; then
echo "::error:: text_plan_path not set correctly"
exit 1
fi
if [[ -n "${{ steps.apply.outputs.json_plan_path }}" ]]; then
echo "::error:: json_plan_path should not be set"
exit 1
fi
echo '${{ steps.apply.outputs.run_id }}'
if [[ "${{ steps.apply.outputs.run_id }}" != "run-"* ]]; then
echo "::error:: output run_id not set correctly"
exit 1
fi
- name: Destroy the last workspace
uses: ./terraform-destroy-workspace
with:
path: tests/workflows/test-cloud/${{ matrix.tf_version }}
workspace: ${{ github.head_ref }}-2
backend_config: token=${{ secrets.TF_API_TOKEN }}
- name: Destroy non-existent workspace
uses: ./terraform-destroy-workspace
continue-on-error: true
id: destroy-non-existant-workspace
with:
path: tests/workflows/test-cloud/${{ matrix.tf_version }}
workspace: ${{ github.head_ref }}-1
backend_config: token=${{ secrets.TF_API_TOKEN }}
- name: Check failed to destroy
run: |
if [[ "${{ steps.destroy-non-existant-workspace.outcome }}" != "failure" ]]; then
echo "Destroy non-existant workspace"
exit 1
fi
cloud:
runs-on: ubuntu-latest
name: Partial cloud config
env:
TF_CLOUD_ORGANIZATION: flooktech
TERRAFORM_CLOUD_TOKENS: app.terraform.io=${{ secrets.TF_API_TOKEN }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Create a new workspace with no existing workspaces
uses: ./terraform-new-workspace
with:
path: tests/workflows/test-cloud/partial
workspace: ${{ github.head_ref }}-cloud-1
- name: Create a new workspace when it doesn't exist
uses: ./terraform-new-workspace
with:
path: tests/workflows/test-cloud/partial
workspace: ${{ github.head_ref }}-cloud-2
- name: Create a new workspace when it already exists
uses: ./terraform-new-workspace
with:
path: tests/workflows/test-cloud/partial
workspace: ${{ github.head_ref }}-cloud-2
- name: Auto apply workspace
uses: ./terraform-apply
id: auto_apply
with:
path: tests/workflows/test-cloud/partial
workspace: ${{ github.head_ref }}-cloud-1
auto_approve: true
- name: Verify auto_apply terraform outputs
run: |
if [[ "${{ steps.auto_apply.outputs.len }}" != "5" ]]; then
echo "::error:: output not set correctly"
exit 1
fi
if ! grep -q "Terraform will perform the following actions" '${{ steps.auto_apply.outputs.text_plan_path }}'; then
echo "::error:: text_plan_path not set correctly"
exit 1
fi
if [[ ! -f "${{ steps.auto_apply.outputs.json_plan_path }}" ]]; then
echo "::error:: json_plan_path should be set"
exit 1
fi
echo '${{ steps.auto_apply.outputs.run_id }}'
if [[ "${{ steps.auto_apply.outputs.run_id }}" != "run-"* ]]; then
echo "::error:: output run_id not set correctly"
exit 1
fi
- name: Get outputs
uses: ./terraform-output
id: output
with:
path: tests/workflows/test-cloud/partial
workspace: ${{ github.head_ref }}-cloud-1
- name: Verify terraform-output outputs
run: |
if [[ "${{ steps.output.outputs.len }}" != "5" ]]; then
echo "::error:: output not set correctly"
exit 1
fi
- name: Check no changes
uses: ./terraform-check
with:
path: tests/workflows/test-cloud/partial
workspace: ${{ github.head_ref }}-cloud-1
- name: Check changes
uses: ./terraform-check
id: check
continue-on-error: true
with:
path: tests/workflows/test-cloud/partial
workspace: ${{ github.head_ref }}-cloud-1
variables: |
length=6
- name: Verify changes detected
run: |
if [[ "${{ steps.check.outcome }}" != "failure" ]]; then
echo "Check didn't fail correctly"
exit 1
fi
if [[ "${{ steps.check.outputs.failure-reason }}" != "changes-to-apply" ]]; then
echo "failure-reason not set correctly"
exit 1
fi
- name: Destroy workspace
uses: ./terraform-destroy-workspace
with:
path: tests/workflows/test-cloud/partial
workspace: ${{ github.head_ref }}-cloud-1
- name: Plan changes
uses: ./terraform-plan
id: plan
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
label: test-cloud cloud plan
path: tests/workflows/test-cloud/partial
workspace: ${{ github.head_ref }}-cloud-2
- name: Verify plan outputs
run: |
if [[ "${{ steps.plan.outputs.changes }}" != "true" ]]; then
echo "::error:: output changes not set correctly"
exit 1
fi
if ! grep -q "Terraform will perform the following actions" '${{ steps.plan.outputs.text_plan_path }}'; then
echo "::error:: text_plan_path not set correctly"
exit 1
fi
if [[ ! -f "${{ steps.auto_apply.outputs.json_plan_path }}" ]]; then
echo "::error:: json_plan_path should be set"
exit 1
fi
echo '${{ steps.plan.outputs.run_id }}'
if [[ "${{ steps.plan.outputs.run_id }}" != "run-"* ]]; then
echo "::error:: output run_id not set correctly"
exit 1
fi
- name: Apply changes
uses: ./terraform-apply
id: apply
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
label: test-cloud cloud plan
path: tests/workflows/test-cloud/partial
workspace: ${{ github.head_ref }}-cloud-2
- name: Verify apply terraform outputs
run: |
if [[ "${{ steps.apply.outputs.len }}" != "5" ]]; then
echo "::error:: Variables not set correctly"
exit 1
fi
if ! grep -q "Terraform will perform the following actions" '${{ steps.apply.outputs.text_plan_path }}'; then
echo "::error:: text_plan_path not set correctly"
exit 1
fi
if [[ ! -f "${{ steps.apply.outputs.json_plan_path }}" ]]; then
echo "::error:: json_plan_path should be set"
exit 1
fi
echo '${{ steps.apply.outputs.run_id }}'
if [[ "${{ steps.apply.outputs.run_id }}" != "run-"* ]]; then
echo "::error:: output run_id not set correctly"
exit 1
fi
- name: Plan no changes
uses: ./terraform-plan
id: plan-no-changes
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
label: test-cloud cloud plan-no-changes
path: tests/workflows/test-cloud/partial
workspace: ${{ github.head_ref }}-cloud-2
- name: Apply no changes
uses: ./terraform-apply
id: apply-no-changes
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
label: test-cloud cloud plan-no-changes
path: tests/workflows/test-cloud/partial
workspace: ${{ github.head_ref }}-cloud-2
- name: Verify apply with no changes
run: |
if [[ "${{ steps.plan-no-changes.outputs.changes }}" != "false" ]]; then
echo "::error:: changes output not set correctly"
exit 1
fi
if [[ "${{ steps.apply-no-changes.outputs.len }}" != "5" ]]; then
echo "::error:: Variables not set correctly"
exit 1
fi
if ! grep -q "No changes. Your infrastructure matches the configuration." '${{ steps.plan-no-changes.outputs.text_plan_path }}'; then
echo "::error:: text_plan_path not set correctly"
exit 1
fi
if ! grep -q "No changes. Your infrastructure matches the configuration." '${{ steps.apply-no-changes.outputs.text_plan_path }}'; then
echo "::error:: text_plan_path not set correctly"
exit 1
fi
if [[ ! -f "${{ steps.plan-no-changes.outputs.json_plan_path }}" ]]; then
echo "::error:: json_plan_path should be set"
exit 1
fi
if [[ ! -f "${{ steps.apply-no-changes.outputs.json_plan_path }}" ]]; then
echo "::error:: json_plan_path should be set"
exit 1
fi
echo '${{ steps.plan-no-changes.outputs.run_id }}'
if [[ "${{ steps.plan-no-changes.outputs.run_id }}" != "run-"* ]]; then
echo "::error:: output run_id not set correctly"
exit 1
fi
echo '${{ steps.apply-no-changes.outputs.run_id }}'
if [[ "${{ steps.apply-no-changes.outputs.run_id }}" != "run-"* ]]; then
echo "::error:: output run_id not set correctly"
exit 1
fi
- name: Saved plan with changes
uses: ./terraform-plan
id: saved-plan-changes
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
label: test-cloud cloud save-plan-changes
path: tests/workflows/test-cloud/partial
workspace: ${{ github.head_ref }}-cloud-2
variables: |
length=8
- name: Saved apply with changes
uses: ./terraform-apply
id: saved-apply-changes
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
label: test-cloud cloud save-plan-changes
path: tests/workflows/test-cloud/partial
plan_path: ${{ steps.saved-plan-changes.outputs.plan_path }}
workspace: ${{ github.head_ref }}-cloud-2
variables: |
length=8
- name: Verify saved apply with changes
run: |
if [[ "${{ steps.saved-plan-changes.outputs.changes }}" != "true" ]]; then
echo "::error:: changes output not set correctly"
exit 1
fi
if [[ "${{ steps.saved-apply-changes.outputs.len }}" != "8" ]]; then
echo "::error:: Variables not set correctly"
exit 1
fi
if ! grep -q "Terraform will perform the following actions" '${{ steps.saved-plan-changes.outputs.text_plan_path }}'; then
echo "::error:: text_plan_path not set correctly"
exit 1
fi
if [[ ! -f "${{ steps.saved-plan-changes.outputs.json_plan_path }}" ]]; then
echo "::error:: json_plan_path should be set"
exit 1
fi
echo '${{ steps.saved-plan-changes.outputs.run_id }}'
if [[ "${{ steps.saved-plan-changes.outputs.run_id }}" != "run-"* ]]; then
echo "::error:: output run_id not set correctly"
exit 1
fi
echo '${{ steps.saved-apply-changes.outputs.run_id }}'
if [[ "${{ steps.saved-apply-changes.outputs.run_id }}" != "run-"* ]]; then
echo "::error:: output run_id not set correctly"
exit 1
fi
- name: Saved plan with no changes
uses: ./terraform-plan
id: saved-plan-no-changes
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
label: test-cloud cloud save-plan-no-changes
path: tests/workflows/test-cloud/partial
workspace: ${{ github.head_ref }}-cloud-2
variables: |
length=8
- name: Saved apply with no changes
uses: ./terraform-apply
id: saved-apply-no-changes
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
label: test-cloud cloud save-plan-no-changes
path: tests/workflows/test-cloud/partial
plan_path: ${{ steps.saved-plan-no-changes.outputs.plan_path }}
workspace: ${{ github.head_ref }}-cloud-2
variables: |
length=8
- name: Verify saved apply with no changes
run: |
if [[ "${{ steps.saved-plan-no-changes.outputs.changes }}" != "false" ]]; then
echo "::error:: changes output not set correctly"
exit 1
fi
if [[ "${{ steps.saved-apply-no-changes.outputs.len }}" != "8" ]]; then
echo "::error:: Variables not set correctly"
exit 1
fi
if ! grep -q "No changes. Your infrastructure matches the configuration." '${{ steps.saved-plan-no-changes.outputs.text_plan_path }}'; then
echo "::error:: text_plan_path not set correctly"
exit 1
fi
if [[ ! -f "${{ steps.saved-plan-no-changes.outputs.json_plan_path }}" ]]; then
echo "::error:: json_plan_path should be set"
exit 1
fi
echo '${{ steps.saved-plan-no-changes.outputs.run_id }}'
if [[ "${{ steps.saved-plan-no-changes.outputs.run_id }}" != "run-"* ]]; then
echo "::error:: output run_id not set correctly"
exit 1
fi
echo '${{ steps.saved-apply-no-changes.outputs.run_id }}'
if [[ "${{ steps.saved-apply-no-changes.outputs.run_id }}" != "run-"* ]]; then
echo "::error:: output run_id not set correctly"
exit 1
fi
- name: Destroy the last workspace
uses: ./terraform-destroy-workspace
with:
path: tests/workflows/test-cloud/partial
workspace: ${{ github.head_ref }}-cloud-2
- name: Destroy non-existent workspace
uses: ./terraform-destroy-workspace
continue-on-error: true
id: destroy-non-existent-workspace
with:
path: tests/workflows/test-cloud/partial
workspace: ${{ github.head_ref }}-cloud-1
- name: Check failed to destroy
run: |
if [[ "${{ steps.destroy-non-existent-workspace.outcome }}" != "failure" ]]; then
echo "Destroy non-existant workspace"
exit 1
fi