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 v202507-1.View latest version.

This set of APIs covers create, update, list and delete operations on workspace variables.

Viewing variables requires permission to read variables for their workspace. Creating, updating, and deleting variables requires permission to read and write variables for their workspace. (More about permissions.)

Create a Variable

POST /workspaces/:workspace_id/vars

ParameterDescription
:workspace_idThe ID of the workspace to create the variable in.

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"vars".
data.attributes.keystringThe name of the variable.
data.attributes.valuestring""The value of the variable.
data.attributes.descriptionstringThe description of the variable.
data.attributes.categorystringWhether this is a Terraform or environment variable. Valid values are"terraform" or"env".
data.attributes.hclboolfalseWhether to evaluate the value of the variable as a string of HCL code. Has no effect for environment variables.
data.attributes.sensitiveboolfalseWhether the value is sensitive. If true then the variable is written once and not visible thereafter.

Deprecation warning: The customfilter properties are replaced by JSON APIrelationships and will be removed from future versions of the API!

Key pathTypeDefaultDescription
filter.workspace.namestringThe name of the workspace that owns the variable.
filter.organization.namestringThe 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    }  }}

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-4j8p6jX1w33MiDC7/vars

Sample Response

{  "data": {    "id":"var-EavQ1LztoRTQHSNT",    "type":"vars",    "attributes": {      "key":"some_key",      "value":"some_value",      "description":"some description",      "sensitive":false,      "category":"terraform",      "hcl":false,      "version-id":"1aa07d63ea8ff4df941c94ca9ddfd5d2bd04"    },    "relationships": {      "configurable": {        "data": {          "id":"ws-4j8p6jX1w33MiDC7",          "type":"workspaces"        },        "links": {          "related":"/api/v2/organizations/my-organization/workspaces/my-workspace"        }      }    },    "links": {      "self":"/api/v2/workspaces/ws-4j8p6jX1w33MiDC7/vars/var-EavQ1LztoRTQHSNT"    }  }}

List Variables

GET /workspaces/:workspace_id/vars

ParameterDescription
:workspace_idThe ID of the workspace to list variables for.

Sample Request

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

Sample Response

{  "data": [    {      "id":"var-AD4pibb9nxo1468E",      "type":"vars","attributes": {        "key":"name",        "value":"hello",        "description":"some description",        "sensitive":false,        "category":"terraform",        "hcl":false,        "version-id":"1aa07d63ea8ff4df941c94ca9ddfd5d2bd04"      },      "relationships": {        "configurable": {          "data": {            "id":"ws-cZE9LERN3rGPRAmH",            "type":"workspaces"          },          "links": {            "related":"/api/v2/organizations/my-organization/workspaces/my-workspace"          }        }      },      "links": {        "self":"/api/v2/workspaces/ws-cZE9LERN3rGPRAmH/vars/var-AD4pibb9nxo1468E"      }    }  ]}

Update Variables

PATCH /workspaces/:workspace_id/vars/:variable_id

ParameterDescription
:workspace_idThe ID of the workspace that owns the variable.
:variable_idThe ID of the variable to be updated.

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"vars".
data.idstringThe ID of the variable to update.
data.attributesobjectNew 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":"some 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/workspaces/ws-4j8p6jX1w33MiDC7/vars/var-yRmifb4PJj7cLkMG

Sample Response

{  "data": {    "id":"var-yRmifb4PJj7cLkMG",    "type":"vars",    "attributes": {      "key":"name",      "value":"mars",      "description":"some description",      "sensitive":false,      "category":"terraform",      "hcl":false,      "version-id":"1aa07d63ea8ff4df941c94ca9ddfd5d2bd04"    },    "relationships": {      "configurable": {        "data": {          "id":"ws-4j8p6jX1w33MiDC7",          "type":"workspaces"        },        "links": {          "related":"/api/v2/organizations/workspace-v2-06/workspaces/workspace-v2-06"        }      }    },    "links": {      "self":"/api/v2/workspaces/ws-4j8p6jX1w33MiDC7/vars/var-yRmifb4PJj7cLkMG"    }  }}

Delete Variables

DELETE /workspaces/:workspace_id/vars/:variable_id

ParameterDescription
:workspace_idThe ID of the workspace that owns the variable.
:variable_idThe 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/workspaces/ws-4j8p6jX1w33MiDC7/vars/var-yRmifb4PJj7cLkMG
Edit this page on GitHub

[8]ページ先頭

©2009-2025 Movatter.jp