Skip to main content
Glama

update_workspace_variable

Update workspace variables in Terraform Cloud by specifying the workspace ID, variable ID, and parameters like key, value, description, category, HCL, or sensitivity. Modify only the specified attributes while leaving others unchanged.

Instructions

Update an existing workspace variable.

Modifies the configuration of an existing workspace variable. Only specified attributes will be updated; unspecified attributes remain unchanged.

API endpoint: PATCH /workspaces/{workspace_id}/vars/{variable_id}

Args: workspace_id: The ID of the workspace (format: "ws-xxxxxxxx") variable_id: The ID of the variable (format: "var-xxxxxxxx")

params: Variable parameters to update (optional): - key: New variable name/key - value: New variable value - description: New description of the variable - category: New variable category ("terraform" or "env") - hcl: Whether the value is HCL code (terraform variables only) - sensitive: Whether the variable value is sensitive

Returns: The updated variable with all current settings and configuration

See: docs/tools/variables.md#update-workspace-variable for reference documentation

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
paramsNo
variable_idYes
workspace_idYes

Implementation Reference

  • The handler function that implements the core logic for updating a Terraform Cloud workspace variable. It constructs a Pydantic model from parameters, creates an API payload, and sends a PATCH request to the appropriate endpoint.
    @handle_api_errors async def update_workspace_variable( workspace_id: str, variable_id: str, params: Optional[WorkspaceVariableParams] = None, ) -> APIResponse: """Update an existing workspace variable. Modifies the configuration of an existing workspace variable. Only specified attributes will be updated; unspecified attributes remain unchanged. API endpoint: PATCH /workspaces/{workspace_id}/vars/{variable_id} Args: workspace_id: The ID of the workspace (format: "ws-xxxxxxxx") variable_id: The ID of the variable (format: "var-xxxxxxxx") params: Variable parameters to update (optional): - key: New variable name/key - value: New variable value - description: New description of the variable - category: New variable category ("terraform" or "env") - hcl: Whether the value is HCL code (terraform variables only) - sensitive: Whether the variable value is sensitive Returns: The updated variable with all current settings and configuration See: docs/tools/variables.md#update-workspace-variable for reference documentation """ param_dict = params.model_dump(exclude_none=True) if params else {} request = WorkspaceVariableUpdateRequest( workspace_id=workspace_id, variable_id=variable_id, **param_dict ) payload = create_api_payload( resource_type="vars", model=request, exclude_fields={"workspace_id", "variable_id"}, ) return await api_request( f"workspaces/{workspace_id}/vars/{variable_id}", method="PATCH", data=payload )
  • Pydantic model defining the request structure and validation for updating workspace variables, including required IDs and optional update fields.
    class WorkspaceVariableUpdateRequest(APIRequest): """Request model for updating workspace variables. Used for PATCH /workspaces/:workspace_id/vars/:variable_id endpoint. Reference: https://developer.hashicorp.com/terraform/cloud-docs/api-docs/workspace-variables See: docs/models/variables.md for reference """ workspace_id: str = Field( ..., description="The workspace ID", pattern=r"^ws-[a-zA-Z0-9]{16}$", ) variable_id: str = Field( ..., description="The variable ID", pattern=r"^var-[a-zA-Z0-9]{16}$", ) key: Optional[str] = Field( None, description="Variable name/key", min_length=1, max_length=255, ) value: Optional[str] = Field( None, description="Variable value", max_length=256000, ) description: Optional[str] = Field( None, description="Description of the variable", max_length=512, ) category: Optional[VariableCategory] = Field( None, description="Variable category (terraform or env)", ) hcl: Optional[bool] = Field( None, description="Whether the value is HCL code (only valid for terraform variables)", ) sensitive: Optional[bool] = Field( None, description="Whether the variable value is sensitive", )
  • MCP tool registration for update_workspace_variable, configured as a write operation (enabled unless read-only mode).
    mcp.tool(**write_tool_config)(variables.update_workspace_variable)
  • Pydantic model for optional parameters passed to the update_workspace_variable handler, used to populate the update request.
    class WorkspaceVariableParams(APIRequest): """Parameters for workspace variable operations without routing fields. This model provides all optional parameters for creating or updating workspace variables, separating configuration parameters from routing information like workspace ID and variable ID. Reference: https://developer.hashicorp.com/terraform/cloud-docs/api-docs/workspace-variables See: docs/models/variables.md for reference """ key: Optional[str] = Field( None, description="Variable name/key", min_length=1, max_length=255, ) value: Optional[str] = Field( None, description="Variable value", max_length=256000, ) description: Optional[str] = Field( None, description="Description of the variable", max_length=512, ) category: Optional[VariableCategory] = Field( None, description="Variable category (terraform or env)", ) hcl: Optional[bool] = Field( None, description="Whether the value is HCL code (only valid for terraform variables)", ) sensitive: Optional[bool] = Field( None, description="Whether the variable value is sensitive", )

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/severity1/terraform-cloud-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server