-
Notifications
You must be signed in to change notification settings - Fork 242
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
Do not fail when theres an exit-code 2 #125
Conversation
Hey @dannyibishev I am working on the same case as you now, but what I get from GitHub folks is, Actions itself only supports success (0 exit code) vs failure (anything else). So, it's not lack of support in Terraform Actions task, but general behavior of GitHub Actions. |
Thanks @DariuszPorowski for the additional detail. We'll need to confirm what the best approach is here |
We gone through a bit of song and dance here attempting to get apply job to run automatically if no changes to the plan. - name: Terraform Plan - https://www.terraform.io/docs/commands/plan.html
id: plan
run: terraform plan -detailed-exitcode -input=false -out=plan.out ${{ inputs.tf_plan_args}} ${{ secrets.tf_plan_secret_args }}
continue-on-error: true
- name: Check for Plan Failure
if: steps.plan.outputs.exitcode == 1
run: exit 1
# Encrypt - Terraform plan.out
- name: Encrypt Terraform "plan.out"
if: steps.plan.outputs.exitcode == 2
run: gpg --quiet --batch --yes --passphrase ${{ secrets.gpg_passphrase }} --symmetric --cipher-algo AES256 plan.out
# Github - Upload Artifact
# https://github.com/marketplace/actions/upload-a-build-artifact
- name: Upload Encrypted Artifact
if: steps.plan.outputs.exitcode == 2
uses: actions/upload-artifact@v2
with:
name: ${{ inputs.tf_workspace }}-encrypted-plan
path: ${{ inputs.working_dir }}/plan.out.gpg
outputs:
planExitcode: ${{ steps.plan.outputs.exitcode }}
apply:
name: "Terraform: apply"
needs: plan
if: needs.plan.outputs.planExitcode == 2
runs-on: ubuntu-latest
environment:
name: ${{ inputs.github_env }} The exit code stuff you guys are talking about gives us the annotation errors and is rather confusing to people. |
This should allow plans to succeed using the terraform_wrapper functionality whenever an exit code of 2 is returned. https://www.terraform.io/docs/cli/commands/plan.html#detailed-exitcode - This is useful for adding custom steps in our GitHub action workflows. - Not a Javascript developer so Im not sure how valid the OR condition is.
@dannyibishev I've rebased your PR with latest changes so it will pass linting. I changed the condition to exit early if it is 0 or 2 instead of setting the exit code to be more explicit with our returns. We'll tes this out and get it merged in the 2.1.0 release. |
Hello, With terraform-wrapper, we always have a response code 0 even if there is changes and option --detailled-exit-code. We cannot return exitCode 2 with the wrapper because of setFailed function. There is an opened issue for custom exit code. Maybe, it will be better to add an environnement variable with status code for the wrapper. |
I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions. |
This should allow plans to succeed using the terraform_wrapper functionality whenever an exit code of
2
is returned.https://www.terraform.io/docs/cli/commands/plan.html#detailed-exitcode
Disclaimer: Im not a Javascript developer so Im not sure how valid the OR condition is.