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 -ignore-empty-output flag #23008

Merged
merged 2 commits into from
Nov 7, 2019
Merged

Add -ignore-empty-output flag #23008

merged 2 commits into from
Nov 7, 2019

Conversation

jgrancell
Copy link
Contributor

This PR adds an -ignore-empty-output flag to the terraform output command.

With this flag, when terraform output -ignore-empty-flag is run against no state or empty state, the exit status is 0 and the output is not from Error().

Without this flag, when terraform output is run against no state or empty state, the exit status remains 1 and the output continues to be from Error().

When merged, resolves #18975

@hashicorp-cla
Copy link

hashicorp-cla commented Oct 5, 2019

CLA assistant check
All committers have signed the CLA.

@apparentlymart
Copy link
Contributor

Hi @jgrancell! Sorry for the slow response here, and thanks for working on this.

We usually try to keep the number of options and other configurables in the CLI commands to a minimum and instead try to find a single behavior that's a good compromise between the various use-cases, because that makes Terraform easier to learn and use and it gives fewer different codepaths to maintain compatibility with as Terraform evolves.

With that in mind, I was thinking about ways we could potentially meet your goal here without adding an extra option. It feels to me like there being no outputs defined is not really an error, because there being no outputs is a perfectly legitimate situation true of many reasonable configurations. We include the extra error message in the output in order to avoid a confusing situation where the command would otherwise produce no output at all, but I think we could reasonably continue to produce that error message while returning exit status zero.

Therefore I'd like to propose a smaller change to make the exit status be zero when we display this error message, and make that be the default (and only) behavior. Folks who are running Terraform manually at a shell will still see the same result, while folks who are running Terraform in automation will avoid having to treat the zero-outputs case as special. For those who do want to treat zero outputs as special for some reason, they can use terraform output -json and parse the output to recognize that situation instead.

What do you think? Would that simplification still allow you to achieve your goals here?

Thanks again for working on this!

@apparentlymart apparentlymart added the waiting-response An issue/pull request is waiting for a response from the community label Nov 6, 2019
@apparentlymart
Copy link
Contributor

Thanks @jgrancell! I'm going to merge this now.

@apparentlymart apparentlymart merged commit ac3578a into hashicorp:master Nov 7, 2019
@jgrancell
Copy link
Contributor Author

Sounds good @apparentlymart . Thanks. Time to find a new bug to work on from the backlog.

@ghost ghost removed the waiting-response An issue/pull request is waiting for a response from the community label Nov 7, 2019
@ghost
Copy link

ghost commented Mar 29, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Mar 29, 2020
@jgrancell jgrancell deleted the ignore-empty-output branch April 10, 2020 18:40
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

terraform output should not error when no outputs defined
4 participants