diff --git a/.github/workflows/infra_features.yaml b/.github/workflows/infra_features.yaml index 3f8b98a..3584760 100644 --- a/.github/workflows/infra_features.yaml +++ b/.github/workflows/infra_features.yaml @@ -15,7 +15,6 @@ jobs: ARM_TENANT_ID: ${{ secrets.ARM_TENANT_ID }} runs-on: ubuntu-latest - defaults: run: shell: bash diff --git a/.github/workflows/infra_main.yaml b/.github/workflows/infra_main.yaml index 33f3014..baaaf11 100644 --- a/.github/workflows/infra_main.yaml +++ b/.github/workflows/infra_main.yaml @@ -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 }}\` - -
Show Plan - - \`\`\`\n - ${process.env.PLAN} - \`\`\` - -
- *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 \ No newline at end of file + - 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 \ No newline at end of file