Skip to content
Closed
Show file tree
Hide file tree
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
1 change: 0 additions & 1 deletion .github/workflows/infra_features.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ jobs:
ARM_TENANT_ID: ${{ secrets.ARM_TENANT_ID }}

runs-on: ubuntu-latest

defaults:
run:
shell: bash
Expand Down
136 changes: 64 additions & 72 deletions .github/workflows/infra_main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,88 +2,80 @@ name: infra-main

on:
pull_request:
types: [opened, closed]
push:
branches:
- infra_main

jobs:
infracost-pull-request-checks:
name: Infracost Pull Request Checks
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
permissions:
contents: read
pull_request: write
env:
ARM_CLIENT_ID: ${{ secrets.ARM_CLIENT_ID }}
ARM_CLIENT_SECRET: ${{ secrets.ARM_CLIENT_SECRET }}
ARM_SUBSCRIPTION_ID: ${{ secrets.ARM_SUBSCRIPTION_ID }}
ARM_TENANT_ID: ${{ secrets.ARM_TENANT_ID }}

steps:
- name: Checkout PR branch
uses: actions/checkout@v4
name: Infracost Pull Request Checks
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write

- name: Terraform plan
id: plan
if: github.event_name == 'pull_request'
run: terraform plan -no-color -input=false
continue-on-error: true

- uses: actions/github-script@v6
if: github.event_name == 'pull_request'
env:
PLAN: "terraform\n${{ steps.plan.outputs.stdout }}"
with:
script: |
const output = `#### Terraform Plan 📖`${{ steps.plan.outcome }}\`

<details><summary>Show Plan</summary>

\`\`\`\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
steps:
- name: checkout repository
uses: actions/checkout@v3

- name: Setup Infracost
uses: infracost/actions/setup@v3
with:
api-key: ${{ secrets.INFRACOST_API_KEY }}
- name: Setup Terraform
uses: hashicorp/setup-terraform@v2
with:
terraform_version: 1.11.0

# - name: Checkout base branch
# uses: actions/checkout@v4
# with:
# ref: '${{ github.event.pull_request.base.ref }}'
- name: Terraform Init
run: |
cd infrastructure/terraform
terraform init

- name: Generate Infracost cost estimate
run: |
infracost breakdown --path=infrastructure \
--format=json \
--out-file=/tmp/infracost.json
- name: Terraform plan
run: |
cd infrastructure/terraform
terraform plan -out .planfile

# - name: Checkout PR branch
# uses: actions/checkout@v4
- name: Post PR comment
uses: borchero/terraform-plan-comment@v2
with:
token: ${{ github.token }}
planfile: ./infrastructure/terraform/planfile
header: 📝 Terraform Plan

- name: Setup Infracost
uses: infracost/actions/setup@v3
with:
api-key: ${{ secrets.INFRACOST_API_KEY }}

# - name: Generate Infracost diff
# run: |
# infracost diff --path=. \
# --format=json \
# --compare-to=/tmp/infracost-base.json \
# --out-file=/tmp/infracost.json
# - name: Checkout base branch
# uses: actions/checkout@v4
# with:
# ref: '${{ github.event.pull_request.base.ref }}'

- name: Post Infracost comment
run: |
infracost comment github --path=/tmp/infracost.json \
--repo=$GITHUB_REPOSITORY \
--github-token=${{ github.token }} \
--pull-request=${{ github.event.pull_request.number }} \
--behavior=update
- name: Generate Infracost cost estimate
run: |
infracost breakdown --path=infrastructure \
--format=json \
--out-file=/tmp/infracost.json

# - name: Checkout PR branch
# uses: actions/checkout@v4

# - name: Generate Infracost diff
# run: |
# infracost diff --path=. \
# --format=json \
# --compare-to=/tmp/infracost-base.json \
# --out-file=/tmp/infracost.json

- name: Post Infracost comment
run: |
infracost comment github --path=/tmp/infracost.json \
--repo=$GITHUB_REPOSITORY \
--github-token=${{ github.token }} \
--pull-request=${{ github.event.pull_request.number }} \
--behavior=update
Loading