Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How stop workflow when the plan detects no changes #100

Open
hspecter758 opened this issue Apr 1, 2021 · 1 comment
Open

How stop workflow when the plan detects no changes #100

hspecter758 opened this issue Apr 1, 2021 · 1 comment
Labels
question Further information is requested

Comments

@hspecter758
Copy link

What is the easiest way to find if the "terraform plan" command detect zero changes so I can stop the workflow and don't call "terraform apply"?

With the previous edition this action (hashicorp/terraform-github-actions) I could use a condition like below:

      - name: 'Terraform Apply'
        if: steps.tf_plan.outputs.tf_actions_plan_has_changes == 'true'
        id: terraform_apply
        uses: hashicorp/terraform-github-actions@master
        with:
          tf_actions_version: ${{ env.tf_version }}
          tf_actions_subcommand: 'apply'

How can I do have a similar condition with hashicorp/setup-terraform ?

@aeschright aeschright added the question Further information is requested label Apr 20, 2021
@johnbooth
Copy link

Is this feature going to be added back into this action in the future?

I had to create a workaround for this by adding the -detailed-exitcode to the terraform plan and creating my own error conditions and checks to see if I should run the apply job.
One of the downsides of this approach is that I see failures in the annotations when changes are required because the terraform plan exit code is 2.

      - name: Terraform Plan - https://www.terraform.io/docs/commands/plan.html
        id: plan
        run: terraform plan -detailed-exitcode -input=false -out=plan.out
        continue-on-error: true

      - name: Check for Plan Failure
        if: steps.plan.outputs.exitcode == 1
        run: exit 1

    outputs:
      planExitcode: ${{ steps.plan.outputs.exitcode }}

  apply:
    name: "Terraform: apply"
    needs: plan
    if: needs.plan.outputs.planExitcode == 2
    runs-on: ubuntu-latest

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants