Update variables.tf #16
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: "Preflight" | |
on: | |
pull_request: | |
jobs: | |
extract-changed-directories: | |
name: "extract-changed-directories" | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Install GitHub CLI | |
run: sudo apt-get install gh | |
- name: Get unique changed files in PR | |
id: changed-dirs | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
PR_NUMBER=${{ github.event.pull_request.number }} | |
echo $PR_NUMBER | |
FILES=$(gh pr view $PR_NUMBER --json files -q '.files[].path') | |
echo "$FILES" | grep '\.tf$' | sed 's|/[^/]*$||' | sort -u | jq -R -s -c 'split("\n") | map(select(length > 0))' > changed_dirs.json | |
cat changed_dirs.json | |
echo "dirs=$(cat changed_dirs.json)" >> $GITHUB_OUTPUT | |
- name: Confirm Output | |
run: | | |
echo "Changes directories: ${{ steps.changed-dirs.outputs.dirs }}" | |
outputs: | |
dirs: ${{ steps.changed-dirs.outputs.dirs }} | |
terraform-preflight: | |
name: "terraform-preflight" | |
runs-on: ubuntu-latest | |
permissions: | |
pull-requests: write | |
needs: extract-changed-directories | |
if: needs.extract-changed-directories.outputs.dirs != '[]' && needs.extract-changed-directories.outputs.dirs != '' | |
strategy: | |
matrix: | |
dir: ${{ fromJson(needs.extract-changed-directories.outputs.dirs) }} | |
defaults: | |
run: | |
working-directory: ${{ matrix.dir }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Setup Terraform | |
uses: hashicorp/setup-terraform@v1 | |
with: | |
terraform_version: 0.13.0 | |
cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }} | |
- name: Terraform Format | |
id: fmt | |
run: terraform fmt -check | |
- name: Terraform Init | |
id: init | |
run: terraform init | |
- name: Terraform Validate | |
id: validate | |
run: terraform validate -no-color | |
- name: Terraform Plan | |
id: plan | |
if: github.event_name == 'pull_request' | |
run: terraform plan -no-color -input=false | |
continue-on-error: true | |
- name: Update Pull Request | |
uses: actions/github-script@v6 | |
if: github.event_name == 'pull_request' | |
env: | |
PLAN: ${{ steps.plan.outputs.stdout }} | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
const output = `#### Terraform Format and Style 🖌\`${{ steps.fmt.outcome }}\` | |
#### Terraform Initialization ⚙️\`${{ steps.init.outcome }}\` | |
#### Terraform Validation 🤖\`${{ steps.validate.outcome }}\` | |
#### Terraform Plan 📖\`${{ steps.plan.outcome }}\` | |
<details><summary>Show Plan</summary> | |
\`\`\`terraform\n | |
${process.env.PLAN} | |
\`\`\` | |
</details> | |
*Pushed by: @${{ github.actor }}, Action: \`${{ github.event_name }}\`*`; | |
github.rest.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: output | |
}) | |
- name: Terraform Plan Status | |
if: steps.plan.outcome == 'failure' | |
run: exit 1 |