Skip to main content
Glama

update_workspace_variable

Modify existing workspace variables in Terraform Cloud by updating specific attributes like name, value, category, or sensitivity while leaving unspecified settings 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
workspace_idYes
variable_idYes
paramsNo

Implementation Reference

  • The async handler function that implements the core logic for updating a Terraform Cloud workspace variable using a PATCH API request, including payload construction with Pydantic models.
    @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 input parameters (key, value, description, category, hcl, sensitive) for updating workspace variables, used as the 'params' argument in the handler.
    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", )
  • Registers the 'update_workspace_variable' handler as an MCP tool in the FastMCP server, using the write_tool_config which enables it for non-read-only mode.
    mcp.tool(**write_tool_config)(variables.update_workspace_variable)

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