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

add detailed-exitcode-ish behavior with saved plan file #23542

Open
StephenWithPH opened this issue Dec 2, 2019 · 3 comments
Open

add detailed-exitcode-ish behavior with saved plan file #23542

StephenWithPH opened this issue Dec 2, 2019 · 3 comments
Labels
enhancement v0.12 Issues (primarily bugs) reported against v0.12 releases

Comments

@StephenWithPH
Copy link

StephenWithPH commented Dec 2, 2019

Current Terraform Version

Terraform v0.12.3

Use-cases

When running Terraform in automation per official guidance with human approval between plan and apply, a saved plan is always generated. If the saved plan is a no-op, it would be useful to be able to determine that fact using only the saved plan in later automation stages. This would allow build stages which either wait for human plan approval or run apply on the saved plan to exit early.

Attempted Solutions

  1. terraform plan can be invoked with -detailed-exitcode and -out=<path> to both create a plan file and communicate whether there's work to be done. User-provided convenience scripts in the build step can respond accordingly, but many build systems have limitations when trying to communicate between different steps/stages/jobs in the larger workflow/graph/pipeline. Collapsing -detailed-exitcode's 1 = Error and 2 = Succeeded with non-empty diff (changes present) exit codes into the usual "any non-zero exit code is a failure" on the build ends up masking useful feedback ("plan failed" versus "plan shows work to do"). Doing so also forces the rest of the workflow/graph/pipeilne down a "failure" path, which is a bit abusive if trying simply to omit the terraform applystep when appropriate.
  2. terraform show -json ./tfplan | jq '...' seems possible to back into this, but using jq to parse the plan json to determine if there's work to be done is... gross. The user's jq filter may become a source of bugs in the workflow/graph/pipeline logic.

Proposal

(either/or)

  • enhance terraform plan to take an optional path to an existing plan file and allow the existing -detailed-exitcode flag to accurately reflect the state of the provided plan file
  • enhance terraform show to take an optional -detailed-exitcode flag to accurately reflect the state of the provided plan file

References

@danieldreier danieldreier added the v0.12 Issues (primarily bugs) reported against v0.12 releases label Dec 2, 2019
@danieldreier
Copy link
Contributor

@StephenWithPH this is an interesting suggestion and the workflow you're describing makes sense to me. For clarification, is this something you're hoping to build and you're filing this to coordinate prior to making a pull request, or are you asking the terraform core team to make this improvement?

@danieldreier danieldreier added the waiting-response An issue/pull request is waiting for a response from the community label Dec 2, 2019
@StephenWithPH
Copy link
Author

@danieldreier ... thank you for the quick response!

For clarification, is this something you're hoping to build and you're filing this to coordinate prior to making a pull request, or are you asking the terraform core team to make this improvement?

I can't honestly commit to finding the time to implement this and PR it myself. I would love it if the Terraform Core team gets to it, but I'm happy to see this wait and (hopefully) accrue enough 👍 to merit Core team efforts.

@ghost ghost removed the waiting-response An issue/pull request is waiting for a response from the community label Dec 2, 2019
@danieldreier
Copy link
Contributor

Thanks @StephenWithPH! This isn't going to be a short-term priority for us, but I think it's a solid idea. If someone wants to build it, please put your ✋up and we should design it a little more together. This is a solid area for work, but we'll want to spec it out a little more before work starts to make sure we don't make breaking changes to exit codes. If anyone is interested, please say so. In the meantime, I'm going to put this in our backlog and we'll prioritize based on interest and engineering availability.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement v0.12 Issues (primarily bugs) reported against v0.12 releases
Projects
None yet
Development

No branches or pull requests

2 participants