-
Notifications
You must be signed in to change notification settings - Fork 116
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 option to Plan #55
Add -detailed-exitcode option to Plan #55
Conversation
Per the internal conversation, I think we should make the following changes to surface this functionality:
We probably need a test case for a diff and no diff, not sure if that is present in the e2e testing yet, so probably need to add a test case that modifies the TF file, I can assist with this though if you have any questions. |
func (tf *Terraform) Plan(ctx context.Context, opts ...PlanOption) (bool, error) { | ||
cmd := tf.planCmd(ctx, opts...) | ||
err := tf.runTerraformCmd(cmd) | ||
if err != nil && cmd.ProcessState.ExitCode() == 2 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You probably need to confirm this is ExitError
, ie something like:
if err != nil && cmd.ProcessState.ExitCode() == 2 { | |
var exitErr *exec.ExitError | |
if errors.As(err, &exitErr) && cmd.ProcessState.ExitCode() == 2 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't believe this will work since the err
here is returned from parseError()
(hitting the default
case). At that time the original err
is essentially discarded.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I perhaps add another case to parseError()
that checks the original error and returns a new error type that I can then check from Plan()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, i think we should probably fix the default case to just wrap the ExitError
so that its compatible with errors.As
/Is
.
This needs a rebase but I think we just merge it as is. The refactor for the error handling won't be user facing, so can just be a future improvement if someone gets to it. |
This adds the `-detailed-exitcode` option to `tfexec.Plan()` along with a new error named `ErrExitCodeTwo` (name suggestions welcomed) that is returned when the exit code of a given Terraform command is `2`.
Return a boolean that tells the caller whether the plan diff was empty or non-empty. Added and updates tests to be compatible with this change.
This adds the
-detailed-exitcode
option totfexec.Plan()
and returnsa boolean detailing whether a plan diff is empty or non-empty.
This allows the caller to make decisions when the plan has changes.