Plans API
A plan represents the execution plan of a Run in a Terraform workspace.
Attributes
Plan States
The plan state is found in data.attributes.status
, and you can reference the following list of possible states.
State | Description |
---|---|
pending | The initial status of a plan once it has been created. |
managed_queued /queued | The plan has been queued, awaiting backend service capacity to run terraform. |
running | The plan is running. |
errored | The plan has errored. This is a final state. |
canceled | The plan has been canceled. This is a final state. |
finished | The plan has completed successfully. This is a final state. |
unreachable | The plan will not run. This is a final state. |
Show a plan
GET /plans/:id
Parameter | Description |
---|---|
id | The ID of the plan to show. |
There is no endpoint to list plans. You can find the ID for a plan in the
relationships.plan
property of a run object.
Status | Response | Reason |
---|---|---|
200 | JSON API document (type: "plans" ) | The request was successful |
404 | JSON API error object | Plan not found, or user unauthorized to perform action |
Sample Request
Sample Response
Using HCP Terraform agents
HCP Terraform agents allow HCP Terraform to communicate with isolated, private, or on-premises infrastructure. When a workspace is set to use the agent execution mode, the plan response will include additional details about the agent pool and agent used.
Retrieve the JSON execution plan
GET /plans/:id/json-output
GET /runs/:id/plan/json-output
These endpoints generate a temporary authenticated URL to the location of the JSON formatted execution plan. When successful, this endpoint responds with a temporary redirect that should be followed. If using a client that can follow redirects, you can use this endpoint to save the .json
file locally without needing to save the temporary URL.
This temporary URL provided by the redirect has a life of 1 minute, and should not be relied upon beyond the initial request. If you need repeat access, you should use this endpoint to generate a new URL each time.
Note: This endpoint is available for plans using Terraform 0.12 and later. For Terraform Enterprise, this endpoint is available from v202005-1, and its stability was improved in v202007-1.
Note: This endpoint cannot be accessed with organization tokens. You must access it with a user token or team token that has admin level access to the workspace. (More about permissions.)
Status | Response | Reason |
---|---|---|
204 | No Content | Plan JSON supported, but plan has not yet completed. |
307 | Temporary Redirect | Plan JSON found and temporary download URL generated |
422 | JSON API error object | Plan does not use a supported version of terraform (< 0.12.X) |
Sample Request