terraform-exec
terraform-exec copied to clipboard
Plan/Apply `-json` support missing
Plans and applies now support streaming json with the -json flag. Adding support for the flag may not be enough--including streamed data structures from stdout would be preferred.
As a workaround:
ctx := context.Background()
outfile := "./mystate.state"
tfexec.Plan(context, tfexec.Out(outfile))
tfjson, _ := txexec.ShowPlanFile(context, outfile)
b, _ := json.Marshal(tfjson)
jsonOutfile := "./mystate.json"
os.WriteFile(jsonOutfile, b, 0666)
We have a use case for being able to stream JSON with the -json flag in Ability to test whether warnings are raised during test steps.
The intention is to modify the acceptance testing framework so that the -json flag can be used with terraform-exec to allow parsing of the streamed JSON in order to be able to verify that warning diagnostics are being emitted in specific tests.