Is there any way to run terraform apply in such a way that the normal, human readable output is sent to stdout, and the json output is written to a file?
We’d like to have access to the JSON output for automation and tooling but we don’t want to lose the normal stdout output.
terraform plan -out=foobar.state
terraform apply -state=foobar.state
It seems like you might be writing your own wrapper for terraform. If you are using github or gitlab there are native integrations for terraform you may want to consider as they already have this functionality built in.
Assuming you mean terraform apply -json, which produces JSON-formatted event output, then that is not possible today: the JSON UI output is intended to allow implementing an alternative UI on top of Terraform which replaces rather than augments the normal output. For example, Terraform Cloud uses it to produce an interactive HTML-based UI for reviewing the output, which entirely replaces the console-based UI.