assign_variable_set_to_workspaces
Assign a Terraform Cloud variable set to multiple workspaces to make shared variables available for infrastructure management.
Instructions
Assign a variable set to one or more workspaces.
Makes the variables in a variable set available to the specified workspaces. Variables from variable sets take precedence over workspace variables if the variable set has priority enabled.
API endpoint: POST /varsets/{varset_id}/relationships/workspaces
Args: varset_id: The ID of the variable set (format: "varset-xxxxxxxx") workspace_ids: List of workspace IDs (format: ["ws-xxxxxxxx", ...])
Returns: Empty response with HTTP 204 status code if successful
See: docs/tools/variables.md#assign-variable-set-to-workspaces for reference documentation
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| varset_id | Yes | ||
| workspace_ids | Yes |
Implementation Reference
- The handler function that implements the tool logic: assigns a variable set to specified workspaces by constructing a relationships payload and making a POST request to the Terraform Cloud API endpoint /varsets/{varset_id}/relationships/workspaces.async def assign_variable_set_to_workspaces( varset_id: str, workspace_ids: List[str] ) -> APIResponse: """Assign a variable set to one or more workspaces. Makes the variables in a variable set available to the specified workspaces. Variables from variable sets take precedence over workspace variables if the variable set has priority enabled. API endpoint: POST /varsets/{varset_id}/relationships/workspaces Args: varset_id: The ID of the variable set (format: "varset-xxxxxxxx") workspace_ids: List of workspace IDs (format: ["ws-xxxxxxxx", ...]) Returns: Empty response with HTTP 204 status code if successful See: docs/tools/variables.md#assign-variable-set-to-workspaces for reference documentation """ # Build relationships payload relationships_data = [] for workspace_id in workspace_ids: relationships_data.append({"id": workspace_id, "type": "workspaces"}) payload = {"data": relationships_data} endpoint = f"varsets/{varset_id}/relationships/workspaces" return await api_request(endpoint, method="POST", data=payload)
- terraform_cloud_mcp/server.py:136-136 (registration)Registers the assign_variable_set_to_workspaces tool with the MCP server using mcp.tool decorator, configured with write permissions (write_tool_config).mcp.tool(**write_tool_config)(variables.assign_variable_set_to_workspaces)