Enhance PR comments #191
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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@v3 | |
- 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@v3 | |
- 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 [[ -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/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 workspace | |
uses: ./terraform-plan | |
id: plan | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
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 | |
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 workspace | |
uses: ./terraform-apply | |
id: apply | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
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 [[ -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/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 |