Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 29 additions & 6 deletions .github/workflows/terraform-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,8 @@ name: Terraform Integration
# (required reviewers configured in repo Settings). See MSRC #127928.

on:
pull_request_target:
paths:
- '**.tf'
- '**.json'
- '**.tfvars'
- 'modules/terraform/**'
pull_request_review:
types: [submitted]
Comment on lines 6 to +8

permissions:
contents: read
Expand All @@ -19,7 +15,32 @@ env:
TERRAFORM_AWS_MODULES_DIR: modules/terraform/aws

jobs:
gate:
if: github.event.review.state == 'approved'

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@liyu-ma, here is the dilemma. Suppose I'm a reviewer, I can't approve before I feel confident the change is correct, then I need to check the tf change is working. If I already checked it, the test is not useful anymore.
Alternatively. If this remains a pr check, a reviewer can trigger it before he starts reviewing and check back the result later.

runs-on: ubuntu-latest
outputs:
run: ${{ steps.check.outputs.run }}
steps:
Comment on lines +18 to +23
- name: Check PR touches terraform files
id: check
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -eu
files=$(gh api \
"/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/files" \
--paginate --jq '.[].filename')
echo "Changed files:"
echo "$files"
if echo "$files" | grep -Eq '\.tf$|\.tfvars$|^modules/terraform/|^scenarios/.+/terraform-(inputs|test-inputs)/'; then
echo "run=true" >> "$GITHUB_OUTPUT"
else
echo "run=false" >> "$GITHUB_OUTPUT"
fi

terraform-test:
needs: gate
if: needs.gate.outputs.run == 'true'
environment: terraform-privileged
permissions:
contents: read
Expand Down Expand Up @@ -60,6 +81,8 @@ jobs:
ARM_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}

setup-matrix:
needs: gate
if: needs.gate.outputs.run == 'true'
runs-on: ubuntu-latest
name: Setup terraform plan matrix for test scenarios
steps:
Expand Down
Loading