Since the steps are repetitive, quite verbose and with clear parameters, I wanted to encapsulate it within a GitHub composite action.
I managed to work around its current limitations -i.e. not supporting the continue-on-error functionality.
But the action just did not post a comment. Not even mentioned: "this is not a PR..."
@robburger
❓ Am I missing something?
I would love to use this "composite" version in my workflows.
.github/actions/terraform_comment_pr/actions.yml
name: 'Terraform Comment PR'
description: 'Init, Plan and Apply TF projects, commenting Plan output onto PR'
inputs:
deploymentDirectory: # id of input
description: 'the directory of the terraform project'
required: true
env: # id of input
description: 'the deployment environment'
required: true
workspaceEnv: # id of input
description: 'the deployment WORKSPACE environment to be activated'
required: true
Once again, thanks for this great Action!
Since the steps are repetitive, quite verbose and with clear parameters, I wanted to encapsulate it within a GitHub composite action.
I managed to work around its current limitations -i.e. not supporting the
continue-on-error
functionality. But the action just did not post a comment. Not even mentioned: "this is not a PR..."@robburger ❓ Am I missing something? I would love to use this "composite" version in my workflows.
runs: using: "composite" steps:
uses: hashicorp/setup-terraform@v1 with: terraform_version: 0.14.5
name: > Terraform Init >> Env: ${{ inputs.env }} | Dir: ${{ inputs.deploymentDirectory }} shell: bash run: | cd ${{ inputs.deploymentDirectory }} terraform init -backend=true -backend-config=environment/${{ inputs.env }}/backend-config.tfvars terraform workspace new ${{ inputs.workspaceEnv }} || terraform workspace select ${{ inputs.workspaceEnv }}
name: > Terraform Plan >> Env: ${{ inputs.env }} | Dir: ${{ inputs.deploymentDirectory }} id: plan shell: bash run: | cd ${{ inputs.deploymentDirectory }}
Workaround continue-on-error not being supported
name: > Post Plan >> Env: ${{ inputs.env }} | Dir: ${{ inputs.deploymentDirectory }} if: always() && github.ref != 'refs/heads/master' && (steps.plan.outcome == 'success' || steps.plan.outcome == 'failure') uses: robburger/terraform-pr-commenter@v1 env: TF_WORKSPACE: ${{ format('Env= {0} | Dir= {1}', inputs.env, inputs.deploymentDirectory) }} with: commenter_type: plan commenter_input: ${{ format('{0}{1}', steps.plan.outputs.stdout, steps.plan.outputs.stderr) }} commenter_exitcode: ${{ steps.plan.outputs.exitcode }}
name: Raise error if plan.exitcode == 1 if: steps.plan.outputs.exitcode == 1 shell: bash run: exit 1
name: > Terraform Apply >> Env: ${{ inputs.env }} | Dir: ${{ inputs.deploymentDirectory }} if: steps.plan.outputs.exitcode == 2 shell: bash run: | cd ${{ inputs.deploymentDirectory }} terraform apply -var-file environment/${{ inputs.env }}/environment.tfvars -input=false -auto-approve
And the actual workflow would look like this: