Introduction
When making an API call to get the JSON formatted execution plan in HCP Terraform, the JSON output contains all the information of the plan run. This tutorial will guide users on the way to just getting the resource changes from the JSON formatted outputs.
Expected Outcome
To show only the resource changes from JSON formatted execution plan.
Procedure
-
Retrieving the plan ID by making the API call as below,
curl \
A sample output will be like this,
--silent \
--header "Authorization: Bearer $TOKEN" \
--header "Content-Type: application/vnd.api+json" \
--location \
https://app.terraform.io/api/v2/runs/run-hWpJYg54Rc57V4cw | \
jq '.data.relationships.plan.data.id'
"plan-o8NeGBUGRm7Rj3sg"
- Filter the JSON formatted execution plan output from the plan ID (plan-o8NeGBUGRm7Rj3sg) to show only the resource changes,
curl \
A sample output will look like this,
--silent \
--header "Authorization: Bearer $TOKEN" \
--header "Content-Type: application/vnd.api+json" \
--location \
https://app.terraform.io/api/v2/plans/plan-o8NeGBUGRm7Rj3sg/json-output | \
jq '.resource_changes'