TF Plan output format is very different when run from CLI vs API

Hi - I’m working on building a CI pipeline that runs a speculative plan as part of my team’s pull request workflow. I’m having the plan output displayed in a Github comment.

I’ve been experimenting with the tfci workflow tool, as well as using the API directly, and the CLI. They each have their advantages. But I really like how the plan output is formatted when executed from the CLI. Using the CLI, the output displays each resource with +, -, ~ signs to indicate what’s going to happen within the change.

On the other hand, the API plan output (using the ‘Retrieve the JSON execution plan’) is far less easy to interpret. Within this API output JSON, there is a ‘resource_changes’ array that contains all the information about each changing resource, including a ‘before’ and ‘after’ section. This JSON does not contain the +,-,~ signs to easily view what’s about to change.

Am I missing something? Is there a way to get that CLI-style plan output while using the API? Or is the recommendation that I should just ask my users to navigate from the PR to TF Cloud run page to see the details about what exactly is changing within the resource?

Hi @mark.harrison.mcdona,

Unfortunately, when Terraform Cloud runs Terraform CLI it does so using the -json option and exports the plan using terraform show -json PLANFILE because Terraform Cloud wants the underlying data to drive its own UI, rather than the CLI output intended for folks who are running Terraform directly on their local system.

Terraform Cloud doesn’t use the “human-oriented” output and so it doesn’t get generated at all in that execution path, so there’s nowhere to retrieve it from.

I expect that linking to the Terraform Cloud run page will be the most expedient approach, since Terraform Cloud will then translate that JSON data into the web-based version of the diff. Terraform Cloud’s UI is using the same JSON execution plan that the API returns, but interpreted into a “diff-like” shape in a similar way to how Terraform CLI does it when running locally.

1 Like

thank you for the explanation