Outputs are specific values from a Terraform run that are highlighted as a separate part of Terraform run’s log. To extract only the outputs from the log of a Terraform run performed in Terraform Enterprise (TFE), there are two options: set up the Terraform Enterprise backend and use Terraform locally, or use the TFE API to fetch the run log and isolate the outputs.
Using Terraform locally
This option requires setting up the
remote backend, for which we provide a guide. Additional information around connecting Terraform CLI to Terraform Cloud or Terraform Enterprise may be found in the Learn guide titled Authenticate the CLI with Terraform Cloud.
Once the backend is set up, the latest run’s outputs may be retrieved by running the following command.
$ terraform output
One advantage of this method is the ability to supply outputs as JSON. To render outputs as JSON, pass the
-json flag to
terraform output. (More details on the command are available in the Terraform documentation.)
Using the TFE API
If using Terraform locally is not a suitable solution, the outputs can be retrieved via API from the Terraform run log stored in TFE. The most reliable method to get outputs for a specific run on a workspace is using the run ID. The run ID is visible in the Runs list in Terraform Enterprise, or in the link to the run. The apply for the run must have already completed in order to fetch the outputs.
Using the run ID, make the following API call. In these API calls,
$TOKEN represents the user’s Terraform Enterprise user API token, and values prefixed with
: are placeholders that must be replaced with real data.
Private Terraform Enterprise users should replace
app.terraform.io with their own Terraform Enterprise instance URL.
curl \ --header "Authorization: Bearer $TOKEN" \ --header "Content-Type: application/vnd.api+json" \ https://app.terraform.io/api/v2/runs/:run-id/apply
apply has been placed after the ID here, so this call only fetches the run’s apply, not all its data. This limitation works here because the outputs are in the apply log.
The run response contains a key
data.attributes.log-read-url that can be used to load the log content using an HTTP client. To load the load using cURL, make the following call, using the complete log URL:
curl -X GET https://archivist.terraform.io/v1/object/dmF1b..."
The provided read URL is a limited-life unique URL that expires shortly after its creation, so make the call as soon as possible.
The outputs are at the end of the returned log. Using your preferred processing tools, look for
Outputs: and retain the data after that for parsing. Note that the log content includes ANSI color markup, which you may prefer to strip.
Finding the run ID
If you prefer to check the workspace’s runs to determine the desired run ID, issue a query to fetch the workspace’s list of runs:
curl \ --header "Authorization: Bearer $TOKEN" \ --header "Content-Type: application/vnd.api+json" \ https://app.terraform.io/api/v2/workspaces/:workspace-id/runs
This call returns a
data object with an array of runs; the first run in the array is the most recently created run. If that run is complete, then the desired key is
data.id (the ID of the latest run). To combine this step with the apply retrieval, assuming again that the latest run has applied, use:
curl \ --header "Authorization: Bearer $ATLAS_TOKEN" \ --header "Content-Type: application/vnd.api+json" \ https://app.terraform.io/api/v2/workspaces/:workspace-id/runs?include=apply
and look for the key
included.attributes.log-read-url. The reference for available includes for run-related data is available at Terraform Enterprise API - Runs: Available Related Resources. In general, using includes fetches more data, but requires fewer API calls.