- Terraform Enterprise
- 1.1.x (latest)
- 1.0.x
- v202507-1
- v202506-1
- v202505-1
- v202504-1
- v202503-1
- v202502-2
- v202502-1
- v202501-1
- v202411-2
- v202410-1
- v202409-3
- v202409-2
- v202409-1
- v202408-1
- No versions of this document exist before v202408-1. Click below to redirect to the version homepage.
- v202407-1
- v202406-1
- v202405-1
- v202404-2
- v202404-1
- v202402-2
- v202402-1
- v202401-2
- v202401-1
- v202312-1
- v202311-1
- v202310-1
- v202309-1
- v202308-1
- v202307-1
- v202306-1
- v202305-2
- v202305-1
- v202304-1
- v202303-1
- v202302-1
- v202301-2
- v202301-1
- v202212-2
- v202212-1
- v202211-1
- v202210-1
- v202209-2
- v202209-1
- v202208-3
- v202208-2
- v202208-1
- v202207-2
- v202207-1
- v202206-1
Variables API
Important: The Variables API isdeprecated and will be removed in a future release. All existing integrations with this API should transition to theWorkspace Variables API.
This set of APIs covers create, update, list and delete operations on variables.
Create a Variable
POST /vars
Request Body
This POST endpoint requires a JSON object with the following properties as a request payload.
Properties without a default value are required.
| Key path | Type | Default | Description |
|---|---|---|---|
data.type | string | Must be"vars". | |
data.attributes.key | string | The name of the variable. | |
data.attributes.value | string | "" | The value of the variable. |
data.attributes.description | string | The description of the variable. | |
data.attributes.category | string | Whether this is a Terraform or environment variable. Valid values are"terraform" or"env". | |
data.attributes.hcl | bool | false | Whether to evaluate the value of the variable as a string of HCL code. Has no effect for environment variables. |
data.attributes.sensitive | bool | false | Whether the value is sensitive. If true then the variable is written once and not visible thereafter. |
data.relationships.workspace.data.type | string | Must be"workspaces". | |
data.relationships.workspace.data.id | string | The ID of the workspace that owns the variable. Obtain workspace IDs from theworkspace settings or theShow Workspace endpoint. |
Deprecation warning: The customfilter properties are replaced by JSON APIrelationships and will be removed from future versions of the API!
| Key path | Type | Default | Description |
|---|---|---|---|
filter.workspace.name | string | The name of the workspace that owns the variable. | |
filter.organization.name | string | The name of the organization that owns the workspace. |
Sample Payload
{ "data": { "type":"vars", "attributes": { "key":"some_key", "value":"some_value", "description":"some description", "category":"terraform", "hcl":false, "sensitive":false }, "relationships": { "workspace": { "data": { "id":"ws-4j8p6jX1w33MiDC7", "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/varsSample Response
{ "data": { "id":"var-EavQ1LztoRTQHSNT", "type":"vars", "attributes": { "key":"some_key", "value":"some_value", "description":"some description", "sensitive":false, "category":"terraform", "hcl":false }, "relationships": { "configurable": { "data": { "id":"ws-4j8p6jX1w33MiDC7", "type":"workspaces" }, "links": { "related":"/api/v2/organizations/my-organization/workspaces/my-workspace" } } }, "links": { "self":"/api/v2/vars/var-EavQ1LztoRTQHSNT" } }}List Variables
GET /vars
Query Parameters
These are standard URL query parameters. Remember to percent-encode[ as%5B and] as%5D if your tooling doesn't automatically encode URLs.
| Parameter | Description |
|---|---|
filter[workspace][name] | Optional The name of one workspace to list variables for. If included, you must also include the organization name filter. |
filter[organization][name] | Optional The name of the organization that owns the desired workspace. If included, you must also included the workspace name filter. |
These two parameters are optional but linked; if you include one, you must include both. Without a filter, this method lists variables for all workspaces where you have permission to read variables. (More about permissions.)
Sample Request
$ curl \ --header "Authorization: Bearer $TOKEN" \ --header "Content-Type: application/vnd.api+json" \"https://app.terraform.io/api/v2/vars?filter%5Borganization%5D%5Bname%5D=my-organization&filter%5Bworkspace%5D%5Bname%5D=my-workspace"# ?filter[organization][name]=my-organization&filter[workspace][name]=demo01Sample Response
{ "data": [ { "id":"var-AD4pibb9nxo1468E", "type":"vars","attributes": { "key":"name", "value":"hello", "description":"some description", "sensitive":false, "category":"terraform", "hcl":false }, "relationships": { "configurable": { "data": { "id":"ws-cZE9LERN3rGPRAmH", "type":"workspaces" }, "links": { "related":"/api/v2/organizations/my-organization/workspaces/my-workspace" } } }, "links": { "self":"/api/v2/vars/var-AD4pibb9nxo1468E" } } ]}Update Variables
PATCH /vars/:variable_id
| Parameter | Description |
|---|---|
:variable_id | The ID of the variable to be updated. |
Request Body
This POST endpoint requires a JSON object with the following properties as a request payload.
Properties without a default value are required.
| Key path | Type | Default | Description |
|---|---|---|---|
data.type | string | Must be"vars". | |
data.id | string | The ID of the variable to update. | |
data.attributes | object | New attributes for the variable. This object can includekey,value,description,category,hcl, andsensitive properties, which are described above undercreate a variable. All of these properties are optional; if omitted, a property will be left unchanged. |
Sample Payload
{ "data": { "id":"var-yRmifb4PJj7cLkMG", "attributes": { "key":"name", "value":"mars", "description": "new description", "category":"terraform", "hcl": false, "sensitive": false }, "type":"vars" }}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/vars/var-yRmifb4PJj7cLkMGSample Response
{ "data": { "id":"var-yRmifb4PJj7cLkMG", "type":"vars", "attributes": { "key":"name", "value":"mars", "description":"new description", "sensitive":false, "category":"terraform", "hcl":false }, "relationships": { "configurable": { "data": { "id":"ws-4j8p6jX1w33MiDC7", "type":"workspaces" }, "links": { "related":"/api/v2/organizations/workspace-v2-06/workspaces/workspace-v2-06" } } }, "links": { "self":"/api/v2/vars/var-yRmifb4PJj7cLkMG" } }}Delete Variables
DELETE /vars/:variable_id
| Parameter | Description |
|---|---|
:variable_id | The ID of the variable to be deleted. |
Sample Request
$ curl \ --header "Authorization: Bearer $TOKEN" \ --header "Content-Type: application/vnd.api+json" \ --request DELETE \ https://app.terraform.io/api/v2/vars/var-yRmifb4PJj7cLkMG