Skip to content

Test PR for CI comment #11

Test PR for CI comment

Test PR for CI comment #11

Workflow file for this run

name: Terraform CI
on:
pull_request:
paths:
- "infra/**"
- ".github/workflows/terraform-ci.yml"
- ".tflint.hcl"
- ".checkov.yml"
- ".tfsec.yml"
permissions:
contents: read
pull-requests: write
security-events: write
jobs:
terraform-ci:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
terraform_version:
- "1.6.6"
- "1.8.5"
- "1.9.5"
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_version: ${{ matrix.terraform_version }}
- name: Terraform fmt
run: terraform fmt -check
working-directory: infra
- name: Terraform init (no backend)
run: terraform init -backend=false
working-directory: infra
- name: Terraform validate
run: terraform validate
working-directory: infra
- name: Setup TFLint
uses: terraform-linters/setup-tflint@v4
with:
tflint_version: latest
- name: Run TFLint (with annotations)
uses: terraform-linters/tflint-pr-commenter-action@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
tflint_command: "tflint --recursive"
directory: "infra"
- name: Run tfsec (SARIF)
uses: aquasecurity/tfsec-action@v1.0.3
with:
working_directory: infra
github_token: ${{ secrets.GITHUB_TOKEN }}
format: sarif
output_file: tfsec.sarif
- name: Upload tfsec SARIF
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: tfsec.sarif
- name: Run Checkov (SARIF)
uses: bridgecrewio/checkov-action@v12
with:
directory: infra
config_file: .checkov.yml
quiet: true
output_format: sarif
output_file_path: checkov.sarif
- name: Upload Checkov SARIF
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: checkov.sarif
- name: Publish Terraform CI summary
if: ${{ success() }}
run: |
cat << EOF >> "$GITHUB_STEP_SUMMARY"
# Terraform CI Summary
- Terraform version (matrix): \`${{ matrix.terraform_version }}\`
- Format check: passed
- Init (no backend): passed
- Validate: passed
- TFLint: passed
- Security: tfsec + Checkov passed
All Terraform checks finished successfully for this run.
EOF
- name: Comment on PR with Terraform CI result
if: always()
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const conclusion = '${{ job.status }}';
const symbols = { success: '✅', failure: '❌', cancelled: '⚪️' };
const symbol = symbols[conclusion] || 'ℹ️';
const body =
`${symbol} Terraform CI finished with status: **${conclusion}**\n\n` +
`Terraform versions tested: 1.6.6, 1.8.5, 1.9.5.\n` +
`See detailed results in the "Checks" tab.`;
const pr = context.payload.pull_request;
if (!pr) {
core.info('No pull_request context, skipping comment.');
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr.number,
body
});
}