Open ben-z opened 1 month ago
I'm currently using a quick and dirty workaround: next(extract_json_objects(stdout))
def extract_json_objects(text, decoder=JSONDecoder()):
"""
Find JSON objects in text, and yield the decoded JSON data
Does not attempt to look for JSON arrays, text, or other JSON types outside
of a parent JSON object.
Derived from https://stackoverflow.com/a/54235803
This is useful for handling JSON objects embedded in a string, such as
when this bug pollutes the output:
https://github.com/hashicorp/terraform/issues/35159
"""
pos = 0
while True:
match = text.find("{", pos)
if match == -1:
break
try:
result, index = decoder.raw_decode(text[match:])
yield result
pos = match + index
except ValueError:
pos = match + 1
Terraform Version
Terraform Configuration Files
Debug Output
Not relevant
Expected Behavior
terraform -output json
should output only JSON.Actual Behavior
The output is not pure json. It contains some error messages from intermittent (retriable) errors.
These are the culprit messages: https://github.com/hashicorp/terraform/blob/dc3a040a4164ffba863cef7bd216c4f49e30e40b/internal/command/views/cloud.go#L51-L56
This makes it nontrivial for downstream applications to parse the output.
Steps to Reproduce
terraform -output json
Additional Context
No response
References
No response