Configuration Versions API
Note: Before working with the runs or configuration versions APIs, read the API-driven run workflow page, which includes both a full overview of this workflow and a walkthrough of a simple implementation of it.
A configuration version (configuration-version
) is a resource used to reference the uploaded configuration files. It is associated with the run to use the uploaded configuration files for performing the plan and apply.
You need read runs permission to list and view configuration versions for a workspace, and you need queue plans permission to create new configuration versions. Refer to the permissions documentation for more details.
Attributes
Configuration Version States
The configuration version state is found in data.attributes.status
, and you can reference the following list of possible states.
A configuration version created through the API or CLI can only be used in runs if it is in an uploaded
state. A configuration version created through a linked VCS repository may also be used in runs if it is in an archived
state.
State | Description |
---|---|
pending | The initial status of a configuration version after it has been created. Pending configuration versions cannot be used to create new runs. |
fetching | For configuration versions created from a commit to a connected VCS repository, Terraform Cloud is currently fetching the associated files from VCS. |
uploaded | The configuration version is fully processed and can be used in runs. |
archived | All immediate runs are complete and Terraform Cloud has discarded the files associated with this configuration version. If the configuration version was created through a connected VCS repository, it can still be used in new runs. In those cases, Terraform Cloud will re-fetch the files from VCS. |
errored | Terraform Cloud could not process this configuration version, and it cannot be used to create new runs. You can try again by pushing a new commit to your linked VCS repository or creating a new configuration version with the API or CLI. |
List Configuration Versions
GET /workspaces/:workspace_id/configuration-versions
Parameter | Description |
---|---|
:workspace_id | The ID of the workspace to list configurations from. Obtain this from the workspace settings or the Show Workspace endpoint. |
Query Parameters
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.
Parameter | Description |
---|---|
page[number] | Optional. If omitted, the endpoint will return the first page. |
page[size] | Optional. If omitted, the endpoint will return 20 configuration versions per page. |
Sample Request
Sample Response
Show a Configuration Version
GET /configuration-versions/:configuration-id
Parameter | Description |
---|---|
:configuration-id | The id of the configuration to show. |
Sample Request
Sample Response
Show a Configuration Version's Commit Information
An ingress attributes resource (ingress-attributes
) is used to reference commit information for configuration versions created in a workspace with a VCS repository.
GET /configuration-versions/:configuration-id/ingress-attributes
Parameter | Description |
---|---|
:configuration-id | The id of the configuration to show. |
Ingress attributes can also be fetched as part of a query to a particular configuration version via include
:
GET /configuration-versions/:configuration-id?include=ingress-attributes
Parameter | Description |
---|---|
:configuration-id | The id of the configuration to show. |
Sample Request
Sample Response
Create a Configuration Version
POST /workspaces/:workspace_id/configuration-versions
Parameter | Description |
---|---|
:workspace_id | The ID of the workspace to create the new configuration version in. Obtain this from the workspace settings or the Show Workspace endpoint. |
Note: This endpoint cannot be accessed with organization tokens. You must access it with a user token or team token.
Request Body
This POST endpoint requires a JSON object with the following properties as a request payload.
Properties without a default value are required.
Key path | Type | Default | Description |
---|---|---|---|
data.attributes.auto-queue-runs | boolean | true | When true, runs are queued automatically when the configuration version is uploaded. |
data.attributes.speculative | boolean | false | When true, this configuration version may only be used to create runs which are speculative, that is, can neither be confirmed nor applied. |
Sample Payload
Sample Request
Sample Response
Configuration Files Upload URL
Once a configuration version is created, use the upload-url
attribute to upload configuration files associated with that version. The upload-url
attribute is only provided in the response when creating configuration versions.
Upload Configuration Files
Note: If auto-queue-runs
was either not provided or set to true
during creation of the configuration version, a run using this configuration version will be automatically queued on the workspace. If auto-queue-runs
was set to false
explicitly, then it is necessary to create a run on the workspace manually after the configuration version is uploaded.
PUT https://archivist.terraform.io/v1/object/<UNIQUE OBJECT ID>
The URL is provided in the upload-url
attribute when creating a configuration-versions
resource. After creation, the URL is hidden on the resource and no longer available.
Sample Request
@filename is the name of configuration file you wish to upload.
Archive a Configuration Version
POST /configuration-versions/:configuration_version_id/actions/archive
Parameter | Description |
---|---|
configuration_version_id | The ID of the configuration version to archive. |
This endpoint notifies Terraform Cloud to discard the uploaded .tar.gz
file associated with this configuration version. This endpoint can only archive configuration versions that were created with the API or CLI, are in an uploaded
state, and have no runs in progress. Otherwise, calling this endpoint will result in an error.
Terraform Cloud automatically archives configuration versions created through VCS when associated runs are complete and then re-fetches the files for subsequent runs.
Note: This endpoint is available in Terraform Enterprise v202203-1 or later.
Status | Response | Reason(s) |
---|---|---|
202 | none | Successfully initiated the archive process. |
409 | JSON API error object | Configuration version was in a non-archivable state or the configuration version was created with VCS and cannot be archived through the API. |
404 | JSON API error object | Configuration version was not found or user not authorized. |
Request Body
This POST endpoint does not take a request body.
Sample Request
Download Configuration Files
GET /configuration-versions/:configuration_version_id/download
Parameter | Description |
---|---|
configuration_version_id | The ID of the configuration version to download. |
GET /runs/:run_id/configuration-version/download
Parameter | Description |
---|---|
run_id | The ID of the run whose configuration version should be downloaded. |
These endpoints generate a temporary URL to the location of the configuration version in a .tar.gz
archive, and then redirect to that link. If using a client that can follow redirects, you can use these endpoints to save the .tar.gz
archive locally without needing to save the temporary URL. These endpoints will return an error if attempting to download a configuration version that is not in an uploaded
state.
Note: These endpoints are available in Terraform Enterprise v202203-1 or later.
Status | Response | Reason |
---|---|---|
302 | HTTP Redirect | Configuration version found and temporary download URL generated |
404 | JSON API error object | Configuration version not found, or specified configuration version is not uploaded, or user unauthorized to perform action |
Sample Request
Available Related Resources
The GET endpoints above can optionally return related resources, if requested with the include
query parameter. The following resource types are available:
Resource Name | Description |
---|---|
ingress_attributes | The commit information used in the configuration. |
run | The run created by the configuration. |