Terraform v0.14.0
output "foo" {
value = "Hello, World"
}
With Terraform 0.13:
$ terraform output foo
Hello, World
With Terraform 0.14:
$ terraform output foo
"Hello, World"
Note that the output is now wrapped in quotes.
For any script or other automation that relied on terraform output, this is a backwards incompatible change that may cause problems. Was this change intentional? Is it in the CHANGELOG?
terraform initterraform applyterraform output fooSame problem here, just upgraded to terraform 0.14 on a project and it _is_ causing us problems in one of our scripts depending on the terraform output command
Hi @brikis98 & @nover - Thanks for reporting this.
It's a discussion we've been preparing to have as we move to Terraform 1.0.
This change, in particular, is part of a group of small changes we're introducing in 0.14 that we don't consider breaking and I'll try to explain why here.
We consider the console output of Terraform human readable; specifically designed and optimized for operators and practitioners to review themselves. As a result we occasionally (maybe even regularly) intend to tweak that output to help improve consistently, clarity, actionability and more.
In order to provide a stable surface area for using Terraform in automation, we encourage our community to rely on outputs (not to be confused with terraform output) produced with the -json command line option. This includes terraform output -json, terraform version -json and terraform show -json (for creating versions of the plan and state in JSON).
As we mature and evolve Terraform we're hopeful this delineation will produce better results for both interactive, practitioner-focused workflows and automated workflows where Terraform is part of a larger system.
Duplicate of: https://github.com/hashicorp/terraform/issues/26831
PS - It also aligns the formatting of terraform output with the formatting of terraform show which did include quotes in the console output.
OK - thanks for the explanation. I found a workaround as described in the duplicate issue using terraform show and some jq parsing.
However, I would argue that aligning output and show does not necessarily make sense to me. show for humans with quotes and output for machines without quotes.
I just ran into this issue which has broken my workflows where I relied on exporting terraform outputs.
I would argue that aligning output and show does not necessarily make sense to me. show for humans with quotes and output for machines without quotes.
:100:% agree with this - I would like to be able to actually use the result of terraform output programmatically without having to parse it.
This is a nasty breaking change which I think should be reverted. If you want to show "human readable" output then it should be behind a --human-readable flag instead of breaking peoples existing code.
Also, including the <<EOT heredoc markers makes it less human readable IMHO.
If this won't be reverted can we at least get an --old-format flag so that we aren't forced to parse the output to get something usable.
Well, it is documented: https://www.terraform.io/docs/commands/output.html#use-in-automation (although, not sure since when). And I can see why they'd want to align output and show since the aim of both is the same (human readable output), so I would expect them both to print out in the same way by default. It is, however, a breaking change, but to a CLI that was not meant to be used in automation.
According to way back machine / web archive that chapter was not there in November 2020, so it's a new chapter documenting the human readable form. If show and output serve the same purpose, why have both?
@nover It seems like there is some overlap in what show and output do as they both can be used to get human readable (or formatted) output about the state file. But show also works on plan files. That seems to be the only difference on the surface. I can see how it may be less confusing to give output a different purpose altogether, perhaps it only prints formatted values (JSON by default?) -- it just has a default output format right now that matches show.
After some consideration we've added a -raw CLI argument to output. Thanks for all the input!
From Martin's PR:
So far the output command has had a default output format intended for human consumption and a JSON output format intended for machine consumption.
However, until Terraform v0.14 the default output format for primitive types happened to be almost a raw string representation of the value, and so users started using that as a more convenient way to access primitive-typed output values from shell scripts, avoiding the need to also use a tool like "jq" to decode the JSON. Terraform v0.14 improved the default terraform output formatting to be consistent with how we print values in other commands such as terraform plan, but consequently it's no longer suitable for direct consumption by shell scripts.
Recognizing that primitive-typed output values are common and that processing them with shell scripts is common, this commit introduces a new -raw mode which is explicitly intended for that use-case, guaranteeing that the result will always be the direct result of a string conversion of the output value, or an error if no such conversion is possible.
Our policy elsewhere in Terraform is that we always use JSON for machine-readable output. We adopted that policy because our other machine-readable output has typically been complex data structures rather than single primitive values. A special mode seems justified for output values because it is common for root module output values to be just strings, and so it's pragmatic to offer access to the raw value directly rather than requiring a round-trip through JSON.
I'm not intending this to set any precedent for offering -raw options on any other commands. I would also consider any further complexity, such as selecting a deep primitive value out of a nested data structure using an expression/traversal, to be out of scope for this command. jq is a far better answer to those more complex cases, because it has a richer query language and various output post-processing options.
0.14 backport here: https://github.com/hashicorp/terraform/pull/27224
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.
Most helpful comment
After some consideration we've added a
-rawCLI argument tooutput. Thanks for all the input!From Martin's PR:
0.14 backport here: https://github.com/hashicorp/terraform/pull/27224