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, HCP Terraform 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 HCP Terraform 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, HCP Terraform will re-fetch the files from VCS. | |
errored | HCP Terraform 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. | |
backing_data_soft_deleted | Enterprise Indicates that the configuration version's backing data is marked for garbage collection. If no action is taken, the backing data associated with this configuration version is permanently deleted after a set number of days. You can restore the backing data associated with the configuration version before it is permanently deleted. | |
backing_data_permanently_deleted | Enterprise The configuration version's backing data has been permanently deleted and can no longer be restored. |
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. |
data.attributes.provisional | boolean | false | When true, this configuration version does not immediately become the workspace current configuration version. If the associated run is applied, it then becomes the current configuration version unless a newer one exists. |
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 HCP Terraform 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, have no runs in progress, and are not the current configuration version for any workspace. Otherwise, calling this endpoint will result in an error.
HCP Terraform automatically archives configuration versions created through VCS when associated runs are complete and then re-fetches the files for subsequent runs.
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.
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
Mark a Configuration Version for Garbage Collection
This endpoint is exclusive to Terraform Enterprise, and not available in HCP Terraform. Learn more about Terraform Enterprise.
POST /api/v2/configuration-versions/:configuration-id/actions/soft_delete_backing_data
Parameter | Description |
---|---|
:configuration-id | The ID of the configuration version to soft delete. |
This endpoint directs Terraform Enterprise to soft delete the backing files associated with the configuration version. Soft deletion refers to marking the configuration version for garbage collection. Terraform permanently deletes configuration versions marked for soft deletion after a set number of days unless the configuration version is restored. Once a configuration version is soft deleted, any attempts to read the configuration version will fail. Refer to Configuration Version States for information about all data states.
This endpoint can only soft delete configuration versions that meet the following criteria:
- Were created using the API or CLI,
- are in an
uploaded
state, - and are not the current configuration version.
Otherwise, the endpoint returns an error.
Status | Response | Reason(s) |
---|---|---|
200 | none | Terraform successfully marked the data for garbage collection. |
400 | JSON API error object | Terraform failed to transition the state to backing_data_soft_deleted . |
404 | JSON API error object | Terraform did not find the configuration version or the user is not authorized to modify the configuration version state. |
Request Body
This POST endpoint does not take a request body.
Sample Request
Restore Configuration Versions Marked for Garbage Collection
This endpoint is exclusive to Terraform Enterprise, and not available in HCP Terraform. Learn more about Terraform Enterprise.
POST /api/v2/configuration-versions/:configuration-id/actions/restore_backing_data
Parameter | Description |
---|---|
:configuration-id | The ID of the configuration version to restore back to its uploaded state if applicable. |
This endpoint directs Terraform Enterprise to restore backing files associated with this configuration version. This endpoint can only restore delete configuration versions that meet the following criteria:
- are not in a
backing_data_permanently_deleted
state.
Otherwise, the endpoint returns an error. Terraform restores applicable configuration versions back to their uploaded
state.
Status | Response | Reason(s) |
---|---|---|
200 | none | Terraform successfully initiated the restore process. |
400 | JSON API error object | Terraform failed to transition the state to uploaded . |
404 | JSON API error object | Terraform did not find the configuration version or the user is not authorized to modify the configuration version state. |
Request Body
This POST endpoint does not take a request body.
Sample Request
Permanently Delete a Configuration Version
This endpoint is exclusive to Terraform Enterprise, and not available in HCP Terraform. Learn more about Terraform Enterprise.
POST /api/v2/configuration-versions/:configuration-id/actions/permanently_delete_backing_data
Parameter | Description |
---|---|
:configuration-id | The ID of the configuration version to permanently delete. |
This endpoint directs Terraform Enterprise to permanently delete backing files associated with this configuration version. This endpoint can only permanently delete configuration versions that meet the following criteria:
- Were created using the API or CLI,
- are in a
backing_data_soft_deleted
state, - and are not the current configuration version.
Otherwise, the endpoint returns an error.
Status | Response | Reason(s) |
---|---|---|
200 | none | Terraform successfully deleted the data permanently. |
400 | JSON API error object | Terraform failed to transition the state to backing_data_permanently_deleted . |
404 | JSON API error object | Terraform did not find the configuration version or the user is not authorized to modify the configuration version state. |
Request Body
This POST endpoint does not take a request body.
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. |