You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The output is not pure json. It contains some error messages from intermittent (retriable) errors.
> terraform -output json
There was an error connecting to HCP Terraform. Please do not exit Terraform to prevent data loss!
Trying to restore the connection...
Still trying to restore the connection... (3s elapsed)
{}
I'm currently using a quick and dirty workaround: next(extract_json_objects(stdout))
defextract_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=0whileTrue:
match=text.find("{", pos)
ifmatch==-1:
breaktry:
result, index=decoder.raw_decode(text[match:])
yieldresultpos=match+indexexceptValueError:
pos=match+1
Terraform has [a
bug](hashicorp/terraform#35159) where the JSON
output of `terraform output -json` can be polluted by error messages.
This is a workaround to parse the output json properly.
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:
terraform/internal/command/views/cloud.go
Lines 51 to 56 in dc3a040
This makes it nontrivial for downstream applications to parse the output.
Steps to Reproduce
terraform -output json
Additional Context
No response
References
No response
The text was updated successfully, but these errors were encountered: