- Terraform Enterprise
- 2.1.x (latest)
- 2.0.x
- 1.2.x
- 1.1.x
- 1.0.x
- v202507-1
- v202506-1
- v202505-1
- v202504-1
- v202503-1
- v202502-2
- v202502-1
- v202501-1
- v202411-2
- v202411-1
- v202410-1
- v202409-3
- v202409-2
- v202409-1
- v202408-1
- No versions of this document exist before v202408-1. Click below to redirect to the version homepage.
- v202407-1
- v202406-1
- v202405-1
- v202404-2
- v202404-1
- v202402-2
- v202402-1
- v202401-2
- v202401-1
- v202312-1
- v202311-1
- v202310-1
- v202309-1
- v202308-1
- v202307-1
- v202306-1
- v202305-2
- v202305-1
- v202304-1
- v202303-1
- v202302-1
- v202301-2
- v202301-1
- v202212-2
- v202212-1
- v202211-1
- v202210-1
- v202209-2
- v202209-1
- v202208-3
- v202208-2
- v202208-1
- v202207-2
- v202207-1
- v202206-1
Data retention policy API
Data retention policies allow administrators to control storage usage by specifying how long backing data is retained for different resource types.
A data retention policy determines when Terraform Enterprise automatically marks backing data for garbage collection. Backing data refers to the files associated with configuration versions, state versions, and run data. Run data refers to the data and log files associated with plans, apply operations, and assessment operations.
You can set data retention policies per workspace, organization, and Terraform Enterprise installation.
Default policy settings
When the data retention policy is unspecified for a workspace, the workspace inherits the data retention policy defined for the organization. Refer to Data Retention Policies in the workspace settings documentation for additional information.
When the data retention policy is unspecified for an organization, the organization inherits the global data retention policy. Refer to Data Retention Policies in the organization settings documentation for additional information.
Show data retention policy
This endpoint shows the data retention policy set on the target resource.
| Resource | API Endpoint |
|---|---|
| Workspaces | GET /workspaces/:workspace_id/relationships/data-retention-policy |
| Organizations | GET /organizations/:organization_name/relationships/data-retention-policy |
| Site-wide | GET /admin/data-retention-policy-settings |
For more information on the types of data retention policies and the keys returned for each, refer to Data Retention Policy Types.
| Status | Response | Reason |
|---|---|---|
| 200 | JSON API document with type set to "data-retention-policy-delete-olders" or "data-retention-policy-dont-deletes" | Successful request. Refer to Data Retention Policy Types. |
| 404 | JSON API error object | Target resource not found, data retention policy does not exist, or user unauthorized to perform action. |
Request body
No request body.
Sample request
$ curl \
--header "Authorization: Bearer $TOKEN" \
--header "Content-Type: application/vnd.api+json" \
https://<TFE_HOSTNAME>/api/v2/organizations/hashicorp/relationships/data-retention-policy
Sample response
{
"data": {
"id": "drp-Kh74zpKVGNWbpugQ",
"type": "data-retention-policy-delete-olders",
"attributes": {
"delete-older-than-n-days": 60,
"delete-state-versions": true,
"delete-configuration-versions": true,
"delete-run-data-and-logs": false,
"state-versions-delete-after-n-days": 60,
"configuration-versions-delete-after-n-days": 60,
"run-data-and-logs-delete-after-n-days": null,
"state-versions-keep-latest-count": 0,
"configuration-versions-keep-latest-count": 0,
"run-data-keep-latest-count": 0
},
"relationships": {
"target": {
"data": {
"id": "hashicorp",
"type": "organizations"
}
}
}
}
}
Create or update data retention policy
This endpoint creates a data retention policy attached to a target resource or updates the existing policy.
| Resource | API Endpoint |
|---|---|
| Workspaces | POST /workspaces/:workspace_id/relationships/data-retention-policy |
| Organizations | POST /organizations/:organization_name/relationships/data-retention-policy |
| Site-wide | POST /admin/data-retention-policy-settings |
You can also call the endpoint to change the type of the data retention policy. Sending a POST or PATCH request and specifying a different type of policy in the payload automatically creates the new data retention policy for the target resource to replace the existing policy. For more information on the types of data retention policies, refer to Data Retention Policy Types.
| Status | Response | Reason(s) |
|---|---|---|
| 204 | No content | Successfully updated the target resource's data retention policy. |
| 404 | JSON API error object | Target resource not found or user is not authorized to perform action. |
| 422 | JSON API error object | Validation error. Refer to Mixed field validation for details. |
Request body
This POST endpoint requires a JSON object with the following properties as a request payload:
| Key path | Type | Description |
|---|---|---|
data.type | string | A data retention policy type. |
data.attributes | object | The attributes for the specified policy type. |
Sample payload
{
"data": {
"type": "data-retention-policy-delete-olders",
"attributes": {
"deleteStateVersions": true,
"stateVersionsDeleteAfterNDays": 30,
"deleteConfigurationVersions": true,
"configurationVersionsDeleteAfterNDays": 30,
"deleteRunDataAndLogs": true,
"runDataAndLogsDeleteAfterNDays": 14
}
}
}
Sample request
$ curl \
--header "Authorization: Bearer $TOKEN" \
--header "Content-Type: application/vnd.api+json" \
--request POST \
--data @payload.json \
https://<TFE_HOSTNAME>/api/v2/workspaces/ws-UYv6RYM8fVhzeGG5/relationships/data-retention-policy
Sample response
{
"data": {
"id": "drp-Kh74zpKVGNWbpugQ",
"type": "data-retention-policy-delete-olders",
"attributes": {
"delete-older-than-n-days": 30,
"delete-state-versions": true,
"delete-configuration-versions": true,
"delete-run-data-and-logs": true,
"state-versions-delete-after-n-days": 30,
"configuration-versions-delete-after-n-days": 30,
"run-data-and-logs-delete-after-n-days": 14,
"state-versions-keep-latest-count": 0,
"configuration-versions-keep-latest-count": 0,
"run-data-keep-latest-count": 0
},
"relationships": {
"target": {
"data": {
"id": "ws-7aiqKYf6ejMFdtWS",
"type": "workspaces"
}
}
}
}
}
Remove data retention policy
This endpoint removes the data retention policy explicitly set on a target resource.
| Resource | API Endpoint |
|---|---|
| Workspaces | DELETE /workspaces/:workspace_id/relationships/data-retention-policy |
| Organizations | DELETE /organizations/:organization_name/relationships/data-retention-policy |
| Site-wide | DELETE /admin/data-retention-policy-settings |
| Status | Response | Reason(s) |
|---|---|---|
| 204 | No Content | Successfully removed the target resource's data retention policy. |
| 404 | JSON API error object | Target resource not found, or user unauthorized to perform action. |
Request body
No request body.
Sample request
$ curl \
--header "Authorization: Bearer $TOKEN" \
--header "Content-Type: application/vnd.api+json" \
--request DELETE \
https://<TFE_HOSTNAME>/api/v2/organizations/hashicorp/relationships/data-retention-policy
Response
No response body.
Status code 204.
Data retention policy types
You can send a POST or PATCH request to /data-retention-policy and /data-retention-policy-settings endpoints to set the policy or change the existing policy. The schema for each type has a set of attributes specific to the type.
Specify one of the following data retention policy types in the data.type parameter in the request payload:
data-retention-policy-delete-olders: Directs Terraform Enterprise to delete backing data after a configured number of days, with per-artifact-type control. Refer todata-retention-policy-delete-oldersfor additional information.data-retention-policy-dont-deletes: Directs Terraform Enterprise to preserve backing data for the related resource. Refer todata-retention-policy-dont-deletesfor additional information.
To view the existing policy, send a GET request to the endpoint. Endpoints are polymorphic and may return different policy types depending on how Terraform Enterprise has been configured.
data-retention-policy-delete-olders
This policy directs Terraform Enterprise to delete backing data for the configured artifact types after their respective retention windows elapse.
Properties
| Key path | Type | Description |
|---|---|---|
data.type | string | Must be data-retention-policy-delete-olders. |
data.attributes.deleteStateVersions | boolean | Whether to enable deletion of state version backing data. Defaults to false. When true, at least one of stateVersionsDeleteAfterNDays or stateVersionsKeepLatestCount must be set. |
data.attributes.stateVersionsDeleteAfterNDays | integer | Number of days to retain state version backing data. |
data.attributes.stateVersionsKeepLatestCount | integer | Minimum number of most-recent state versions to retain per workspace, regardless of age. |
data.attributes.deleteConfigurationVersions | boolean | Whether to enable deletion of configuration version backing data. Defaults to false. When true, at least one of configurationVersionsDeleteAfterNDays or configurationVersionsKeepLatestCount must be set. |
data.attributes.configurationVersionsDeleteAfterNDays | integer | Number of days to retain configuration version backing data. |
data.attributes.configurationVersionsKeepLatestCount | integer | Minimum number of most-recent configuration versions to retain per workspace, regardless of age. |
data.attributes.deleteRunDataAndLogs | boolean | Whether to enable deletion of run data for plan, apply, and assessment operations, including their logs. Defaults to false. When true, at least one of runDataAndLogsDeleteAfterNDays or runDataKeepLatestCount must be set. |
data.attributes.runDataAndLogsDeleteAfterNDays | integer | Number of days to retain run data and logs. |
data.attributes.runDataKeepLatestCount | integer | Minimum number of most-recent runs to retain per workspace, regardless of age. |
data.attributes.deleteOlderThanNDays | integer | Deprecated. Use artifact specific properties instead. Sets a single retention window applied to all enabled artifact types. For backward compatibility, when creating a policy the value provided will be used for stateVersionsDeleteAfterNDays and configurationVersionsDeleteAfterNDays. On update, the value provided will be used as the new retention window for all enabled artifact types. You cannot combine this property with per-artifact fields in the same request. Refer to Mixed field validation. |
data.relationships.target | object | The resource the policy is attached to. You can specify organization, workspace, or null for the site-wide policy. Cannot be updated directly. |
Mixed field validation
In the same request, providing deleteOlderThanNDays together with any per-artifact field, such as stateVersionsDeleteAfterNDays or deleteRunDataAndLogs, returns a 422 Unprocessable Entity error. Use the per-artifact fields for all new integrations. The deleteOlderThanNDays field is retained only for backwards compatibility with older API clients that do not support the granular fields.
Eligibility guards for run data
Run data backing data for plan, apply, and assessment operations is never eligible for soft deletion if any of the following conditions are true:
- The associated run is in a non-terminal state.
- The run is the most recent run in the workspace.
- The run represents the last successful apply in the workspace.
These guards ensure that active and critical workspace state is never inadvertently removed.
Sample payload
{
"data": {
"type": "data-retention-policy-delete-olders",
"attributes": {
"deleteStateVersions": true,
"stateVersionsDeleteAfterNDays": 60,
"stateVersionsKeepLatestCount": 5,
"deleteConfigurationVersions": true,
"configurationVersionsDeleteAfterNDays": 60,
"deleteRunDataAndLogs": true,
"runDataAndLogsDeleteAfterNDays": 30,
"runDataKeepLatestCount": 10
}
}
}
Sample response body
{
"data": {
"id": "drp-Kh74zpKVGNWbpugQ",
"type": "data-retention-policy-delete-olders",
"attributes": {
"delete-older-than-n-days": 60,
"delete-state-versions": true,
"delete-configuration-versions": true,
"delete-run-data-and-logs": true,
"state-versions-delete-after-n-days": 60,
"configuration-versions-delete-after-n-days": 60,
"run-data-and-logs-delete-after-n-days": 30,
"state-versions-keep-latest-count": 5,
"configuration-versions-keep-latest-count": 0,
"run-data-keep-latest-count": 10
},
"relationships": {
"target": {
"data": {
"id": "ws-7aiqKYf6ejMFdtWS",
"type": "workspaces"
}
}
}
}
}
data-retention-policy-dont-deletes
This policy directs Terraform Enterprise to preserve backing data for the related resource.
Properties
| Key path | Type | Description |
|---|---|---|
data.type | string | Must be data-retention-policy-dont-deletes. |
data.attributes | object | Not applicable. This policy type does not have attributes. |
data.relationships.target | object | The resource the policy is attached to. You can specify organization or workspace. Cannot be updated directly. |
Sample payload
{
"data": {
"type": "data-retention-policy-dont-deletes",
"attributes": {}
}
}
Sample response body
{
"data": {
"id": "drp-Kh74zpKVGNWbpugQ",
"type": "data-retention-policy-dont-deletes",
"attributes": {},
"relationships": {
"target": {
"data": {
"id": "hashicorp",
"type": "organizations"
}
}
}
}
}