Explorer API reference
Explorer allows you to query your HCP Terraform data across workspaces in an organization. You can select from a variety of available views and supply optional sort and filter parameters to present your data in the format that best suits your needs.
Queries are scoped to the organization level. You must have owner permissions in the organization, or read access to workspaces and projects.
Execute a query
GET /organizations/:organization_name/explorer
Parameter | Description |
---|---|
:organization_name | The name of the organization to query. The organization must already exist and you must have permissions to read the organization's workspaces and projects. |
Note: Explorer is restricted to the owners team, teams with the "Read all workspaces" permission, teams with the "Read all projects" permission, and the organization API token.
Explorer queries will time out after 60 seconds. If the desired query is timing out, try a simpler query that uses less filters.
Requests to the explorer are subject to rate limiting. Explorer will return a 429 status code when rate limiting is active for the authenticated context.
Data presented by the explorer is eventually consistent. Query results typically contain data that represents the current state of the system, but in some cases a small delay may be necessary before querying for data that has recently been updated.
Query parameters
This GET endpoint requires a query string that supports the following properties.
Parameter | Description |
---|---|
type | Required. Must be one of the following available views: workspaces , tf_versions , providers , or modules . See the View Types section for more information about each. |
sort | Optionally sort the returned data by the specified field name. The field name must use snake case and exist within the supplied view type. The field name supplied can be prefixed with a hyphen (- ) to perform a descending sort. |
filter | Optionally specify one or more filters to limit the data returned. See Filtering for more information. |
fields | Optionally limit the data returned only to the specified fields. The field names supplied must use snake case and be submitted in comma-separated format. If omitted, all available fields will be returned for the requested view type. |
page[number] | Optional. If omitted, the endpoint will return the first page. |
page[size] | Optional. If omitted, the endpoint will use a default page size. |
View Types
Explorer queries each require a view, specified by the type
query string parameter.
There are several contextual views available for querying:
Type | Description |
---|---|
workspaces | Information about the workspaces in the target organization and any current runs associated with them. Each row returned represents a single workspace. See View Type: workspaces for available fields. |
tf_versions | Information about the Terraform versions in use across this organization. Each row returned represents a Terraform version in use. See View Type: tf_versions for available fields. |
providers | Information about the Terraform providers in use across the target organization. Each row returned represents a Terraform provider in use. See View Type: providers for available fields. |
modules | Information about the Terraform modules in use across the target organization. Each row returned represents a Terraform module in use. See View Type: modules for available fields. |
The fields returned by a given query are specific to the view type used. The fields available for each view type are detailed below:
View Type: workspaces
Field | Type | Description |
---|---|---|
all_checks_succeeded | boolean | True if checks have succeeded for the workspace, false otherwise. |
checks_errored | number | The number of checks that errored without completing. |
checks_failed | number | The number of checks that completed and failed. |
checks_passed | number | The number of checks that completed and passed. |
checks_unknown | number | The number of checks that could not be assessed. |
current_run_applied_at | datetime | Represents the time that this workspace's current run was applied. |
current_run_external_id | string | The external ID of this workspace's current run. |
current_run_status | string | The status of this workspace's current run. |
drifted | boolean | True if drift has been detected for the workspace, false otherwise. |
external_id | string | The external ID of this workspace. |
module_count | number | The number of distinct modules used by this workspace. |
modules | string | A comma separated list of modules used by this workspace. |
organization_name | string | The name of the organization this workspace belongs to. |
project_external_id | string | The external ID of the project this workspace belongs to. |
project_name | string | The name of the project this workspace belongs to. |
provider_count | number | The number of distinct providers used in this workspace. |
providers | string | A comma separated list of providers used in this workspace. |
resources_drifted | number | The count of resources that drift was detected for. |
resources_undrifted | number | The count of resources that drift was not detected for. |
state_version_terraform_version | string | The Terraform version used to create the current run's state file. |
vcs_repo_identifier | string | The name of the repository configured for this workspace, if available. |
workspace_created_at | datetime | The time this workspace was created. |
workspace_name | string | The name of this workspace. |
workspace_terraform_version | string | The Terraform version currently configured for this workspace. |
workspace_updated_at | datetime | The time this workspace was last updated. |
View Type: tf_versions
Field | Type | Description |
---|---|---|
version | string | The semantic version string for this Terraform version. |
workspace_count | number | The number of workspaces using this terraform version. |
workspaces | string | A comma-separated list of workspaces using this terraform version. |
View Type: providers
Field | Type | Description |
---|---|---|
name | string | The name of this provider. |
source | string | The source of this provider. |
version | string | The semantic version string for this provider. |
workspace_count | number | The number of workspaces using this provider. |
workspaces | string | A comma-separated list of workspaces using this provider. |
View Type: modules
Field | Type | Description |
---|---|---|
name | string | The name of this module. |
source | string | The source of this module. |
version | string | The semantic version string for this module. |
workspace_count | number | The number of workspaces using this module version. |
workspaces | string | A comma-separated list of workspaces using this module version. |
Filtering
The explorer can present filtered data from any view type using a variety of operators.
Filter strings begin with the reserved string filter
, and are passed as URL
query string parameters using key-value pairs. The parameter key contains the
filter's target field and operator, and the parameter value contains the filter
value to be used during the query.
Multiple filters can be used in a query by providing multiple filter query
string parameters separated with &
. When multiple filters are used, a logical AND is used
to evaluate the results.
Each filter string must use the following format:
Filter string sub-parameters
- FILTER_INDEX: The index of the filter. Each filter requires a unique
index. The first filter should use a
0
and each additional filter should use an index that is the previous filter's index incremented by 1. - FIELD_NAME: The name of the field to apply the filter to. The field must be a valid field for the view type being queried. See View Types for a list of fields available for each type.
- FIELD_OPERATOR: The operator to use when filtering. Must be supported by the field type being filtered. See Filter Operators for the available operators and their supported field types.
- FIELD_VALUE_INDEX: Must be
0
. This sub-parameter is reserved for future use. - FILTER_VALUE: The filter value used by the filter during the query.
Once the desired filter strings have been added to a request URI, they should be percent-encoded along with the rest of the query string parameters.
Sample Filter Strings
View Type: workspace
Show workspaces that contain test
in their name:
After encoding:
View Type: modules
Show modules that contain aws
in their name and version string equal to 1.1
After encoding:
Filter Operators
Operator | Supported Field Types | Description |
---|---|---|
is | boolean , number , string | Filters data to rows where the field value is equivalent to the filter value. |
is_not | number , string | Filters data to rows where the field value is different from the filter value. |
contains | string | Filters data to rows where the field value contains the filter value as a sub-string. |
does not contain | string | Filters data to rows where the field value does not contain the filter value as a sub-string. |
is_empty | boolean , number , string | Filters data to rows where the field does not contain a value. |
is_not_empty | boolean , number , string | Filters data to rows where the field contains any value. |
gt | number | Filters data to rows where the field value is greater than the filter value. |
lt | number | Filters data to rows where the field value is less than the filter value. |
gteq | number | Filters data to rows where the field value is greater than or equal to the filter value. |
lteq | number | Filters data to rows where the field value is less than or equal to the filter value. |
is_before | datetime | Filters data to rows |
where the field value is earlier than the filter value. ISO 8601 formatted timestamps are required for filter values. If no time zone offset is provided, the filter value will be interpreted as UTC. | ||
is_after | datetime | Filters data to rows |
where the field value is earlier than the filter value. ISO 8601 formatted timestamps are required for filter values. If no time zone offset is provided, the filter value will be interpreted as UTC. |
Pagination
This endpoint supports pagination with standard URL query parameters. Remember to percent-encode [
as %5B
and ]
as %5D
if your tooling doesn't automatically encode URLs.
Sample requests
View Type: workspaces
Show data for all workspaces
Show data for all workspaces with test
in their name
View Type: modules
Show modules used across all workspaces
Show public modules only
View Type: provider
Show providers used across all workspaces
Show most used providers across all workspaces
View Type: tf_versions
Show Terraform versions used across all workspaces
Show all Terraform versions used in more than 10 workspaces
Sample response
Show data for all workspaces
Export data as CSV
GET /organizations/:organization_name/explorer/export/csv
Parameter | Description |
---|---|
:organization_name | The name of the organization to query. The organization must already exist in the system, and the user must have permissions to read the workspaces and projects within it. |
This endpoint can be used to download a full, unpaged export of the query results in CSV format (with the filter, sort, and field selections applied).
Explorer queries will time out after 60 seconds. If the desired query is timing out, try a simpler query that uses less filters.
Requests to the explorer are subject to rate limiting. Explorer will return a 429 status code when rate limiting is active for the authenticated context.
Data presented by the explorer is eventually consistent. Query results typically contain data that represents the current state of the system, but in some cases a small delay may be necessary before querying for data that has recently been updated.
Query parameters
This GET endpoint supports the same query string parameters as the Explorer Query endpoint.
Sample requests
View Type: workspaces
Show data for all workspaces
Sample response
Show data for all workspaces
List saved views
Note: The ability to save views in the explorer is in public beta. All APIs and workflows are subject to change.
Use this endpoint to display all of the explorer's saved views in an organization.
GET /api/v2/organizations/:organization_name/explorer/views
Parameter | Description |
---|---|
:organization_name | The name of the organization to query. To view a query, you must have permission to read the workspaces and projects within that query. |
Sample request
Sample response
Create saved view
Note: The ability to save views in the explorer is in public beta. All APIs and workflows are subject to change.
Use this endpoint to create a saved view in the explorer.
POST /api/v2/organizations/:organization_name/explorer/views
Parameter | Description |
---|---|
:organization_name | The name of the organization to query. To view a query, you must have permission to read the workspaces and projects within that query. |
To create a saved view, provide the following data in your payload.
Key path | Type | Default | Description |
---|---|---|---|
data.name | string | The name of the saved view. | |
data.query_type | string | The primary type that the view is querying. Refer to View Types for details. | |
data.query | object | A list of filters, fields, and sorting rules for the view. Refer to Query parameters for full details. | |
data.query.filter | array[objects] | A list of filters composed of fields, operators, and values. | |
data.query.filter.field | string | The field name to filter by. | |
data.query.filter.operator | string | The operator applied to field and value. | |
data.query.filter.value | array[strings] | A list of values to filter by. | |
data.query.fields | array[strings] | A list of fields to include in the view. | |
data.query.sort | array[strings] | A list of fields to sort by. Prefix with - for descending sort. |
Sample request
Sample response
Show saved view
Use this endpoint to display a specific saved view from the explorer.
GET /api/v2/organizations/:organization_name/explorer/views/:view_id
Parameter | Description |
---|---|
:organization_name | The name of the organization to query. To view a query, you must have permission to read the workspaces and projects within that query. |
:view_id | The ID of the saved view to show. |
Sample request
Sample response
Update a saved view
Use this endpoint to update the data a saved view queries.
PATCH /api/v2/organizations/:organization_name/explorer/views/:view_id
Parameter | Description |
---|---|
:organization_name | The name of the organization to query. To view a query, you must have permission to read the workspaces and projects within that query. |
:view_id | The external id of the saved view to update. |
You must have the following fields in the payload for your request.
Key path | Type | Default | Description |
---|---|---|---|
data.name | string | The name of the saved view. | |
data.query | object | A list of filters, fields, and sorting rules for the view. See Query parameters for full details. | |
data.query.filter | array[objects] | A list of filters composed of fields, operators, and values. See Filtering for more information. | |
data.query.filter.field | string | The field name to filter by. | |
data.query.filter.operator | string | The operator applied to field and value. | |
data.query.filter.value | array[strings] | A list of values to filter by. | |
data.query.fields | array[strings] | A list of fields to include in the view. Refer to execute a query for a list of available parameters. | |
data.query.sort | array[strings] | A list of fields to sort by. Prefix with - for descending sort. |
Sample request
Sample response
Delete a saved view
Use this endpoint to delete a saved view.
DELETE /api/v2/organizations/:organization_name/explorer/views/:view_id
Parameter | Description |
---|---|
:organization_name | The name of the organization to query. To view a query, you must have permission to read the workspaces and projects within that query. |
:view_id | The ID of the saved view you want to delete. |
Sample request
Sample response
Query a saved view
Re-execute a saved view's query to retrieve current results.
GET /api/v2/organizations/:organization_name/explorer/views/:view_id/results
Parameter | Description |
---|---|
:organization_name | The name of the organization to query. To view a query, you must have permission to read the workspaces and projects within that query. |
:view_id | The ID of the saved view to re-query. |
Sample request
Sample response
Query a saved view as CSV
Re-execute a saved view's query to retrieve current results, HCP Terraform returns results as a CSV.
GET /api/v2/organizations/:organization_name/explorer/views/:view_id/csv
Parameter | Description |
---|---|
:organization_name | The name of the organization to query. To view a query, you must have permission to read the workspaces and projects within that query. |
:view_id | The external id of the saved view to query. |
Sample request
Sample response