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

Allow null value outputs to be present in json output #34080

Open
jorenvh1 opened this issue Oct 13, 2023 · 1 comment
Open

Allow null value outputs to be present in json output #34080

jorenvh1 opened this issue Oct 13, 2023 · 1 comment

Comments

@jorenvh1
Copy link

Terraform Version

Terraform v1.6.1

Use Cases

When using the json output of terraform as config for other systems, it might be a good idea to also give the option to include the null values inside the output json. This way you can be sure that certain keys will always exist.

Attempted Solutions

The current terraform output command with the json option does not output values that have a null value.

Proposal

It would be nice if either by default the output json always includes null values. It might also be an option for the terraform output command like this

terraform output --json --allow-null

References

No response

@jorenvh1 jorenvh1 added enhancement new new issue not yet triaged labels Oct 13, 2023
@jbardin jbardin added core and removed new new issue not yet triaged labels Oct 13, 2023
@jbardin
Copy link
Member

jbardin commented Oct 13, 2023

Hi @jorenvh1,

Thanks for filing the issue. This unfortunately is a little more difficult than just displaying a null value. Throughout Terraform null is used to indicate the absence of a value, and for top-level objects, triggers their removal from state. If you inspect the state file, you will see that there is no output at all if the value was null, so there is nothing for Terraform to display in that case.

In most cases if you are decoding json, there is usually a way to handle missing keys in the same manner as keys with a null value, given of course that you know what keys to expect. Some other workarounds may be to handle the -json output from the CLI plan itself which has information about all actions being performed, or inspect the stored plan which does store null output values, as that is captured before they are applied to the state.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants