Movatterモバイル変換


[0]ホーム

URL:


HashiConf 2025Don't miss the live stream of HashiConf Day 2 happening now View live stream

You are viewing documentation for version v202503-1.View latest version.

This topic provides reference information about the workspaces AP. Workspaces represent running infrastructure managed by Terraform.

Overview

The scope of the API includes the following endpoints:

MethodPathAction
POST/organizations/:organization_name/workspacesCall this endpoint tocreate a workspace.
POST/organizations/:organization_name/workspaces/:name/actions/safe-deleteCall this endpoint tosafely delete a workspace by querying the organization and workspace names.
POST/workspaces/:workspace_id/actions/safe-deleteCall this endpointsafely delete a workspace by querying the workspace ID.
POST/workspaces/:workspace_id/actions/lockCall this endpoint tolock a workspace.
POST/workspaces/:workspace_id/actions/unlockCall this endpoint tounlock a workspace.
POST/workspaces/:workspace_id/actions/force-unlockCall this endpoint toforce a workspace to unlock.
POST/workspaces/:workspace_id/relationships/remote-state-consumersCall this endpoint toadd remote state consumers.
POST/workspaces/:workspace_id/relationships/tagsCall this endpoint tobind flat string tags to an existing workspace.
POST/workspaces/:workspace_id/relationships/data-retention-policyCall this endpoint toshow the workspace data retention policy.
GET/organizations/:organization_name/workspacesCall this endpoint tolist existing workspaces.
GET/organizations/:organization_name/workspaces/:nameCall this endpoint toshow workspace details by querying the organization and workspace names.
GET/workspaces/:workspace_idCall this endpoint toshow workspace details.
GET/workspaces/:workspace_id/relationships/remote-state-consumersCall this endpoint tolist remote state consumers.
GET/workspaces/:workspace_id/relationships/tagsCall this endpoint tolist flat string workspace tags.
GET/workspaces/:workspace_id/relationships/data-retention-policyCall this endpoint toshow the workspace data retention policy.
PATCH/workspaces/:workspace_id/relationships/ssh-keyCall this endpoint to manage SSH key assignments for workspaces. Refer toAssign an SSH key to a workspace andUnassign an SSH key from a workspace for instructions.
PATCH/workspaces/:workspace_idCall this endpoint toupdate a workspace.
PATCH/organizations/:organization_name/workspaces/:nameCall this endpoint toupdate a workspace by querying the organization and workspace names.
PATCH/workspaces/:workspace_id/relationships/remote-state-consumersCall this endpoint toreplace remote state consumers.
DELETE/workspaces/:workspace_id/relationships/remote-state-consumersCall this endpoint todelete remote state consumers.
DELETE/workspaces/:workspace_id/relationships/tagsCall this endpoint todelete flat string workspace tags from the workspace.
DELETE/workspaces/:workspace_id/relationships/data-retention-policyCall this endpoint toremove a workspace data retention policy.
DELETE/workspaces/:workspace_idCall this endpoint toforce delete a workspace, which deletes the workspace without first checking for managed resources.
DELETE/organizations/:organization_name/workspaces/:nameCall this endpoint toforce delete a workspace, which deletes the workspace without first checking for managed resources, by querying the organization and workspace names.

Requirements

  • You must be a member of a team with theRead permission enabled for Terraform runs to view workspaces.
  • You must be a member of a team with theAdmin permissions enabled on the workspace to change settings and force-unlock it.
  • You must be a member of a team with theLock/unlock permission enabled to lock and unlock the workspace.
  • You must meet one of the following requirements to create a workspace:
    • Be the team owner
    • Be on a team with theManage all workspaces permission enabled
    • Present anorganization API token when calling the API.

Refer toWorkspace Permissions for additional information.

Create a Workspace

Use the following endpoint to create a new workspace:

POST /organizations/:organization_name/workspaces

ParameterDescription
:organization_nameThe name of the organization to create the workspace in. The organization must already exist in the system, and the user must have permissions to create new workspaces.

Request Body

This POST endpoint requires a JSON object with the following properties as a request payload.

Properties without a default value are required.

By supplying the necessary attributes under avcs-repository object, you can create a workspace that is configured against a VCS Repository.

Key pathTypeDefaultDescription
data.typestringnoneMust be"workspaces".
data.attributes.namestringnoneThe name of the workspace. Workspace names can only include letters, numbers,-, and_. The name a unique identifier n the organization.
data.attributes.agent-pool-idstringnoneRequired whenexecution-mode is set toagent. The ID of the agent pool belonging to the workspace's organization. This value must not be specified ifexecution-mode is set toremote orlocal or ifoperations is set totrue.
data.attributes.allow-destroy-planbooleantrueWhether destroy plans can be queued on the workspace.
data.attributes.assessments-enabledbooleanfalse(previouslydrift-detection) Whether or not HCP Terraform performs health assessments for the workspace. May be overridden by the organization settingassessments-enforced. Only available for Plus tier organizations, in workspaces running Terraform version 0.15.4+ and operating inRemote execution mode.
data.attributes.auto-applybooleanfalseWhether to automatically apply changes when a Terraform plan is successful in runs initiated by VCS, UI or CLI,with some exceptions.
data.attributes.auto-apply-run-triggerbooleanfalseWhether to automatically apply changes when a Terraform plan is successful in runs initiated by run triggers.
data.attributes.auto-destroy-atstring(nothing)Timestamp when the next scheduled destroy run will occur, refer toScheduled Destroy.
data.attributes.auto-destroy-activity-durationstring(nothing)Value and units forautomatically scheduled destroy runs based on workspace activity. Valid values are greater than 0 and four digits or less. Valid units ared andh. For example, to queue destroy runs after fourteen days of inactivity setauto-destroy-activity-duration: "14d".
data.attributes.descriptionstring(nothing)A description for the workspace.
data.attributes.execution-modestring(nothing)Whichexecution mode to use. Valid values areremote,local, andagent. When set tolocal, the workspace will be used for state storage only. This valuemust not be specified ifoperations is specified, andmust be specified ifsetting-overwrites.execution-mode is set totrue.
data.attributes.file-triggers-enabledbooleantrueWhether to filter runs based on the changed files in a VCS push. If enabled, it uses eithertrigger-prefixes in conjunction withworking_directory ortrigger-patterns to describe the set of changed files that will start a run. If disabled, any push triggers a run.
data.attributes.global-remote-statebooleanfalseWhether the workspace should allow all workspaces in the organization toaccess its state data during runs. Iffalse, then only specifically approved workspaces can access its state. Manage allowed workspaces using theRemote State Consumers endpoints, documented later on this page. Terraform Enterprise admins can choose the default value for new workspaces if this attribute is omitted.
data.attributes.operationsbooleantrueDEPRECATED Useexecution-mode instead. Whether to use remote execution mode. When set tofalse, the workspace will be used for state storage only. This value must not be specified ifexecution-mode is specified.
data.attributes.queue-all-runsbooleanfalseWhether runs should be queued immediately after workspace creation. When set to false, runs triggered by a VCS change will not be queued until at least one run is manually queued.
data.attributes.source-namestringnoneA friendly name for the application or client creating this workspace. If set, this will be displayed on the workspace as "Created via<SOURCE NAME>".
data.attributes.source-urlstringnoneA URL for the application or client creating this workspace. This can be the URL of a related resource in another app, or a link to documentation or other info about the client.
data.attributes.speculative-enabledbooleantrueWhether this workspace allows automaticspeculative plans. Setting this tofalse prevents HCP Terraform from running plans on pull requests, which can improve security if the VCS repository is public or includes untrusted contributors. It doesn't prevent manual speculative plans via the CLI or the runs API.
data.attributes.terraform-versionstringlatest releaseSpecifies the version of Terraform to use for this workspace. You can specify an exact version or aversion constraint such as~> 1.0.0. If you specify a constraint, the workspace always uses the newest release that meets that constraint. If omitted when creating a workspace, this defaults to the latest released version.
data.attributes.trigger-patternsarray[]List of glob patterns that describe the files HCP Terraform monitors for changes. Trigger patterns are always appended to the root directory of the repository.
data.attributes.trigger-prefixesarray[]List of trigger prefixes that describe the paths HCP Terraform monitors for changes, in addition to the working directory. Trigger prefixes are always appended to the root directory of the repository. HCP Terraform starts a run when files are changed in any directory path matching the provided set of prefixes.
data.attributes.vcs-repo.branchstringrepository's default branchThe repository branch that Terraform executes from. If omitted or submitted as an empty string, this defaults to the repository's default branch.
data.attributes.vcs-repo.identifierstringnoneA reference to your VCS repository in the format :org/:repo where :org and :repo refer to the organization and repository in your VCS provider. The format for Azure DevOps is:org/:project/_git/:repo.
data.attributes.vcs-repo.ingress-submodulesbooleanfalseWhether submodules should be fetched when cloning the VCS repository.
data.attributes.vcs-repo.oauth-token-idstringnoneSpecifies the VCS OAuth connection and token. Call theoauth-tokens endpoint to retrieve the OAuth ID.
data.attributes.vcs-repo.tags-regexstringnoneA regular expression used to match Git tags. HCP Terraform triggers a run when this value is present and a VCS event occurs that contains a matching Git tag for the regular expression.
data.attributes.vcs-repoobjectnoneSettings for the workspace's VCS repository. If omitted, the workspace is created without a VCS repo. If included, you must specify at least theoauth-token-id andidentifier keys.
data.attributes.working-directorystring(nothing)A relative path that Terraform will execute within. This defaults to the root of your repository and is typically set to a subdirectory matching the environment when multiple environments exist within the same repository.
data.attributes.setting-overwritesobjectnoneThe keys in this object are attributes that have organization-level defaults. Each attribute key stores a boolean value which istrue by default. To overwrite the default inherited value, set an attribute's value tofalse. For example, to setexecution-mode as the organization default, setsetting-overwrites.execution-mode tofalse.
data.relationshipsobjectnoneSpecifies a group of workspace associations.
data.relationships.project.data.idstringdefault projectThe ID of the project to create the workspace in. If left blank, Terraform creates the workspace in the organization's default project. You must have permission to create workspaces in the project, either by organization-level permissions or team admin access to a specific project.

Sample Payload

Without a VCS repository

{  "data": {    "attributes": {      "name": "workspace-1"    },    "type": "workspaces"  }}

With a VCS repository

{  "data": {    "attributes": {      "name": "workspace-2",      "terraform_version": "0.11.1",      "working-directory": "",      "vcs-repo": {        "identifier": "example/terraform-test-proj",        "oauth-token-id": "ot-hmAyP66qk2AMVdbJ",        "branch": "",        "tags-regex": null      }    },    "type": "workspaces"  }}

Using Git Tags

HCP Terraform triggers a run when you push a Git tag that matches the regular expression (SemVer):1.2.3,22.33.44, etc.

{  "data": {    "attributes": {      "name": "workspace-3",      "terraform_version": "0.12.1",      "file-triggers-enabled": false,      "working-directory": "/networking",      "vcs-repo": {        "identifier": "example/terraform-test-proj-monorepo",        "oauth-token-id": "ot-hmAyP66qk2AMVdbJ",        "branch": "",        "tags-regex": "\d+.\d+.\d+"      }    },    "type": "workspaces"  }}

For a monorepo using trigger prefixes

A run will be triggered in this workspace when changes are detected in any of the specified directories:/networking,/modules, or/vendor.

{  "data": {    "attributes": {      "name": "workspace-3",      "terraform_version": "0.12.1",      "file-triggers-enabled": true,      "trigger-prefixes": ["/modules", "/vendor"],      "working-directory": "/networking",      "vcs-repo": {        "identifier": "example/terraform-test-proj-monorepo",        "oauth-token-id": "ot-hmAyP66qk2AMVdbJ",        "branch": ""      },      "updated-at": "2017-11-29T19:18:09.976Z"    },    "type": "workspaces"  }}

For a monorepo using trigger patterns

A run will be triggered in this workspace when HCP Terraform detects any of the following changes:

  • A file with the extensiontf in any directory structure in which the last folder is namednetworking (e.g.,root/networking androot/module/networking)
  • Any file changed in the folder/base, no subfolders are included
  • Any file changed in the folder/submodule and all of its subfolders
{  "data": {    "attributes": {      "name": "workspace-4",      "terraform_version": "1.2.2",      "file-triggers-enabled": true,      "trigger-patterns": ["/**/networking/*.tf", "/base/*", "/submodule/**/*"],      "vcs-repo": {        "identifier": "example/terraform-test-proj-monorepo",        "oauth-token-id": "ot-hmAyP66qk2AMVdbJ",        "branch": ""      },      "updated-at": "2022-06-09T19:18:09.976Z"    },    "type": "workspaces"  }}

Using HCP Terraform agents

HCP Terraform agents allow HCP Terraform to communicate with isolated, private, or on-premises infrastructure.

{  "data": {    "attributes": {      "name":"workspace-1",      "execution-mode": "agent",      "agent-pool-id": "apool-ZjT6A7mVFm5WHT5a"    }  },  "type": "workspaces"}

Using an organization default execution mode

{  "data": {    "attributes": {      "name":"workspace-with-default",      "setting-overwrites": {        "execution-mode": false      }    }  },  "type": "workspaces"}

With a project

{  "data": {    "type": "workspaces",    "attributes": {      "name": "workspace-in-project"    },    "relationships": {      "project": {        "data": {          "type": "projects",          "id": "prj-jT92VLSFpv8FwKtc"        }      }    }  }}

Sample Request

$ curl \  --header "Authorization: Bearer $TOKEN" \  --header "Content-Type: application/vnd.api+json" \  --request POST \  --data @payload.json \  https://app.terraform.io/api/v2/organizations/my-organization/workspaces

Sample Response

Without a VCS repository

Note: Theassessments-enabled property is only accepted by or returned from HCP Terraform.

{  "data": {    "id": "ws-6jrRyVDv1J8zQMB5",    "type": "workspaces",    "attributes": {      "actions": {        "is-destroyable": true      },      "allow-destroy-plan": true,      "assessments-enabled": false,      "auto-apply": false,      "auto-apply-run-trigger": false,      "auto-destroy-at": null,      "auto-destroy-status": null,      "auto-destroy-activity-duration": null,      "inherits-project-auto-destroy": null,      "created-at": "2021-08-16T21:22:49.566Z",      "description": null,      "environment": "default",      "execution-mode": "agent",      "file-triggers-enabled": true,      "global-remote-state": false,      "latest-change-at": "2021-08-16T21:22:49.566Z",      "last-assessment-result-at" : "2021-08-17T21:20:12.908Z",      "locked": true,      "locked-reason": null,      "name": "workspace-1",      "oauth-client-name": null,      "operations": true,      "permissions": {        "can-update": true,        "can-destroy": true,        "can-queue-run": true,        "can-read-run": true,        "can-read-variable": true,        "can-update-variable": true,        "can-read-state-versions": true,        "can-read-state-outputs": true,        "can-create-state-versions": true,        "can-queue-apply": true,        "can-lock": true,        "can-unlock": true,        "can-force-unlock": true,        "can-read-settings": true,        "can-manage-tags": true,        "can-manage-run-tasks": true,        "can-force-delete": true,        "can-manage-assessments": true,        "can-manage-ephemeral-workspaces": false,        "can-read-assessment-results": true,        "can-queue-destroy": true      },      "apply-duration-average": 35000,      "plan-duration-average": 53000,      "policy-check-failures": null,      "queue-all-runs": false,      "resource-count": 10,      "run-failures": 3,      "source": "tfe-api",      "source-name": null,      "source-url": null,      "speculative-enabled": true,      "structured-run-output-enabled": true,      "tag-names": [],      "terraform-version": "1.9.4",      "trigger-prefixes": [],      "updated-at": "2021-08-16T21:22:49.566Z",      "vcs-repo": null,      "vcs-repo-identifier": null,      "working-directory": null,      "workspace-kpis-runs-count": 8,      "setting-overwrites": {        "execution-mode": true,        "agent-pool": true      }    },    "links": {      "self": "/api/v2/organizations/my-organization/workspaces/workspace-1",      "self-html": "/app/my-organization/workspaces/workspace-1"    },    "relationships": {      "agent-pool": {        "data": {          "id": "apool-QxGd2tRjympfMvQc",          "type": "agent-pools"        }      },      "current-configuration-version": {        "data": null      },      "current-run": {        "data": {          "id": "run-hjy7ndEkmCtn31ps",          "type": "runs"        },        "links": {          "related": "/api/v2/runs/run-hjy7ndEkmCtn31ps"        }      },      "latest-run": {// Deprecated; same as current-run        "data": {          "id": "run-hjy7ndEkmCtn31ps",          "type": "runs"        },        "links": {          "related": "/api/v2/runs/run-hjy7ndEkmCtn31ps"        }      },      "current-state-version": {        "data": {          "id": "sv-hjy7ndEkmCtn31ps",          "type": "state-versions"        },        "links": {          "related": "/api/v2/workspaces/ws-6jrRyVDv1J8zQMB5/current-state-version"        }      },      "current-configuration-version": {        "data": {          "id": "cv-hjy7ndEkmCtn31ps",          "type": "configuration-versions"        },        "links": {          "related": "/api/v2/configuration-versions/cv-hjy7ndEkmCtn31ps"        }      },      "current-assessment-result": {        "data": null      },      "organization": {        "data": {          "id": "my-organization",          "type": "organizations"        }      },      "outputs": {        "data": [          {            "id": "wsout-hjy7ndEkmCtn31ps",            "type": "workspace-outputs"          },          {            "id": "wsout-hjy7ndEkmCtn31ps",            "type": "workspace-outputs"          }        ],        "links": {          "related": "/api/v2/workspaces/ws-6jrRyVDv1J8zQMB5/current-state-version-outputs"        }      },      "project": {        "data": {          "id": "prj-hjy7ndEkmCtn31ps",          "type": "projects"        }      },      "readme": {        "data": null      },      "remote-state-consumers": {        "links": {          "related": "/api/v2/workspaces/ws-6jrRyVDv1J8zQMB5/relationships/remote-state-consumers"        }      },      "ssh-key": {        "data": {          "id": "sshkey-hjy7ndEkmCtn31ps",          "type": "ssh-keys"        },        "links": {          "related": "/api/v2/ssh-keys/sshkey-hjy7ndEkmCtn31ps"        }      },      "locked-by": {        "data": {          "id": "user-hjy7ndEkmCtn31ps",          "type": "users"        },        "links": {          "related": "/api/v2/users/user-hjy7ndEkmCtn31ps"        }      },      "vars": {        "data": [          {            "id": "var-hjy7ndEkmCtn31ps",            "type": "vars"          }        ]      },    }  }}

With a VCS repository

{  "data": {    "id": "ws-KTuq99JSzgmDSvYj",    "type": "workspaces",    "attributes": {      "actions": {        "is-destroyable": true      },      "allow-destroy-plan": true,      "apply-duration-average": null,      "assessments-enabled": false,      "auto-apply": false,      "auto-apply-run-trigger": false,      "auto-destroy-at": null,      "auto-destroy-activity-duration": null,      "created-at": "2021-08-16T21:50:58.726Z",      "description": null,      "environment": "default",      "execution-mode": "remote",      "file-triggers-enabled": true,      "global-remote-state": false,      "latest-change-at": "2021-08-16T21:50:58.726Z",      "locked": false,      "locked-reason": "",      "name": "workspace-2",      "oauth-client-name": "github example",      "operations": true,      "permissions": {        "can-update": true,        "can-destroy": true,        "can-queue-run": true,        "can-read-run": true,        "can-read-variable": true,        "can-update-variable": true,        "can-read-state-versions": true,        "can-read-state-outputs": true,        "can-create-state-versions": true,        "can-queue-apply": true,        "can-lock": true,        "can-unlock": true,        "can-force-unlock": true,        "can-read-settings": true,        "can-manage-tags": true,        "can-manage-run-tasks": true,        "can-force-delete": true,        "can-manage-assessments": true,        "can-manage-ephemeral-workspaces": false,        "can-read-assessment-results": true,        "can-queue-destroy": true      },      "apply-duration-average": 35000,      "plan-duration-average": 53000,      "policy-check-failures": null,      "queue-all-runs": false,      "resource-count": 10,      "run-failures": 3,      "source": "tfe-api",      "source-name": null,      "source-url": null,      "speculative-enabled": true,      "structured-run-output-enabled": true,      "tag-names": [],      "terraform-version": "1.9.4",      "trigger-prefixes": [],      "vcs-repo": {        "branch": "",        "display-identifier": "example/terraform-test-proj",        "identifier": "example/terraform-test-proj",        "ingress-submodules": false,        "oauth-token-id": "ot-hmAyP66qk2AMVdbJ",        "repository-http-url": "https://github.com/example/terraform-test-proj",        "service-provider": "github",        "tags-regex": null,        "webhook-url": "https://app.terraform.io/webhooks/vcs/704ac743-df64-4b8e-b9a3-a4c5fe1bec87"      },      "vcs-repo-identifier": "example/terraform-test-proj",      "working-directory": "",      "workspace-kpis-runs-count": null,      "setting-overwrites": {        "execution-mode": true,        "agent-pool": true      }    },    "links": {      "self": "/api/v2/organizations/my-organization/workspaces/workspace-2",      "self-html": "/app/my-organization/workspaces/workspace-2"    },    "relationships": {      "relationships": {      "agent-pool": {        "data": null      },      "current-configuration-version": {        "data": null      },      "current-run": {        "data": {          "id": "run-hjy7ndEkmCtn31ps",          "type": "runs"        },        "links": {          "related": "/api/v2/runs/run-hjy7ndEkmCtn31ps"        }      },      "latest-run": {// Deprecated; same as current-run        "data": {          "id": "run-hjy7ndEkmCtn31ps",          "type": "runs"        },        "links": {          "related": "/api/v2/runs/run-hjy7ndEkmCtn31ps"        }      },      "current-state-version": {        "data": {          "id": "sv-hjy7ndEkmCtn31ps",          "type": "state-versions"        },        "links": {          "related": "/api/v2/workspaces/ws-6jrRyVDv1J8zQMB5/current-state-version"        }      },      "current-configuration-version": {        "data": {          "id": "cv-hjy7ndEkmCtn31ps",          "type": "configuration-versions"        },        "links": {          "related": "/api/v2/configuration-versions/cv-hjy7ndEkmCtn31ps"        }      },      "current-assessment-result": {        "data": null      },      "organization": {        "data": {          "id": "my-organization",          "type": "organizations"        }      },      "outputs": {        "data": [          {            "id": "wsout-hjy7ndEkmCtn31ps",            "type": "workspace-outputs"          }        ],        "links": {          "related": "/api/v2/workspaces/ws-6jrRyVDv1J8zQMB5/current-state-version-outputs"        }      },      "project": {        "data": {          "id": "prj-hjy7ndEkmCtn31ps",          "type": "projects"        }      },      "readme": {        "data": null      },      "remote-state-consumers": {        "links": {          "related": "/api/v2/workspaces/ws-6jrRyVDv1J8zQMB5/relationships/remote-state-consumers"        }      },      "ssh-key": {        "data": {          "id": "sshkey-hjy7ndEkmCtn31ps",          "type": "ssh-keys"        },        "links": {          "related": "/api/v2/ssh-keys/sshkey-hjy7ndEkmCtn31ps"        }      },      "locked-by": {        "data": {          "id": "user-hjy7ndEkmCtn31ps",          "type": "users"        },        "links": {          "related": "/api/v2/users/user-hjy7ndEkmCtn31ps"        }      },      "vars": {        "data": [          {            "id": "var-hjy7ndEkmCtn31ps",            "type": "vars"          }        ]      },    }  }}

With a project

{  "data": {    "id": "ws-HRkJLSYWF97jucqQ",    "type": "workspaces",    "attributes": {      "allow-destroy-plan": true,      "auto-apply": false,      "auto-apply-run-trigger": false,      "auto-destroy-at": null,      "auto-destroy-activity-duration": null,      "created-at": "2022-12-05T20:57:13.829Z",      "environment": "default",      "locked": false,      "locked-reason": "",      "name": "workspace-in-project",      "queue-all-runs": false,      "speculative-enabled": true,      "structured-run-output-enabled": true,      "terraform-version": "1.3.5",      "working-directory": null,      "global-remote-state": true,      "updated-at": "2022-12-05T20:57:13.829Z",      "resource-count": 0,      "apply-duration-average": null,      "plan-duration-average": null,      "policy-check-failures": null,      "run-failures": null,      "workspace-kpis-runs-count": null,      "latest-change-at": "2022-12-05T20:57:13.829Z",      "operations": true,      "execution-mode": "remote",      "vcs-repo": null,      "vcs-repo-identifier": null,      "permissions": {        "can-update": true,        "can-destroy": true,        "can-queue-run": true,        "can-read-variable": true,        "can-update-variable": true,        "can-read-state-versions": true,        "can-read-state-outputs": true,        "can-create-state-versions": true,        "can-queue-apply": true,        "can-lock": true,        "can-unlock": true,        "can-force-unlock": true,        "can-read-settings": true,        "can-manage-tags": true,        "can-manage-run-tasks": false,        "can-force-delete": true,        "can-manage-assessments": true,        "can-read-assessment-results": true,        "can-queue-destroy": true      },      "actions": {        "is-destroyable": true      },      "description": null,      "file-triggers-enabled": true,      "trigger-prefixes": [],      "trigger-patterns": [],      "assessments-enabled": false,      "last-assessment-result-at": null,      "source": "tfe-api",      "source-name": null,      "source-url": null,      "tag-names": [],      "setting-overwrites": {        "execution-mode": false,        "agent-pool": false      }    },    "relationships": {      "organization": {        "data": {          "id": "my-organization",          "type": "organizations"        }      },      "current-run": {        "data": null      },      "latest-run": {        "data": null      },      "outputs": {        "data": []      },      "remote-state-consumers": {        "links": {          "related": "/api/v2/workspaces/ws-HRkJLSYWF97jucqQ/relationships/remote-state-consumers"        }      },      "current-state-version": {        "data": null      },      "current-configuration-version": {        "data": null      },      "agent-pool": {        "data": null      },      "readme": {        "data": null      },      "project": {        "data": {          "id": "prj-jT92VLSFpv8FwKtc",          "type": "projects"        }      },      "current-assessment-result": {        "data": null      },      "vars": {        "data": []      },    },    "links": {      "self": "/api/v2/organizations/my-organization/workspaces/workspace-in-project"    }  }}

Update a Workspace

Use one of the following endpoint to update a workspace:

ParameterDescription
:workspace_idThe ID of the workspace to update
:organization_nameThe name of the organization the workspace belongs to.
:nameThe name of the workspace to update. Workspace names are unique identifiers in the organization and can only include letters, numbers,-, and_.

Request Body

These PATCH endpoints require a JSON object with the following properties as a request payload.

Properties without a default value are required.

Key pathTypeDefaultDescription
data.typestringMust be"workspaces".
data.attributes.namestring(previous value)A new name for the workspace, which can only include letters, numbers,-, and_. This will be used as an identifier and must be unique in the organization.Warning: Changing a workspace's name changes its URL in the API and UI.
data.attributes.agent-pool-idstring(previous value)Required whenexecution-mode is set toagent. The ID of the agent pool belonging to the workspace's organization. This value must not be specified ifexecution-mode is set toremote orlocal or ifoperations is set totrue.
data.attributes.allow-destroy-planboolean(previous value)Whether destroy plans can be queued on the workspace.
data.attributes.assessments-enabledbooleanfalse(previouslydrift-detection) Whether or not HCP Terraform performs health assessments for the workspace. May be overridden by the organization settingassessments-enforced. Only available for Plus tier organizations, in workspaces running Terraform version 0.15.4+ and operating inRemote execution mode.
data.attributes.auto-applyboolean(previous value)Whether to automatically apply changes when a Terraform plan is successful in runs initiated by VCS, UI or CLI,with some exceptions.
data.attributes.auto-apply-run-triggerboolean(previous value)Whether to automatically apply changes when a Terraform plan is successful in runs initiated by run triggers.
data.attributes.auto-destroy-atstring(previous value)Timestamp when the next scheduled destroy run will occur, refer toScheduled Destroy.
data.attributes.auto-destroy-activity-durationstring(previous value)Value and units forautomatically scheduled destroy runs based on workspace activity. Valid values are greater than 0 and four digits or less. Valid units ared andh. For example, to queue destroy runs after fourteen days of inactivity setauto-destroy-activity-duration: "14d".
data.attributes.descriptionstring(previous value)A description for the workspace.
data.attributes.execution-modestring(previous value)Whichexecution mode to use. Valid values areremote,local, andagent. When set tolocal, the workspace will be used for state storage only. This valuemust not be specified ifoperations is specified, andmust be specified ifsetting-overwrites.execution-mode is set totrue.
data.attributes.file-triggers-enabledboolean(previous value)Whether to filter runs based on the changed files in a VCS push. If enabled, it uses eithertrigger-prefixes in conjunction withworking_directory ortrigger-patterns to describe the set of changed files that will start a run. If disabled, any push will trigger a run.
data.attributes.global-remote-stateboolean(previous value)Whether the workspace should allow all workspaces in the organization toaccess its state data during runs. Iffalse, then only specifically approved workspaces can access its state. Manage allowed workspaces using theRemote State Consumers endpoints, documented later on this page.
data.attributes.operationsboolean(previous value)DEPRECATED Useexecution-mode instead. Whether to use remote execution mode. When set tofalse, the workspace will be used for state storage only. This value must not be specified ifexecution-mode is specified.
data.attributes.queue-all-runsboolean(previous value)Whether runs should be queued immediately after workspace creation. When set to false, runs triggered by a VCS change will not be queued until at least one run is manually queued.
data.attributes.speculative-enabledboolean(previous value)Whether this workspace allows automaticspeculative plans. Setting this tofalse prevents HCP Terraform from running plans on pull requests, which can improve security if the VCS repository is public or includes untrusted contributors. It doesn't prevent manual speculative plans via the CLI or the runs API.
data.attributes.terraform-versionstring(previous value)The version of Terraform to use for this workspace. This can be either an exact version or aversion constraint (like~> 1.0.0); if you specify a constraint, the workspace will always use the newest release that meets that constraint.
data.attributes.trigger-patternsarray(previous value)List of glob patterns that describe the files HCP Terraform monitors for changes. Trigger patterns are always appended to the root directory of the repository.
data.attributes.trigger-prefixesarray(previous value)List of trigger prefixes that describe the paths HCP Terraform monitors for changes, in addition to the working directory. Trigger prefixes are always appended to the root directory of the repository. HCP Terraform will start a run when files are changed in any directory path matching the provided set of prefixes.
data.attributes.vcs-repo.branchstring(previous value)The repository branch that Terraform will execute from.
data.attributes.vcs-repo.identifierstring(previous value)A reference to your VCS repository in the format :org/:repo where :org and :repo refer to the organization and repository in your VCS provider. The format for Azure DevOps is:org/:project/_git/:repo.
data.attributes.vcs-repo.ingress-submodulesboolean(previous value)Whether submodules should be fetched when cloning the VCS repository.
data.attributes.vcs-repo.oauth-token-idstringThe VCS Connection (OAuth Connection + Token) to use as identified. Get this ID from theoauth-tokens endpoint. You can not specify this value ifgithub-app-installation-id is specified.
data.attributes.vcs-repo.github-app-installation-idstringThe VCS Connection GitHub App Installation to use. Find this ID on the account settings page. Requires previously authorizing the GitHub App and generating a user-to-server token. Manage the token fromAccount Settings within HCP Terraform. You can not specify this value ifoauth-token-id is specified.
data.attributes.vcs-repo.tags-regexstring(previous value)A regular expression used to match Git tags. HCP Terraform triggers a run when this value is present and a VCS event occurs that contains a matching Git tag for the regular expression.
data.attributes.vcs-repoobject or null(previous value)To delete a workspace's existing VCS repo, specifynull instead of an object. To modify a workspace's existing VCS repo, include whichever of the keys below you wish to modify. To add a new VCS repo to a workspace that didn't previously have one, include at least theoauth-token-id andidentifier keys.
data.attributes.working-directorystring(previous value)A relative path that Terraform will execute within. This defaults to the root of your repository and is typically set to a subdirectory matching the environment when multiple environments exist within the same repository.
data.attributes.setting-overwritesobjectThe keys in this object are attributes that have organization-level defaults. Each attribute key stores a boolean value which istrue by default. To overwrite the default inherited value, set an attribute's value tofalse. For example, to setexecution-mode as the organization default, you setsetting-overwrites.execution-mode = false.
data.relationshipsobjectnoneSpecifies a group of workspace relationships.
data.relationships.project.data.idstringexisting valueThe ID of the project to move the workspace to. If left blank or unchanged, the workspace will not be moved. You must have admin permissions on both the source project and destination project in order to move a workspace between projects.

Sample Payload

{  "data": {    "attributes": {      "name": "workspace-2",      "resource-count": 0,      "terraform_version": "0.11.1",      "working-directory": "",      "vcs-repo": {        "identifier": "example/terraform-test-proj",        "branch": "",        "ingress-submodules": false,        "oauth-token-id": "ot-hmAyP66qk2AMVdbJ"      },      "updated-at": "2017-11-29T19:18:09.976Z"    },    "relationships": {      "project": {        "data": {          "type": "projects",          "id": "prj-7HWWPGY3fYxztELU"        }    },    "type": "workspaces"  }}

Sample Request

$ curl \  --header "Authorization: Bearer $TOKEN" \  --header "Content-Type: application/vnd.api+json" \  --request PATCH \  --data @payload.json \  https://app.terraform.io/api/v2/organizations/my-organization/workspaces/workspace-2

Sample Response

{  "data": {    "id": "ws-KTuq99JSzgmDSvYj",    "type": "workspaces",    "attributes": {      "actions": {        "is-destroyable": true      },      "allow-destroy-plan": true,      "apply-duration-average": null,      "assessments-enabled": false,      "auto-apply": false,      "auto-apply-run-trigger": false,      "auto-destroy-at": null,      "auto-destroy-activity-duration": null,      "created-at": "2021-08-16T21:50:58.726Z",      "description": null,      "environment": "default",      "execution-mode": "remote",      "file-triggers-enabled": true,      "global-remote-state": false,      "latest-change-at": "2021-08-16T21:50:58.726Z",      "locked": false,      "locked-reason": "",      "name": "workspace-2",      "oauth-client-name": "github example",      "operations": true,      "permissions": {        "can-update": true,        "can-destroy": true,        "can-queue-run": true,        "can-read-run": true,        "can-read-variable": true,        "can-update-variable": true,        "can-read-state-versions": true,        "can-read-state-outputs": true,        "can-create-state-versions": true,        "can-queue-apply": true,        "can-lock": true,        "can-unlock": true,        "can-force-unlock": true,        "can-read-settings": true,        "can-manage-tags": true,        "can-manage-run-tasks": true,        "can-force-delete": true,        "can-manage-assessments": true,        "can-manage-ephemeral-workspaces": false,        "can-read-assessment-results": true,        "can-queue-destroy": true      },      "apply-duration-average": 35000,      "plan-duration-average": 53000,      "policy-check-failures": null,      "queue-all-runs": false,      "resource-count": 10,      "run-failures": 3,      "source": "tfe-api",      "source-name": null,      "source-url": null,      "speculative-enabled": true,      "structured-run-output-enabled": true,      "tag-names": [],      "terraform-version": "1.9.4",      "trigger-prefixes": [],      "vcs-repo": {        "branch": "",        "display-identifier": "example/terraform-test-proj",        "identifier": "example/terraform-test-proj",        "ingress-submodules": false,        "oauth-token-id": "ot-hmAyP66qk2AMVdbJ",        "repository-http-url": "https://github.com/example/terraform-test-proj",        "service-provider": "github",        "tags-regex": null,        "webhook-url": "https://app.terraform.io/webhooks/vcs/704ac743-df64-4b8e-b9a3-a4c5fe1bec87"      },      "vcs-repo-identifier": "example/terraform-test-proj",      "working-directory": "",      "workspace-kpis-runs-count": null,      "setting-overwrites": {        "execution-mode": true,        "agent-pool": true      }    },    "links": {      "self": "/api/v2/organizations/my-organization/workspaces/workspace-2",      "self-html": "/app/my-organization/workspaces/workspace-2"    },    "relationships": {      "relationships": {      "agent-pool": {        "data": null      },      "current-configuration-version": {        "data": null      },      "current-run": {        "data": {          "id": "run-hjy7ndEkmCtn31ps",          "type": "runs"        },        "links": {          "related": "/api/v2/runs/run-hjy7ndEkmCtn31ps"        }      },      "latest-run": {// Deprecated; same as current-run        "data": {          "id": "run-hjy7ndEkmCtn31ps",          "type": "runs"        },        "links": {          "related": "/api/v2/runs/run-hjy7ndEkmCtn31ps"        }      },      "current-state-version": {        "data": {          "id": "sv-hjy7ndEkmCtn31ps",          "type": "state-versions"        },        "links": {          "related": "/api/v2/workspaces/ws-6jrRyVDv1J8zQMB5/current-state-version"        }      },      "current-configuration-version": {        "data": {          "id": "cv-hjy7ndEkmCtn31ps",          "type": "configuration-versions"        },        "links": {          "related": "/api/v2/configuration-versions/cv-hjy7ndEkmCtn31ps"        }      },      "current-assessment-result": {        "data": null      },      "organization": {        "data": {          "id": "my-organization",          "type": "organizations"        }      },      "outputs": {        "data": [          {            "id": "wsout-hjy7ndEkmCtn31ps",            "type": "workspace-outputs"          }        ],        "links": {          "related": "/api/v2/workspaces/ws-6jrRyVDv1J8zQMB5/current-state-version-outputs"        }      },      "project": {        "data": {          "id": "prj-hjy7ndEkmCtn31ps",          "type": "projects"        }      },      "readme": {        "data": null      },      "remote-state-consumers": {        "links": {          "related": "/api/v2/workspaces/ws-6jrRyVDv1J8zQMB5/relationships/remote-state-consumers"        }      },      "ssh-key": {        "data": {          "id": "sshkey-hjy7ndEkmCtn31ps",          "type": "ssh-keys"        },        "links": {          "related": "/api/v2/ssh-keys/sshkey-hjy7ndEkmCtn31ps"        }      },      "locked-by": {        "data": {          "id": "user-hjy7ndEkmCtn31ps",          "type": "users"        },        "links": {          "related": "/api/v2/users/user-hjy7ndEkmCtn31ps"        }      },      "vars": {        "data": [          {            "id": "var-hjy7ndEkmCtn31ps",            "type": "vars"          }        ]      },    }  }}

List workspaces

This endpoint lists workspaces in the organization.

GET /organizations/:organization_name/workspaces

ParameterDescription
:organization_nameThe name of the organization to list the workspaces of.

Query Parameters

This endpoint supports paginationwith standard URL query parameters. Remember to percent-encode[ as%5B and] as%5D if your tooling doesn't automatically encode URLs.

ParameterDescription
page[number]Optional. If omitted, the endpoint will return the first page.
page[size]Optional. If omitted, the endpoint will return 20 workspaces per page.
search[name]Optional. If specified, restricts results to workspaces with a name that matches the search string using a fuzzy search.
search[tags]Optional. If specified, restricts results to workspaces with that tag. If multiple comma separated values are specified, results matching all of the tags are returned.
search[exclude-tags]Optional. If specified, results exclude workspaces with that tag. If multiple comma separated values are specified, workspaces with tags matching any of the tags are excluded.
search[wildcard-name]Optional. If specified, restricts results to workspaces with partial matching, using* on prefix, suffix, or both. For example,search[wildcard-name]=*-prod returns all workspaces ending in-prod,search[wildcard-name]=prod-* returns all workspaces beginning withprod-, andsearch[wildcard-name]=*-prod-* returns all workspaces with substring-prod- regardless of prefix and/or suffix.
sortOptional. Allows sorting the organization's workspaces by a provided value. You can sort by"name","current-run.created-at" (the time of the current run), and"latest-change-at" (the creation time of the latest state version or the workspace itself if no state version exists). Prepending a hyphen to the sort parameter reverses the order. For example,"-name" sorts by name in reverse alphabetical order. If omitted, the default sort order is arbitrary but stable.
filter[project][id]Optional. If specified, restricts results to workspaces in the specific project.
filter[current-run][status]Optional. If specified, restricts results to workspaces that match the status of a current run.
filter[tagged][i][key]Optional. If specified, restricts results to workspaces that are tagged with the provided key. Use a value of "0" fori if you are only using a single filter. For multiple tag filters, use an incrementing integer value for each filter. Multiple tag filters will be combined together with a logical AND when filtering results.
filter[tagged][i][value]Optional. If specified, restricts results to workspaces that are tagged with the provided value. This is useful when combined with akey filter for more specificity. Use a value of "0" fori if you are only using a single filter. For multiple tag filters, use an incrementing integer value for each filter. Multiple tag filters will be combined together with a logical AND when filtering results.

Sample Request

$ curl \  --header "Authorization: Bearer $TOKEN" \  --header "Content-Type: application/vnd.api+json" \  https://app.terraform.io/api/v2/organizations/my-organization/workspaces

With multiple tag filters

$ curl \  --header "Authorization: Bearer $TOKEN" \  --header "Content-Type: application/vnd.api+json" \  https://app.terraform.io/api/v2/organizations/my-organization/workspaces?filter%5B%tagged5D%5B0%5D%5Bkey%5D=environment&filter%5B%tagged5D%5B0%5D%5Bvalue%5D=development&filter%5B%tagged5D%5B1%5D%5Bkey%5D=meets-compliance

Sample Response

{  "data": [    {      "id": "ws-6jrRyVDv1J8zQMB5",      "type": "workspaces",      "attributes": {        "actions": {          "is-destroyable": true        },        "allow-destroy-plan": true,        "assessments-enabled": false,        "auto-apply": false,        "auto-apply-run-trigger": false,        "auto-destroy-at": null,        "auto-destroy-status": null,        "auto-destroy-activity-duration": null,        "inherits-project-auto-destroy": null,        "created-at": "2021-08-16T21:22:49.566Z",        "description": null,        "environment": "default",        "execution-mode": "agent",        "file-triggers-enabled": true,        "global-remote-state": false,        "latest-change-at": "2021-08-16T21:22:49.566Z",        "last-assessment-result-at" : "2021-08-17T21:20:12.908Z",        "locked": true,        "locked-reason": null,        "name": "workspace-1",        "oauth-client-name": null,        "operations": true,        "permissions": {          "can-update": true,          "can-destroy": true,          "can-queue-run": true,          "can-read-run": true,          "can-read-variable": true,          "can-update-variable": true,          "can-read-state-versions": true,          "can-read-state-outputs": true,          "can-create-state-versions": true,          "can-queue-apply": true,          "can-lock": true,          "can-unlock": true,          "can-force-unlock": true,          "can-read-settings": true,          "can-manage-tags": true,          "can-manage-run-tasks": true,          "can-force-delete": true,          "can-manage-assessments": true,          "can-manage-ephemeral-workspaces": false,          "can-read-assessment-results": true,          "can-queue-destroy": true        },        "apply-duration-average": 35000,        "plan-duration-average": 53000,        "policy-check-failures": null,        "queue-all-runs": false,        "resource-count": 10,        "run-failures": 3,        "source": "tfe-api",        "source-name": null,        "source-url": null,        "speculative-enabled": true,        "structured-run-output-enabled": true,        "tag-names": [],        "terraform-version": "1.9.4",        "trigger-prefixes": [],        "updated-at": "2021-08-16T21:22:49.566Z",        "vcs-repo": null,        "vcs-repo-identifier": null,        "working-directory": null,        "workspace-kpis-runs-count": 8,        "setting-overwrites": {          "execution-mode": true,          "agent-pool": true        }      },      "links": {        "self": "/api/v2/organizations/my-organization/workspaces/workspace-1",        "self-html": "/app/my-organization/workspaces/workspace-1"      },      "relationships": {        "agent-pool": {          "data": {            "id": "apool-QxGd2tRjympfMvQc",            "type": "agent-pools"          }        },        "current-configuration-version": {          "data": null        },        "current-run": {          "data": {            "id": "run-hjy7ndEkmCtn31ps",            "type": "runs"          },          "links": {            "related": "/api/v2/runs/run-hjy7ndEkmCtn31ps"          }        },        "latest-run": {// Deprecated; same as current-run          "data": {            "id": "run-hjy7ndEkmCtn31ps",            "type": "runs"          },          "links": {            "related": "/api/v2/runs/run-hjy7ndEkmCtn31ps"          }        },        "current-state-version": {          "data": {            "id": "sv-hjy7ndEkmCtn31ps",            "type": "state-versions"          },          "links": {            "related": "/api/v2/workspaces/ws-6jrRyVDv1J8zQMB5/current-state-version"          }        },        "current-configuration-version": {          "data": {            "id": "cv-hjy7ndEkmCtn31ps",            "type": "configuration-versions"          },          "links": {            "related": "/api/v2/configuration-versions/cv-hjy7ndEkmCtn31ps"          }        },        "current-assessment-result": {          "data": null        },        "organization": {          "data": {            "id": "my-organization",            "type": "organizations"          }        },        "outputs": {          "data": [            {              "id": "wsout-hjy7ndEkmCtn31ps",              "type": "workspace-outputs"            },            {              "id": "wsout-hjy7ndEkmCtn31ps",              "type": "workspace-outputs"            }          ],          "links": {            "related": "/api/v2/workspaces/ws-6jrRyVDv1J8zQMB5/current-state-version-outputs"          }        },        "project": {          "data": {            "id": "prj-hjy7ndEkmCtn31ps",            "type": "projects"          }        },        "readme": {          "data": null        },        "remote-state-consumers": {          "links": {            "related": "/api/v2/workspaces/ws-6jrRyVDv1J8zQMB5/relationships/remote-state-consumers"          }        },        "ssh-key": {          "data": {            "id": "sshkey-hjy7ndEkmCtn31ps",            "type": "ssh-keys"          },          "links": {            "related": "/api/v2/ssh-keys/sshkey-hjy7ndEkmCtn31ps"          }        },        "locked-by": {          "data": {            "id": "user-hjy7ndEkmCtn31ps",            "type": "users"          },          "links": {            "related": "/api/v2/users/user-hjy7ndEkmCtn31ps"          }        },        "vars": {          "data": [            {              "id": "var-hjy7ndEkmCtn31ps",              "type": "vars"            }          ]        },      }    },  ],  "links": {    "first": "https://app.terraform.io/api/v2/workspaces?page%5Bnumber%5D=1&page%5Bsize%5D=20",    "last": "https://app.terraform.io/api/v2/workspaces?page%5Bnumber%5D=1&page%5Bsize%5D=20",    "next": null,    "prev": null,    "self": "https://app.terraform.io/api/v2/workspaces?page%5Bnumber%5D=1&page%5Bsize%5D=20"  },  "meta": {    "pagination": {      "current-page": 1,      "next-page": null,      "page-size": 20,      "prev-page": null,      "total-count": 1,      "total-pages": 1    }  }}

Show workspace

Details on a workspace can be retrieved from two endpoints, which behave identically.

One refers to a workspace by its ID:

GET /workspaces/:workspace_id

ParameterDescription
:workspace_idThe workspace ID

The other refers to a workspace by its name and organization:

GET /organizations/:organization_name/workspaces/:name

ParameterDescription
:organization_nameThe name of the organization the workspace belongs to.
:nameThe name of the workspace to show details for, which can only include letters, numbers,-, and_.

Workspace performance attributes

The following attributes are helpful in determining the overall health and performance of your workspace configuration. These metrics refer to thepast 30 runs that have either resulted in an error or successfully applied.

ParameterTypeDescription
data.attributes.apply-duration-averagenumberThis is the average time runs spend in theapply phase, represented in milliseconds
data.attributes.plan-duration-averagenumberThis is the average time runs spend in theplan phase, represented in milliseconds
data.attributes.policy-check-failuresnumberReports the number of run failures resulting from a policy check failure
data.attributes.run-failuresnumberReports the number of failed runs
data.attributes.workspace-kpis-run-countnumberTotal number of runs taken into account by these metrics

Sample Request

$ curl \  --header "Authorization: Bearer $TOKEN" \  --header "Content-Type: application/vnd.api+json" \  https://app.terraform.io/api/v2/organizations/my-organization/workspaces/workspace-1

Sample Response

{  "data": {    "id": "ws-6jrRyVDv1J8zQMB5",    "type": "workspaces",    "attributes": {      "actions": {        "is-destroyable": true      },      "allow-destroy-plan": true,      "assessments-enabled": false,      "auto-apply": false,      "auto-apply-run-trigger": false,      "auto-destroy-at": null,      "auto-destroy-status": null,      "auto-destroy-activity-duration": null,      "inherits-project-auto-destroy": null,      "created-at": "2021-08-16T21:22:49.566Z",      "description": null,      "environment": "default",      "execution-mode": "agent",      "file-triggers-enabled": true,      "global-remote-state": false,      "latest-change-at": "2021-08-16T21:22:49.566Z",      "last-assessment-result-at" : "2021-08-17T21:20:12.908Z",      "locked": true,      "locked-reason": null,      "name": "workspace-1",      "oauth-client-name": null,      "operations": true,      "permissions": {        "can-update": true,        "can-destroy": true,        "can-queue-run": true,        "can-read-run": true,        "can-read-variable": true,        "can-update-variable": true,        "can-read-state-versions": true,        "can-read-state-outputs": true,        "can-create-state-versions": true,        "can-queue-apply": true,        "can-lock": true,        "can-unlock": true,        "can-force-unlock": true,        "can-read-settings": true,        "can-manage-tags": true,        "can-manage-run-tasks": true,        "can-force-delete": true,        "can-manage-assessments": true,        "can-manage-ephemeral-workspaces": false,        "can-read-assessment-results": true,        "can-queue-destroy": true      },      "apply-duration-average": 35000,      "plan-duration-average": 53000,      "policy-check-failures": null,      "queue-all-runs": false,      "resource-count": 10,      "run-failures": 3,      "source": "tfe-api",      "source-name": null,      "source-url": null,      "speculative-enabled": true,      "structured-run-output-enabled": true,      "tag-names": [],      "terraform-version": "1.9.4",      "trigger-prefixes": [],      "updated-at": "2021-08-16T21:22:49.566Z",      "vcs-repo": null,      "vcs-repo-identifier": null,      "working-directory": null,      "workspace-kpis-runs-count": 8,      "setting-overwrites": {        "execution-mode": true,        "agent-pool": true      }    },    "links": {      "self": "/api/v2/organizations/my-organization/workspaces/workspace-1",      "self-html": "/app/my-organization/workspaces/workspace-1"    },    "relationships": {      "agent-pool": {        "data": {          "id": "apool-QxGd2tRjympfMvQc",          "type": "agent-pools"        }      },      "current-configuration-version": {        "data": null      },      "current-run": {        "data": {          "id": "run-hjy7ndEkmCtn31ps",          "type": "runs"        },        "links": {          "related": "/api/v2/runs/run-hjy7ndEkmCtn31ps"        }      },      "latest-run": {// Deprecated; same as current-run        "data": {          "id": "run-hjy7ndEkmCtn31ps",          "type": "runs"        },        "links": {          "related": "/api/v2/runs/run-hjy7ndEkmCtn31ps"        }      },      "current-state-version": {        "data": {          "id": "sv-hjy7ndEkmCtn31ps",          "type": "state-versions"        },        "links": {          "related": "/api/v2/workspaces/ws-6jrRyVDv1J8zQMB5/current-state-version"        }      },      "current-configuration-version": {        "data": {          "id": "cv-hjy7ndEkmCtn31ps",          "type": "configuration-versions"        },        "links": {          "related": "/api/v2/configuration-versions/cv-hjy7ndEkmCtn31ps"        }      },      "current-assessment-result": {        "data": null      },      "organization": {        "data": {          "id": "my-organization",          "type": "organizations"        }      },      "outputs": {        "data": [          {            "id": "wsout-hjy7ndEkmCtn31ps",            "type": "workspace-outputs"          },          {            "id": "wsout-hjy7ndEkmCtn31ps",            "type": "workspace-outputs"          }        ],        "links": {          "related": "/api/v2/workspaces/ws-6jrRyVDv1J8zQMB5/current-state-version-outputs"        }      },      "project": {        "data": {          "id": "prj-hjy7ndEkmCtn31ps",          "type": "projects"        }      },      "readme": {        "data": null      },      "remote-state-consumers": {        "links": {          "related": "/api/v2/workspaces/ws-6jrRyVDv1J8zQMB5/relationships/remote-state-consumers"        }      },      "ssh-key": {        "data": {          "id": "sshkey-hjy7ndEkmCtn31ps",          "type": "ssh-keys"        },        "links": {          "related": "/api/v2/ssh-keys/sshkey-hjy7ndEkmCtn31ps"        }      },      "locked-by": {        "data": {          "id": "user-hjy7ndEkmCtn31ps",          "type": "users"        },        "links": {          "related": "/api/v2/users/user-hjy7ndEkmCtn31ps"        }      },      "vars": {        "data": [          {            "id": "var-hjy7ndEkmCtn31ps",            "type": "vars"          }        ]      },    }  }}

Safe Delete a workspace

When you delete an HCP Terraform workspace with resources, Terraform can no longer track or manage that infrastructure. During a safe delete, HCP Terraform only deletes the workspace if it is not managing resources.

You can safe delete a workspace using two endpoints that behave identically. The first endpoint identifies a workspace with the workspace ID, and the other identifies the workspace by its name and organization.

POST /workspaces/:workspace_id/actions/safe-delete

ParameterDescription
:workspace_idThe ID of the workspace to delete.

POST /organizations/:organization_name/workspaces/:name/actions/safe-delete

ParameterDescription
:organization_nameThe name of the workspace's organization.
:nameThe name of the workspace to delete, which can only include letters, numbers,-, and_.
StatusResponseReason(s)
204No ContentSuccessfully deleted the workspace
404JSON API error objectWorkspace not found, or user unauthorized to perform workspace delete
409JSON API error objectWorkspace is not safe to delete because it is managing resources

Force Delete a workspace

During a force delete, HCP Terraform removes the specified workspace without checking whether it is managing resources. We recommend using thesafe delete endpoint instead, when possible.

Warning: Terraform cannot track or manage the workspace's infrastructure after deletion. We recommenddestroying the workspace's infrastructure before you delete it.

By default, only organization owners can force delete workspaces. Organization owners can also update [organization's settings](/terraform/cloud-docs/users-teams organizations/organizations#general) to let workspace admins force delete their own workspaces.

You can use two endpoints to force delete a workspace, which behave identically. One endpoint identifies the workspace with its workspace ID and the other endpoint identifies the workspace with its name and organization.

DELETE /workspaces/:workspace_id

ParameterDescription
:workspace_idThe ID of the workspace to delete

DELETE /organizations/:organization_name/workspaces/:name

ParameterDescription
:organization_nameThe name of the organization the workspace belongs to.
:nameThe name of the workspace to delete, which can only include letters, numbers,-, and_.
StatusResponseReason(s)
204No ContentSuccessfully deleted the workspace
403JSON API error objectNot authorized to perform a force delete on the workspace
404JSON API error objectWorkspace not found, or user unauthorized to perform workspace delete

Sample Request

$ curl \  --header "Authorization: Bearer $TOKEN" \  --header "Content-Type: application/vnd.api+json" \  --request DELETE \  https://app.terraform.io/api/v2/organizations/my-organization/workspaces/workspace-1

Lock a workspace

This endpoint locks a workspace.

POST /workspaces/:workspace_id/actions/lock

ParameterDescription
:workspace_idThe workspace ID to lock. Obtain this from theworkspace settings or theShow Workspace endpoint.
StatusResponseReason(s)
200JSON API document (type: "workspaces")Successfully locked the workspace
404JSON API error objectWorkspace not found, or user unauthorized to perform action
409JSON API error objectWorkspace already locked

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 pathTypeDefaultDescription
reasonstring""The reason for locking the workspace.

Sample Payload

{  "reason": "Locking workspace-1"}

Sample Request

$ curl \  --header "Authorization: Bearer $TOKEN" \  --header "Content-Type: application/vnd.api+json" \  --request POST \  --data @payload.json \  https://app.terraform.io/api/v2/workspaces/ws-SihZTyXKfNXUWuUa/actions/lock

Sample Response

{  "data": {    "id": "ws-6jrRyVDv1J8zQMB5",    "type": "workspaces",    "attributes": {      "actions": {        "is-destroyable": true      },      "allow-destroy-plan": true,      "assessments-enabled": false,      "auto-apply": false,      "auto-apply-run-trigger": false,      "auto-destroy-at": null,      "auto-destroy-status": null,      "auto-destroy-activity-duration": null,      "inherits-project-auto-destroy": null,      "created-at": "2021-08-16T21:22:49.566Z",      "description": null,      "environment": "default",      "execution-mode": "agent",      "file-triggers-enabled": true,      "global-remote-state": false,      "latest-change-at": "2021-08-16T21:22:49.566Z",      "last-assessment-result-at" : "2021-08-17T21:20:12.908Z",      "locked": true,      "locked-reason": null,      "name": "workspace-1",      "oauth-client-name": null,      "operations": true,      "permissions": {        "can-update": true,        "can-destroy": true,        "can-queue-run": true,        "can-read-run": true,        "can-read-variable": true,        "can-update-variable": true,        "can-read-state-versions": true,        "can-read-state-outputs": true,        "can-create-state-versions": true,        "can-queue-apply": true,        "can-lock": true,        "can-unlock": true,        "can-force-unlock": true,        "can-read-settings": true,        "can-manage-tags": true,        "can-manage-run-tasks": true,        "can-force-delete": true,        "can-manage-assessments": true,        "can-manage-ephemeral-workspaces": false,        "can-read-assessment-results": true,        "can-queue-destroy": true      },      "apply-duration-average": 35000,      "plan-duration-average": 53000,      "policy-check-failures": null,      "queue-all-runs": false,      "resource-count": 10,      "run-failures": 3,      "source": "tfe-api",      "source-name": null,      "source-url": null,      "speculative-enabled": true,      "structured-run-output-enabled": true,      "tag-names": [],      "terraform-version": "1.9.4",      "trigger-prefixes": [],      "updated-at": "2021-08-16T21:22:49.566Z",      "vcs-repo": null,      "vcs-repo-identifier": null,      "working-directory": null,      "workspace-kpis-runs-count": 8,      "setting-overwrites": {        "execution-mode": true,        "agent-pool": true      }    },    "links": {      "self": "/api/v2/organizations/my-organization/workspaces/workspace-1",      "self-html": "/app/my-organization/workspaces/workspace-1"    },    "relationships": {      "agent-pool": {        "data": {          "id": "apool-QxGd2tRjympfMvQc",          "type": "agent-pools"        }      },      "current-configuration-version": {        "data": null      },      "current-run": {        "data": {          "id": "run-hjy7ndEkmCtn31ps",          "type": "runs"        },        "links": {          "related": "/api/v2/runs/run-hjy7ndEkmCtn31ps"        }      },      "latest-run": {// Deprecated; same as current-run        "data": {          "id": "run-hjy7ndEkmCtn31ps",          "type": "runs"        },        "links": {          "related": "/api/v2/runs/run-hjy7ndEkmCtn31ps"        }      },      "current-state-version": {        "data": {          "id": "sv-hjy7ndEkmCtn31ps",          "type": "state-versions"        },        "links": {          "related": "/api/v2/workspaces/ws-6jrRyVDv1J8zQMB5/current-state-version"        }      },      "current-configuration-version": {        "data": {          "id": "cv-hjy7ndEkmCtn31ps",          "type": "configuration-versions"        },        "links": {          "related": "/api/v2/configuration-versions/cv-hjy7ndEkmCtn31ps"        }      },      "current-assessment-result": {        "data": null      },      "organization": {        "data": {          "id": "my-organization",          "type": "organizations"        }      },      "outputs": {        "data": [          {            "id": "wsout-hjy7ndEkmCtn31ps",            "type": "workspace-outputs"          },          {            "id": "wsout-hjy7ndEkmCtn31ps",            "type": "workspace-outputs"          }        ],        "links": {          "related": "/api/v2/workspaces/ws-6jrRyVDv1J8zQMB5/current-state-version-outputs"        }      },      "project": {        "data": {          "id": "prj-hjy7ndEkmCtn31ps",          "type": "projects"        }      },      "readme": {        "data": null      },      "remote-state-consumers": {        "links": {          "related": "/api/v2/workspaces/ws-6jrRyVDv1J8zQMB5/relationships/remote-state-consumers"        }      },      "ssh-key": {        "data": {          "id": "sshkey-hjy7ndEkmCtn31ps",          "type": "ssh-keys"        },        "links": {          "related": "/api/v2/ssh-keys/sshkey-hjy7ndEkmCtn31ps"        }      },      "locked-by": {        "data": {          "id": "user-hjy7ndEkmCtn31ps",          "type": "users"        },        "links": {          "related": "/api/v2/users/user-hjy7ndEkmCtn31ps"        }      },      "vars": {        "data": [          {            "id": "var-hjy7ndEkmCtn31ps",            "type": "vars"          }        ]      },    }  }}

Unlock a workspace

This endpoint unlocks a workspace. Unlocking a workspace sets the current state version to the latest finalized intermediate state version. If intermediate state versions are available, but HCP Terraform has not yet finalized the latest intermediate state version, the unlock will fail with a 503 response. For this particular error, it's recommended to retry the unlock operation for a short period of time until the platform finalizes the state version. If you must force-unlock a workspace under these conditions, ensure that state was saved successfully by inspecting the latest state version using theState Version List API

POST /workspaces/:workspace_id/actions/unlock

ParameterDescription
:workspace_idThe workspace ID to unlock. Obtain this from theworkspace settings or theShow Workspace endpoint.
StatusResponseReason(s)
200JSON API document (type: "workspaces")Successfully unlocked the workspace
404JSON API error objectWorkspace not found, or user unauthorized to perform action
409JSON API error objectWorkspace already unlocked, or locked by a different user

Sample Request

$ curl \  --header "Authorization: Bearer $TOKEN" \  --header "Content-Type: application/vnd.api+json" \  --request POST \  https://app.terraform.io/api/v2/workspaces/ws-SihZTyXKfNXUWuUa/actions/unlock

Sample Response

{  "data": {    "id": "ws-6jrRyVDv1J8zQMB5",    "type": "workspaces",    "attributes": {      "actions": {        "is-destroyable": true      },      "allow-destroy-plan": true,      "assessments-enabled": false,      "auto-apply": false,      "auto-apply-run-trigger": false,      "auto-destroy-at": null,      "auto-destroy-status": null,      "auto-destroy-activity-duration": null,      "inherits-project-auto-destroy": null,      "created-at": "2021-08-16T21:22:49.566Z",      "description": null,      "environment": "default",      "execution-mode": "agent",      "file-triggers-enabled": true,      "global-remote-state": false,      "latest-change-at": "2021-08-16T21:22:49.566Z",      "last-assessment-result-at" : "2021-08-17T21:20:12.908Z",      "locked": true,      "locked-reason": null,      "name": "workspace-1",      "oauth-client-name": null,      "operations": true,      "permissions": {        "can-update": true,        "can-destroy": true,        "can-queue-run": true,        "can-read-run": true,        "can-read-variable": true,        "can-update-variable": true,        "can-read-state-versions": true,        "can-read-state-outputs": true,        "can-create-state-versions": true,        "can-queue-apply": true,        "can-lock": true,        "can-unlock": true,        "can-force-unlock": true,        "can-read-settings": true,        "can-manage-tags": true,        "can-manage-run-tasks": true,        "can-force-delete": true,        "can-manage-assessments": true,        "can-manage-ephemeral-workspaces": false,        "can-read-assessment-results": true,        "can-queue-destroy": true      },      "apply-duration-average": 35000,      "plan-duration-average": 53000,      "policy-check-failures": null,      "queue-all-runs": false,      "resource-count": 10,      "run-failures": 3,      "source": "tfe-api",      "source-name": null,      "source-url": null,      "speculative-enabled": true,      "structured-run-output-enabled": true,      "tag-names": [],      "terraform-version": "1.9.4",      "trigger-prefixes": [],      "updated-at": "2021-08-16T21:22:49.566Z",      "vcs-repo": null,      "vcs-repo-identifier": null,      "working-directory": null,      "workspace-kpis-runs-count": 8,      "setting-overwrites": {        "execution-mode": true,        "agent-pool": true      }    },    "links": {      "self": "/api/v2/organizations/my-organization/workspaces/workspace-1",      "self-html": "/app/my-organization/workspaces/workspace-1"    },    "relationships": {      "agent-pool": {        "data": {          "id": "apool-QxGd2tRjympfMvQc",          "type": "agent-pools"        }      },      "current-configuration-version": {        "data": null      },      "current-run": {        "data": {          "id": "run-hjy7ndEkmCtn31ps",          "type": "runs"        },        "links": {          "related": "/api/v2/runs/run-hjy7ndEkmCtn31ps"        }      },      "latest-run": {// Deprecated; same as current-run        "data": {          "id": "run-hjy7ndEkmCtn31ps",          "type": "runs"        },        "links": {          "related": "/api/v2/runs/run-hjy7ndEkmCtn31ps"        }      },      "current-state-version": {        "data": {          "id": "sv-hjy7ndEkmCtn31ps",          "type": "state-versions"        },        "links": {          "related": "/api/v2/workspaces/ws-6jrRyVDv1J8zQMB5/current-state-version"        }      },      "current-configuration-version": {        "data": {          "id": "cv-hjy7ndEkmCtn31ps",          "type": "configuration-versions"        },        "links": {          "related": "/api/v2/configuration-versions/cv-hjy7ndEkmCtn31ps"        }      },      "current-assessment-result": {        "data": null      },      "organization": {        "data": {          "id": "my-organization",          "type": "organizations"        }      },      "outputs": {        "data": [          {            "id": "wsout-hjy7ndEkmCtn31ps",            "type": "workspace-outputs"          },          {            "id": "wsout-hjy7ndEkmCtn31ps",            "type": "workspace-outputs"          }        ],        "links": {          "related": "/api/v2/workspaces/ws-6jrRyVDv1J8zQMB5/current-state-version-outputs"        }      },      "project": {        "data": {          "id": "prj-hjy7ndEkmCtn31ps",          "type": "projects"        }      },      "readme": {        "data": null      },      "remote-state-consumers": {        "links": {          "related": "/api/v2/workspaces/ws-6jrRyVDv1J8zQMB5/relationships/remote-state-consumers"        }      },      "ssh-key": {        "data": {          "id": "sshkey-hjy7ndEkmCtn31ps",          "type": "ssh-keys"        },        "links": {          "related": "/api/v2/ssh-keys/sshkey-hjy7ndEkmCtn31ps"        }      },      "locked-by": {        "data": {          "id": "user-hjy7ndEkmCtn31ps",          "type": "users"        },        "links": {          "related": "/api/v2/users/user-hjy7ndEkmCtn31ps"        }      },      "vars": {        "data": [          {            "id": "var-hjy7ndEkmCtn31ps",            "type": "vars"          }        ]      },    }  }}

Force Unlock a workspace

This endpoint force unlocks a workspace. Only users with admin access are authorized to force unlock a workspace.

POST /workspaces/:workspace_id/actions/force-unlock

ParameterDescription
:workspace_idThe workspace ID to force unlock. Obtain this from theworkspace settings or theShow Workspace endpoint.
StatusResponseReason(s)
200JSON API document (type: "workspaces")Successfully force unlocked the workspace
404JSON API error objectWorkspace not found, or user unauthorized to perform action
409JSON API error objectWorkspace already unlocked

Sample Request

$ curl \  --header "Authorization: Bearer $TOKEN" \  --header "Content-Type: application/vnd.api+json" \  --request POST \  https://app.terraform.io/api/v2/workspaces/ws-SihZTyXKfNXUWuUa/actions/force-unlock

Sample Response

{  "data": {    "id": "ws-KTuq99JSzgmDSvYj",    "type": "workspaces",    "attributes": {      "actions": {        "is-destroyable": true      },      "allow-destroy-plan": true,      "apply-duration-average": null,      "assessments-enabled": false,      "auto-apply": false,      "auto-apply-run-trigger": false,      "auto-destroy-at": null,      "auto-destroy-activity-duration": null,      "created-at": "2021-08-16T21:50:58.726Z",      "description": null,      "environment": "default",      "execution-mode": "remote",      "file-triggers-enabled": true,      "global-remote-state": false,      "latest-change-at": "2021-08-16T21:50:58.726Z",      "locked": false,      "locked-reason": "",      "name": "workspace-2",      "oauth-client-name": "github example",      "operations": true,      "permissions": {        "can-update": true,        "can-destroy": true,        "can-queue-run": true,        "can-read-run": true,        "can-read-variable": true,        "can-update-variable": true,        "can-read-state-versions": true,        "can-read-state-outputs": true,        "can-create-state-versions": true,        "can-queue-apply": true,        "can-lock": true,        "can-unlock": true,        "can-force-unlock": true,        "can-read-settings": true,        "can-manage-tags": true,        "can-manage-run-tasks": true,        "can-force-delete": true,        "can-manage-assessments": true,        "can-manage-ephemeral-workspaces": false,        "can-read-assessment-results": true,        "can-queue-destroy": true      },      "apply-duration-average": 35000,      "plan-duration-average": 53000,      "policy-check-failures": null,      "queue-all-runs": false,      "resource-count": 10,      "run-failures": 3,      "source": "tfe-api",      "source-name": null,      "source-url": null,      "speculative-enabled": true,      "structured-run-output-enabled": true,      "tag-names": [],      "terraform-version": "1.9.4",      "trigger-prefixes": [],      "vcs-repo": {        "branch": "",        "display-identifier": "example/terraform-test-proj",        "identifier": "example/terraform-test-proj",        "ingress-submodules": false,        "oauth-token-id": "ot-hmAyP66qk2AMVdbJ",        "repository-http-url": "https://github.com/example/terraform-test-proj",        "service-provider": "github",        "tags-regex": null,        "webhook-url": "https://app.terraform.io/webhooks/vcs/704ac743-df64-4b8e-b9a3-a4c5fe1bec87"      },      "vcs-repo-identifier": "example/terraform-test-proj",      "working-directory": "",      "workspace-kpis-runs-count": null,      "setting-overwrites": {        "execution-mode": true,        "agent-pool": true      }    },    "links": {      "self": "/api/v2/organizations/my-organization/workspaces/workspace-2",      "self-html": "/app/my-organization/workspaces/workspace-2"    },    "relationships": {      "relationships": {      "agent-pool": {        "data": null      },      "current-configuration-version": {        "data": null      },      "current-run": {        "data": {          "id": "run-hjy7ndEkmCtn31ps",          "type": "runs"        },        "links": {          "related": "/api/v2/runs/run-hjy7ndEkmCtn31ps"        }      },      "latest-run": {// Deprecated; same as current-run        "data": {          "id": "run-hjy7ndEkmCtn31ps",          "type": "runs"        },        "links": {          "related": "/api/v2/runs/run-hjy7ndEkmCtn31ps"        }      },      "current-state-version": {        "data": {          "id": "sv-hjy7ndEkmCtn31ps",          "type": "state-versions"        },        "links": {          "related": "/api/v2/workspaces/ws-6jrRyVDv1J8zQMB5/current-state-version"        }      },      "current-configuration-version": {        "data": {          "id": "cv-hjy7ndEkmCtn31ps",          "type": "configuration-versions"        },        "links": {          "related": "/api/v2/configuration-versions/cv-hjy7ndEkmCtn31ps"        }      },      "current-assessment-result": {        "data": null      },      "organization": {        "data": {          "id": "my-organization",          "type": "organizations"        }      },      "outputs": {        "data": [          {            "id": "wsout-hjy7ndEkmCtn31ps",            "type": "workspace-outputs"          }        ],        "links": {          "related": "/api/v2/workspaces/ws-6jrRyVDv1J8zQMB5/current-state-version-outputs"        }      },      "project": {        "data": {          "id": "prj-hjy7ndEkmCtn31ps",          "type": "projects"        }      },      "readme": {        "data": null      },      "remote-state-consumers": {        "links": {          "related": "/api/v2/workspaces/ws-6jrRyVDv1J8zQMB5/relationships/remote-state-consumers"        }      },      "ssh-key": {        "data": {          "id": "sshkey-hjy7ndEkmCtn31ps",          "type": "ssh-keys"        },        "links": {          "related": "/api/v2/ssh-keys/sshkey-hjy7ndEkmCtn31ps"        }      },      "locked-by": {        "data": {          "id": "user-hjy7ndEkmCtn31ps",          "type": "users"        },        "links": {          "related": "/api/v2/users/user-hjy7ndEkmCtn31ps"        }      },      "vars": {        "data": [          {            "id": "var-hjy7ndEkmCtn31ps",            "type": "vars"          }        ]      },    }  }}

Assign an SSH key to a workspace

This endpoint assigns an SSH key to a workspace.

PATCH /workspaces/:workspace_id/relationships/ssh-key

ParameterDescription
:workspace_idThe workspace ID to assign the SSH key to. Obtain this from theworkspace settings or theShow Workspace endpoint.

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 pathTypeDefaultDescription
data.typestringMust be"workspaces".
data.attributes.idstringThe SSH key ID to assign. Obtain this from thessh-keys endpoint.

Sample Payload

{  "data": {    "attributes": {      "id": "sshkey-GxrePWre1Ezug7aM"    },    "type": "workspaces"  }}

Sample Request

$ curl \  --header "Authorization: Bearer $TOKEN" \  --header "Content-Type: application/vnd.api+json" \  --request PATCH \  --data @payload.json \  https://app.terraform.io/api/v2/workspaces/ws-SihZTyXKfNXUWuUa/relationships/ssh-key

Sample Response

{  "data": {    "id": "ws-KTuq99JSzgmDSvYj",    "type": "workspaces",    "attributes": {      "actions": {        "is-destroyable": true      },      "allow-destroy-plan": true,      "apply-duration-average": null,      "assessments-enabled": false,      "auto-apply": false,      "auto-apply-run-trigger": false,      "auto-destroy-at": null,      "auto-destroy-activity-duration": null,      "created-at": "2021-08-16T21:50:58.726Z",      "description": null,      "environment": "default",      "execution-mode": "remote",      "file-triggers-enabled": true,      "global-remote-state": false,      "latest-change-at": "2021-08-16T21:50:58.726Z",      "locked": false,      "locked-reason": "",      "name": "workspace-2",      "oauth-client-name": "github example",      "operations": true,      "permissions": {        "can-update": true,        "can-destroy": true,        "can-queue-run": true,        "can-read-run": true,        "can-read-variable": true,        "can-update-variable": true,        "can-read-state-versions": true,        "can-read-state-outputs": true,        "can-create-state-versions": true,        "can-queue-apply": true,        "can-lock": true,        "can-unlock": true,        "can-force-unlock": true,        "can-read-settings": true,        "can-manage-tags": true,        "can-manage-run-tasks": true,        "can-force-delete": true,        "can-manage-assessments": true,        "can-manage-ephemeral-workspaces": false,        "can-read-assessment-results": true,        "can-queue-destroy": true      },      "apply-duration-average": 35000,      "plan-duration-average": 53000,      "policy-check-failures": null,      "queue-all-runs": false,      "resource-count": 10,      "run-failures": 3,      "source": "tfe-api",      "source-name": null,      "source-url": null,      "speculative-enabled": true,      "structured-run-output-enabled": true,      "tag-names": [],      "terraform-version": "1.9.4",      "trigger-prefixes": [],      "vcs-repo": {        "branch": "",        "display-identifier": "example/terraform-test-proj",        "identifier": "example/terraform-test-proj",        "ingress-submodules": false,        "oauth-token-id": "ot-hmAyP66qk2AMVdbJ",        "repository-http-url": "https://github.com/example/terraform-test-proj",        "service-provider": "github",        "tags-regex": null,        "webhook-url": "https://app.terraform.io/webhooks/vcs/704ac743-df64-4b8e-b9a3-a4c5fe1bec87"      },      "vcs-repo-identifier": "example/terraform-test-proj",      "working-directory": "",      "workspace-kpis-runs-count": null,      "setting-overwrites": {        "execution-mode": true,        "agent-pool": true      }    },    "links": {      "self": "/api/v2/organizations/my-organization/workspaces/workspace-2",      "self-html": "/app/my-organization/workspaces/workspace-2"    },    "relationships": {      "relationships": {      "agent-pool": {        "data": null      },      "current-configuration-version": {        "data": null      },      "current-run": {        "data": {          "id": "run-hjy7ndEkmCtn31ps",          "type": "runs"        },        "links": {          "related": "/api/v2/runs/run-hjy7ndEkmCtn31ps"        }      },      "latest-run": {// Deprecated; same as current-run        "data": {          "id": "run-hjy7ndEkmCtn31ps",          "type": "runs"        },        "links": {          "related": "/api/v2/runs/run-hjy7ndEkmCtn31ps"        }      },      "current-state-version": {        "data": {          "id": "sv-hjy7ndEkmCtn31ps",          "type": "state-versions"        },        "links": {          "related": "/api/v2/workspaces/ws-6jrRyVDv1J8zQMB5/current-state-version"        }      },      "current-configuration-version": {        "data": {          "id": "cv-hjy7ndEkmCtn31ps",          "type": "configuration-versions"        },        "links": {          "related": "/api/v2/configuration-versions/cv-hjy7ndEkmCtn31ps"        }      },      "current-assessment-result": {        "data": null      },      "organization": {        "data": {          "id": "my-organization",          "type": "organizations"        }      },      "outputs": {        "data": [          {            "id": "wsout-hjy7ndEkmCtn31ps",            "type": "workspace-outputs"          }        ],        "links": {          "related": "/api/v2/workspaces/ws-6jrRyVDv1J8zQMB5/current-state-version-outputs"        }      },      "project": {        "data": {          "id": "prj-hjy7ndEkmCtn31ps",          "type": "projects"        }      },      "readme": {        "data": null      },      "remote-state-consumers": {        "links": {          "related": "/api/v2/workspaces/ws-6jrRyVDv1J8zQMB5/relationships/remote-state-consumers"        }      },      "ssh-key": {        "data": {          "id": "sshkey-hjy7ndEkmCtn31ps",          "type": "ssh-keys"        },        "links": {          "related": "/api/v2/ssh-keys/sshkey-hjy7ndEkmCtn31ps"        }      },      "locked-by": {        "data": {          "id": "user-hjy7ndEkmCtn31ps",          "type": "users"        },        "links": {          "related": "/api/v2/users/user-hjy7ndEkmCtn31ps"        }      },      "vars": {        "data": [          {            "id": "var-hjy7ndEkmCtn31ps",            "type": "vars"          }        ]      },    }  }}

Unassign an SSH key from a workspace

This endpoint unassigns the currently assigned SSH key from a workspace.

PATCH /workspaces/:workspace_id/relationships/ssh-key

ParameterDescription
:workspace_idThe workspace ID to assign the SSH key to. Obtain this from theworkspace settings or theShow Workspace endpoint.

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 pathTypeDefaultDescription
data.typestringMust be"workspaces".
data.attributes.idstringMust benull.

Sample Payload

{  "data": {    "attributes": {      "id": null    },    "type": "workspaces"  }}

Sample Request

$ curl \  --header "Authorization: Bearer $TOKEN" \  --header "Content-Type: application/vnd.api+json" \  --request PATCH \  --data @payload.json \  https://app.terraform.io/api/v2/workspaces/ws-SihZTyXKfNXUWuUa/relationships/ssh-key

Sample Response

{  "data": {    "id": "ws-KTuq99JSzgmDSvYj",    "type": "workspaces",    "attributes": {      "actions": {        "is-destroyable": true      },      "allow-destroy-plan": true,      "apply-duration-average": null,      "assessments-enabled": false,      "auto-apply": false,      "auto-apply-run-trigger": false,      "auto-destroy-at": null,      "auto-destroy-activity-duration": null,      "created-at": "2021-08-16T21:50:58.726Z",      "description": null,      "environment": "default",      "execution-mode": "remote",      "file-triggers-enabled": true,      "global-remote-state": false,      "latest-change-at": "2021-08-16T21:50:58.726Z",      "locked": false,      "locked-reason": "",      "name": "workspace-2",      "oauth-client-name": "github example",      "operations": true,      "permissions": {        "can-update": true,        "can-destroy": true,        "can-queue-run": true,        "can-read-run": true,        "can-read-variable": true,        "can-update-variable": true,        "can-read-state-versions": true,        "can-read-state-outputs": true,        "can-create-state-versions": true,        "can-queue-apply": true,        "can-lock": true,        "can-unlock": true,        "can-force-unlock": true,        "can-read-settings": true,        "can-manage-tags": true,        "can-manage-run-tasks": true,        "can-force-delete": true,        "can-manage-assessments": true,        "can-manage-ephemeral-workspaces": false,        "can-read-assessment-results": true,        "can-queue-destroy": true      },      "apply-duration-average": 35000,      "plan-duration-average": 53000,      "policy-check-failures": null,      "queue-all-runs": false,      "resource-count": 10,      "run-failures": 3,      "source": "tfe-api",      "source-name": null,      "source-url": null,      "speculative-enabled": true,      "structured-run-output-enabled": true,      "tag-names": [],      "terraform-version": "1.9.4",      "trigger-prefixes": [],      "vcs-repo": {        "branch": "",        "display-identifier": "example/terraform-test-proj",        "identifier": "example/terraform-test-proj",        "ingress-submodules": false,        "oauth-token-id": "ot-hmAyP66qk2AMVdbJ",        "repository-http-url": "https://github.com/example/terraform-test-proj",        "service-provider": "github",        "tags-regex": null,        "webhook-url": "https://app.terraform.io/webhooks/vcs/704ac743-df64-4b8e-b9a3-a4c5fe1bec87"      },      "vcs-repo-identifier": "example/terraform-test-proj",      "working-directory": "",      "workspace-kpis-runs-count": null,      "setting-overwrites": {        "execution-mode": true,        "agent-pool": true      }    },    "links": {      "self": "/api/v2/organizations/my-organization/workspaces/workspace-2",      "self-html": "/app/my-organization/workspaces/workspace-2"    },    "relationships": {      "relationships": {      "agent-pool": {        "data": null      },      "current-configuration-version": {        "data": null      },      "current-run": {        "data": {          "id": "run-hjy7ndEkmCtn31ps",          "type": "runs"        },        "links": {          "related": "/api/v2/runs/run-hjy7ndEkmCtn31ps"        }      },      "latest-run": {// Deprecated; same as current-run        "data": {          "id": "run-hjy7ndEkmCtn31ps",          "type": "runs"        },        "links": {          "related": "/api/v2/runs/run-hjy7ndEkmCtn31ps"        }      },      "current-state-version": {        "data": {          "id": "sv-hjy7ndEkmCtn31ps",          "type": "state-versions"        },        "links": {          "related": "/api/v2/workspaces/ws-6jrRyVDv1J8zQMB5/current-state-version"        }      },      "current-configuration-version": {        "data": {          "id": "cv-hjy7ndEkmCtn31ps",          "type": "configuration-versions"        },        "links": {          "related": "/api/v2/configuration-versions/cv-hjy7ndEkmCtn31ps"        }      },      "current-assessment-result": {        "data": null      },      "organization": {        "data": {          "id": "my-organization",          "type": "organizations"        }      },      "outputs": {        "data": [          {            "id": "wsout-hjy7ndEkmCtn31ps",            "type": "workspace-outputs"          }        ],        "links": {          "related": "/api/v2/workspaces/ws-6jrRyVDv1J8zQMB5/current-state-version-outputs"        }      },      "project": {        "data": {          "id": "prj-hjy7ndEkmCtn31ps",          "type": "projects"        }      },      "readme": {        "data": null      },      "remote-state-consumers": {        "links": {          "related": "/api/v2/workspaces/ws-6jrRyVDv1J8zQMB5/relationships/remote-state-consumers"        }      },      "ssh-key": {        "data": {          "id": "sshkey-hjy7ndEkmCtn31ps",          "type": "ssh-keys"        },        "links": {          "related": "/api/v2/ssh-keys/sshkey-hjy7ndEkmCtn31ps"        }      },      "locked-by": {        "data": {          "id": "user-hjy7ndEkmCtn31ps",          "type": "users"        },        "links": {          "related": "/api/v2/users/user-hjy7ndEkmCtn31ps"        }      },      "vars": {        "data": [          {            "id": "var-hjy7ndEkmCtn31ps",            "type": "vars"          }        ]      },    }  }}

Get Remote State Consumers

GET /workspaces/:workspace_id/relationships/remote-state-consumers

ParameterDescription
:workspace_idThe workspace ID to get remote state consumers for. Obtain this from theworkspace settings or theShow Workspace endpoint.

This endpoint retrieves the list of other workspaces that are allowed to access the given workspace's state during runs.

  • Ifglobal-remote-state is set to false for the workspace, this will return the list of other workspaces that are specifically authorized to access the workspace's state.
  • Ifglobal-remote-state is set to true, this will return a list of every workspace in the organization except for the subject workspace.

The list returned by this endpoint is subject to the caller's normal workspace permissions; it will not include workspaces that the provided API token is unable to read.

Query Parameters

This endpoint supports paginationwith standard URL query parameters. Remember to percent-encode[ as%5B and] as%5D if your tooling doesn't automatically encode URLs.

ParameterDescription
page[number]Optional. If omitted, the endpoint will return the first page.
page[size]Optional. If omitted, the endpoint will return 20 workspaces per page.

Sample Request

$ curl \  --header "Authorization: Bearer $TOKEN" \  --header "Content-Type: application/vnd.api+json" \  https://app.terraform.io/api/v2/workspaces/ws-SihZTyXKfNXUWuUa/relationships/remote-state-consumers

Sample Response

{  "data": [    {      "id": "ws-6jrRyVDv1J8zQMB5",      "type": "workspaces",      "attributes": {        "actions": {          "is-destroyable": true        },        "allow-destroy-plan": true,        "assessments-enabled": false,        "auto-apply": false,        "auto-apply-run-trigger": false,        "auto-destroy-at": null,        "auto-destroy-status": null,        "auto-destroy-activity-duration": null,        "inherits-project-auto-destroy": null,        "created-at": "2021-08-16T21:22:49.566Z",        "description": null,        "environment": "default",        "execution-mode": "agent",        "file-triggers-enabled": true,        "global-remote-state": false,        "latest-change-at": "2021-08-16T21:22:49.566Z",        "last-assessment-result-at" : "2021-08-17T21:20:12.908Z",        "locked": true,        "locked-reason": null,        "name": "workspace-1",        "oauth-client-name": null,        "operations": true,        "permissions": {          "can-update": true,          "can-destroy": true,          "can-queue-run": true,          "can-read-run": true,          "can-read-variable": true,          "can-update-variable": true,          "can-read-state-versions": true,          "can-read-state-outputs": true,          "can-create-state-versions": true,          "can-queue-apply": true,          "can-lock": true,          "can-unlock": true,          "can-force-unlock": true,          "can-read-settings": true,          "can-manage-tags": true,          "can-manage-run-tasks": true,          "can-force-delete": true,          "can-manage-assessments": true,          "can-manage-ephemeral-workspaces": false,          "can-read-assessment-results": true,          "can-queue-destroy": true        },        "apply-duration-average": 35000,        "plan-duration-average": 53000,        "policy-check-failures": null,        "queue-all-runs": false,        "resource-count": 10,        "run-failures": 3,        "source": "tfe-api",        "source-name": null,        "source-url": null,        "speculative-enabled": true,        "structured-run-output-enabled": true,        "tag-names": [],        "terraform-version": "1.9.4",        "trigger-prefixes": [],        "updated-at": "2021-08-16T21:22:49.566Z",        "vcs-repo": null,        "vcs-repo-identifier": null,        "working-directory": null,        "workspace-kpis-runs-count": 8,        "setting-overwrites": {          "execution-mode": true,          "agent-pool": true        }      },      "links": {        "self": "/api/v2/organizations/my-organization/workspaces/workspace-1",        "self-html": "/app/my-organization/workspaces/workspace-1"      },      "relationships": {        "agent-pool": {          "data": {            "id": "apool-QxGd2tRjympfMvQc",            "type": "agent-pools"          }        },        "current-configuration-version": {          "data": null        },        "current-run": {          "data": {            "id": "run-hjy7ndEkmCtn31ps",            "type": "runs"          },          "links": {            "related": "/api/v2/runs/run-hjy7ndEkmCtn31ps"          }        },        "latest-run": {// Deprecated; same as current-run          "data": {            "id": "run-hjy7ndEkmCtn31ps",            "type": "runs"          },          "links": {            "related": "/api/v2/runs/run-hjy7ndEkmCtn31ps"          }        },        "current-state-version": {          "data": {            "id": "sv-hjy7ndEkmCtn31ps",            "type": "state-versions"          },          "links": {            "related": "/api/v2/workspaces/ws-6jrRyVDv1J8zQMB5/current-state-version"          }        },        "current-configuration-version": {          "data": {            "id": "cv-hjy7ndEkmCtn31ps",            "type": "configuration-versions"          },          "links": {            "related": "/api/v2/configuration-versions/cv-hjy7ndEkmCtn31ps"          }        },        "current-assessment-result": {          "data": null        },        "organization": {          "data": {            "id": "my-organization",            "type": "organizations"          }        },        "outputs": {          "data": [            {              "id": "wsout-hjy7ndEkmCtn31ps",              "type": "workspace-outputs"            },            {              "id": "wsout-hjy7ndEkmCtn31ps",              "type": "workspace-outputs"            }          ],          "links": {            "related": "/api/v2/workspaces/ws-6jrRyVDv1J8zQMB5/current-state-version-outputs"          }        },        "project": {          "data": {            "id": "prj-hjy7ndEkmCtn31ps",            "type": "projects"          }        },        "readme": {          "data": null        },        "remote-state-consumers": {          "links": {            "related": "/api/v2/workspaces/ws-6jrRyVDv1J8zQMB5/relationships/remote-state-consumers"          }        },        "ssh-key": {          "data": {            "id": "sshkey-hjy7ndEkmCtn31ps",            "type": "ssh-keys"          },          "links": {            "related": "/api/v2/ssh-keys/sshkey-hjy7ndEkmCtn31ps"          }        },        "locked-by": {          "data": {            "id": "user-hjy7ndEkmCtn31ps",            "type": "users"          },          "links": {            "related": "/api/v2/users/user-hjy7ndEkmCtn31ps"          }        },        "vars": {          "data": [            {              "id": "var-hjy7ndEkmCtn31ps",              "type": "vars"            }          ]        },      }    },  ],  "links": {    "first": "https://app.terraform.io/api/v2/workspaces?page%5Bnumber%5D=1&page%5Bsize%5D=20",    "last": "https://app.terraform.io/api/v2/workspaces?page%5Bnumber%5D=1&page%5Bsize%5D=20",    "next": null,    "prev": null,    "self": "https://app.terraform.io/api/v2/workspaces?page%5Bnumber%5D=1&page%5Bsize%5D=20"  },  "meta": {    "pagination": {      "current-page": 1,      "next-page": null,      "page-size": 20,      "prev-page": null,      "total-count": 1,      "total-pages": 1    }  }}

Replace Remote State Consumers

PATCH /workspaces/:workspace_id/relationships/remote-state-consumers

ParameterDescription
:workspace_idThe workspace ID to replace remote state consumers for. Obtain this from theworkspace settings or theShow Workspace endpoint.

This endpoint updates the workspace's remote state consumers to beexactly the list of workspaces specified in the payload. It can only be used for workspaces whereglobal-remote-state is false.

This endpoint can only be used by teams with permission to manage workspaces for the entire organization — only those who canview the entire list of consumers canreplace the entire list. (More about permissions.) Teams with admin permissions on specific workspaces can still modify remote state consumers for those workspaces, but must use the add (POST) and remove (DELETE) endpoints listed below instead of this PATCH endpoint.

StatusResponseReason(s)
204No ContentSuccessfully updated remote state consumers
404JSON API error objectWorkspace not found, or user unauthorized to perform action
422JSON API error objectProblem with payload or request; details provided in the error object

Request Body

This PATCH endpoint requires a JSON object with the following properties as a request payload.

Properties without a default value are required.

Key pathTypeDefaultDescription
data[].typestringMust be"workspaces".
data[].idstringThe ID of a workspace to be set as a remote state consumer.

Sample Payload

{  "data": [    {      "id": "ws-7aiqKYf6ejMFdtWS",      "type": "workspaces"    }  ]}

Sample Request

$ curl \  --header "Authorization: Bearer $TOKEN" \  --header "Content-Type: application/vnd.api+json" \  --request PATCH \  --data @payload.json \  https://app.terraform.io/api/v2/workspaces/ws-UYv6RYM8fVhzeGG5/relationships/remote-state-consumers

Response

No response body.

Status code204.

Add Remote State Consumers

POST /workspaces/:workspace_id/relationships/remote-state-consumers

ParameterDescription
:workspace_idThe workspace ID to add remote state consumers for. Obtain this from theworkspace settings or theShow Workspace endpoint.

This endpoint adds one or more remote state consumers to the workspace. It can only be used for workspaces whereglobal-remote-state is false.

  • The workspaces specified as consumers must be readable to the API token that makes the request.
  • A workspace cannot be added as a consumer of itself. (A workspace can always read its own state, regardless of access settings.)
  • You can safely add a consumer workspace that is already present; it will be ignored, and the rest of the consumers in the request will be processed normally.
StatusResponseReason(s)
204No ContentSuccessfully updated remote state consumers
404JSON API error objectWorkspace not found, or user unauthorized to perform action
422JSON API error objectProblem with payload or request; details provided in the error object

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 pathTypeDefaultDescription
data[].typestringMust be"workspaces".
data[].idstringThe ID of a workspace to be set as a remote state consumer.

Sample Payload

{  "data": [    {      "id": "ws-7aiqKYf6ejMFdtWS",      "type": "workspaces"    }  ]}

Sample Request

$ curl \  --header "Authorization: Bearer $TOKEN" \  --header "Content-Type: application/vnd.api+json" \  --request POST \  --data @payload.json \  https://app.terraform.io/api/v2/workspaces/ws-UYv6RYM8fVhzeGG5/relationships/remote-state-consumers

Response

No response body.

Status code204.

Delete Remote State Consumers

DELETE /workspaces/:workspace_id/relationships/remote-state-consumers

ParameterDescription
:workspace_idThe workspace ID to remove remote state consumers for. Obtain this from theworkspace settings or theShow Workspace endpoint.

This endpoint removes one or more remote state consumers from a workspace, according to the contents of the payload. It can only be used for workspaces whereglobal-remote-state is false.

  • The workspaces specified as consumers must be readable to the API token that makes the request.
  • You can safely remove a consumer workspace that is already absent; it will be ignored, and the rest of the consumers in the request will be processed normally.
StatusResponseReason(s)
204No ContentSuccessfully updated remote state consumers
404JSON API error objectWorkspace not found, or user unauthorized to perform action
422JSON API error objectProblem with payload or request; details provided in the error object

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 pathTypeDefaultDescription
data[].typestringMust be"workspaces".
data[].idstringThe ID of a workspace to remove from the remote state consumers.

Sample Payload

{  "data": [    {      "id": "ws-7aiqKYf6ejMFdtWS",      "type": "workspaces"    }  ]}

Sample Request

$ curl \  --header "Authorization: Bearer $TOKEN" \  --header "Content-Type: application/vnd.api+json" \  --request DELETE \  --data @payload.json \  https://app.terraform.io/api/v2/workspaces/ws-UYv6RYM8fVhzeGG5/relationships/remote-state-consumers

Response

No response body.

Status code204.

Add flat string tags to a workspace

POST /workspaces/:workspace_id/relationships/tags

Refer toDefine project tags for information about supported tag values.

ParameterDescription
:workspace_idThe workspace ID to add tags to. Obtain this from theworkspace settings or theShow Workspace endpoint.
StatusResponseReason(s)
204No ContentSuccessfully added tags to workspace
404JSON API error objectWorkspace not found, or user unauthorized to perform action

Request Body

This POST endpoint requires a JSON object with the following properties as a request payload.

It is important to note thattype, as well as one ofidorattributes.name is required.

Key pathTypeDefaultDescription
data[].typestringMust be"tags".
data[].idstringThe ID of the tag to add.
data[].attributes.namestringThe name of the tag to add.

Sample Payload

{  "data": [    {      "type": "tags",      "attributes": {        "name": "foo"      }    },    {      "type": "tags",      "attributes": {        "name": "bar"      }    }  ]}

Sample Request

$ curl \  --header "Authorization: Bearer $TOKEN" \  --header "Content-Type: application/vnd.api+json" \  --request POST \  --data @payload.json \  https://app.terraform.io/api/v2/workspaces/workspace-2/relationships/tags

Sample Response

No response body.

Status code204.

Remove tags from workspace

This endpoint removes one or more tags from a workspace. The workspace must already exist, and tagelement that supplies anid attribute must exist. If thename attribute is used, and no matchingorganization tag is found, no action will occur for that entry. Tags removed from all workspaces will beremoved from the organization-wide list.

DELETE /workspaces/:workspace_id/relationships/tags

ParameterDescription
:workspace_idThe workspace ID to remove tags from. Obtain this from theworkspace settings or theShow Workspace endpoint.
StatusResponseReason(s)
204No ContentSuccessfully removed tags to workspace
404JSON API error objectWorkspace not found, or user unauthorized to perform action

Request Body

This POST endpoint requires a JSON object with the following properties as a request payload.

It is important to note thattype, as well as one ofidorattributes.name is required.

Key pathTypeDefaultDescription
data[].typestringMust be"tags".
data[].idstringThe ID of the tag to remove.
data[].attributes.namestringThe name of the tag to remove.

Sample Payload

{  "data": [    {      "type": "tags",      "id": "tag-Yfha4YpPievQ8wJw"    }  ]}

Sample Request

$ curl \  --header "Authorization: Bearer $TOKEN" \  --header "Content-Type: application/vnd.api+json" \  --request DELETE \  --data @payload.json \  https://app.terraform.io/api/v2/workspaces/workspace-2/relationships/tags

Sample Response

No response body.

Status code204.

Show data retention policy

Enterprise

This endpoint is exclusive to Terraform Enterprise and is not available in HCP Terraform.

GET /workspaces/:workspace_id/relationships/data-retention-policy

ParameterDescription
:workspace_idThe ID of the workspace to show the data retention policy for. Obtain this from theworkspace settings or by sending aGET request to the/workspaces endpoint.

This endpoint shows the data retention policy set explicitly on the workspace.When no data retention policy is set for the workspace, the endpoint returns the default policy configured for the organization. Refer toData Retention Policies for instructions on configuring data retention policies for workspaces.

Refer toData Retention Policy API in the Terraform Enterprise documentation for details.

Create or update data retention policy

Enterprise

This endpoint is exclusive to Terraform Enterprise and is not available in HCP Terraform.

POST /workspaces/:workspace_id/relationships/data-retention-policy

ParameterDescription
:workspace_idThe workspace ID to update the data retention policy for. Obtain this from theworkspace settings or by sending aGET request to the/workspaces endpoint.

This endpoint creates a data retention policy for a workspace or updates the existing policy.Refer toData Retention Policies for additional information.

Refer toData Retention Policy API in the Terraform Enterprise documentation for details.

Remove data retention policy

Enterprise

This endpoint is exclusive to Terraform Enterprise and is not available in HCP Terraform.

DELETE /workspaces/:workspace_id/relationships/data-retention-policy

ParameterDescription
:workspace_idThe workspace ID to remove the data retenetion policy for. Obtain this from theworkspace settings or by sending aGET request to the/workspaces endpoint.

This endpoint removes the data retention policy explicitly set on a workspace.When no data retention policy is set for the workspace, the endpoint returns the default policy configured for the organization. Refer toData Retention Policies for instructions on configuring data retention policies for organizations.

Read more aboutworkspace data retention policies.

Refer toData Retention Policy API in the Terraform Enterprise documentation for details.

Available Related Resources

The GET endpoints above can optionally return related resources, if requested withtheinclude query parameter. The following resource types are available:

Edit this page on GitHub

[8]ページ先頭

©2009-2025 Movatter.jp