Skip to content

aded workflow call to validate #9

aded workflow call to validate

aded workflow call to validate #9

name: Terraform Validate
on:
push:
branches:
- '**'
pull_request:
branches:
- '**'
workflow_call:
workflow_dispatch:
inputs:
terraform_version:
description: 'The version of Terraform to use'
required: true
default: '1.9.0'
type: string
jobs:
verify:
name: Validate Terraform Configuration
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_version: ${{ inputs.terraform_version || '1.9.0' }}
- name: Configure Git for private modules
env:
GH_TOKEN: ${{ secrets.ORG_GITHUB_PAT }}
run: |
git config --global url."https://${GH_TOKEN}@github.com/".insteadOf "https://github.com/"
- name: Initialise with no backend
run: terraform init -backend=false
- name: Validate Terraform
id: validate
run: |
set +e
OUTPUT=$(terraform validate)
CLEAN_OUTPUT=$(echo "$OUTPUT" | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g")
echo "$CLEAN_OUTPUT"
echo "result=$CLEAN_OUTPUT" >> $GITHUB_OUTPUT
set -e
continue-on-error: true
- name: Create comment
if: github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const issue_number = context.issue.number;
const result = `${{ steps.validate.outputs.result }}`;
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue_number,
body: `Terraform validation output:\n\`\`\`\n${result}\n\`\`\``
});