From 0b8adcbc9285f48a34a318938c882bea71849d7b Mon Sep 17 00:00:00 2001 From: Edmund Miller Date: Wed, 22 Nov 2023 21:15:53 -0600 Subject: [PATCH] ci(#8): Switch to fork https://github.com/GetTerminus/terraform-pr-commenter --- .github/workflows/terraform.yml | 87 ++++++++++++++++----------------- 1 file changed, 43 insertions(+), 44 deletions(-) diff --git a/.github/workflows/terraform.yml b/.github/workflows/terraform.yml index e98798f..f6dadff 100644 --- a/.github/workflows/terraform.yml +++ b/.github/workflows/terraform.yml @@ -2,82 +2,81 @@ name: "Terraform" on: pull_request: - push: - branches: - - master env: TF_IN_AUTOMATION: true + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + TF_WORKSPACE: "example" + TF_VERSION: "1.6.4" TF_VAR_gh_token: ${{ secrets.GITHUB_TOKEN }} TF_VAR_billing_email: ${{ secrets.TF_VAR_billing_email }} jobs: terraform: - name: "Terraform" + name: Run Terraform and Comment runs-on: ubuntu-latest - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - TF_IN_AUTOMATION: true steps: - - name: Checkout - uses: actions/checkout@v2 - - - name: Setup Terraform - uses: hashicorp/setup-terraform@v1 + - name: HashiCorp - Setup Terraform + uses: hashicorp/setup-terraform@v2 with: - cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }} - terraform_version: 0.15.0 - + terraform_version: ${{ env.TF_VERSION }} - name: Terraform Format id: fmt - run: terraform fmt -check -recursive + run: | + terraform fmt -check -recursive -diff continue-on-error: true - - - name: Post Format - if: always() && github.ref != 'refs/heads/master' && (steps.fmt.outcome == 'success' || steps.fmt.outcome == 'failure') - uses: robburger/terraform-pr-commenter@v1 + - name: Post Format Comment + if: ${{ always() && (steps.fmt.outcome == 'success' || steps.fmt.outcome == 'failure') }} + uses: GetTerminus/terraform-pr-commenter@v3 with: commenter_type: fmt commenter_input: ${{ format('{0}{1}', steps.fmt.outputs.stdout, steps.fmt.outputs.stderr) }} commenter_exitcode: ${{ steps.fmt.outputs.exitcode }} - - name: Terraform Init id: init - run: terraform init - - - name: Post Init - if: always() && github.ref != 'refs/heads/master' && (steps.init.outcome == 'success' || steps.init.outcome == 'failure') - uses: robburger/terraform-pr-commenter@v1 + run: terraform init -lock=false -input=false + - name: Post Init Comment + if: ${{ always() && (steps.init.outcome == 'success' || steps.init.outcome == 'failure') }} + uses: GetTerminus/terraform-pr-commenter@v3 with: commenter_type: init commenter_input: ${{ format('{0}{1}', steps.init.outputs.stdout, steps.init.outputs.stderr) }} commenter_exitcode: ${{ steps.init.outputs.exitcode }} - - name: Terraform Validate id: validate run: terraform validate - - - name: Post Validate - if: always() && github.ref != 'refs/heads/master' && (steps.validate.outcome == 'success' || steps.validate.outcome == 'failure') - uses: robburger/terraform-pr-commenter@v1 + - name: Post TF Validate Comment + if: ${{ always() && (steps.validate.outcome == 'success' || steps.validate.outcome == 'failure') }} + uses: GetTerminus/terraform-pr-commenter@v3 with: commenter_type: validate commenter_input: ${{ format('{0}{1}', steps.validate.outputs.stdout, steps.validate.outputs.stderr) }} commenter_exitcode: ${{ steps.validate.outputs.exitcode }} - + - name: TFLint - Setup + id: tflint + uses: terraform-linters/setup-tflint@v3 + with: + tflint_wrapper_enabled: true + - name: TFLint - Run + run: | + tflint --version + tflint --init + tflint + - name: Post TFLint Comment + if: ${{ always() && (steps.tflint.outcome == 'success' || steps.tflint.outcome == 'failure') }} + uses: GetTerminus/terraform-pr-commenter@dpr-update-commenter + with: + commenter_type: tflint + commenter_input: ${{ format('{0}{1}', steps.tflint.outputs.stdout, steps.tflint.outputs.stderr) }} + commenter_exitcode: ${{ steps.tflint.outputs.exitcode }} - name: Terraform Plan id: plan - run: terraform plan -out workspace.plan - - - name: Post Plan - if: always() && github.ref != 'refs/heads/master' && (steps.plan.outcome == 'success' || steps.plan.outcome == 'failure') - uses: robburger/terraform-pr-commenter@v1 + run: terraform plan -lock=false -input=false |& tee tf_plan.txt + - uses: GetTerminus/terraform-pr-commenter@v3 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + TF_WORKSPACE: ${{ inputs.terraform_workspace }} with: commenter_type: plan - commenter_input: ${{ format('{0}{1}', steps.plan.outputs.stdout, steps.plan.outputs.stderr) }} - commenter_exitcode: ${{ steps.plan.outputs.exitcode }} - - - name: Terraform Apply - id: apply - if: github.ref == 'refs/heads/master' && github.event_name == 'push' - run: terraform apply workspace.plan + commenter_plan_path: tf_plan.txt + commenter_exitcode: ${{ steps.plan.outputs.exit }}