Skip to main content
Glama
severity1

terraform-cloud-mcp

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)
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations indicate readOnlyHint=false, consistent with the 'update' action. The description adds valuable behavioral context beyond annotations by explaining the partial update behavior ('Only specified attributes will be updated'), specifying the API endpoint, and noting that sensitive values can be updated. It does not mention authentication needs or rate limits, but provides useful operational details.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured with a clear purpose statement, behavioral details, parameter breakdown, and return information. It is appropriately sized but includes a 'See' reference that, while helpful, slightly reduces conciseness. Most sentences earn their place by adding value.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the mutation nature (annotations show readOnlyHint=false), 3 parameters with no schema descriptions, and no output schema, the description is highly complete. It covers purpose, usage behavior, all parameters with semantics, return values, and provides a documentation reference, leaving no significant gaps for tool invocation.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

With 0% schema description coverage, the description fully compensates by detailing all 3 parameters: workspace_id and variable_id (with format examples), and params (listing all 6 sub-parameters with clear explanations). This adds significant meaning beyond the bare schema, making parameter usage unambiguous.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('Update an existing workspace variable') and resource ('workspace variable'), distinguishing it from sibling tools like 'create_workspace_variable' (for creation) and 'list_workspace_variables' (for listing). It precisely defines the operation without being tautological.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides clear context for usage by specifying it updates existing variables and that only specified attributes are changed, implying it should be used for modifications rather than creation. However, it does not explicitly state when not to use it or name alternatives like 'create_workspace_variable' for new variables.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other 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