update_variable_in_variable_set
Modify an existing variable's configuration within a Terraform Cloud variable set. Update attributes like name, value, description, category, HCL status, or sensitivity while keeping unspecified settings unchanged.
Instructions
Update an existing variable in a variable set.
Modifies the configuration of an existing variable within a variable set. Only specified attributes will be updated; unspecified attributes remain unchanged.
API endpoint: PATCH /varsets/{varset_id}/relationships/vars/{var_id}
Args: varset_id: The ID of the variable set (format: "varset-xxxxxxxx") var_id: The ID of the variable (format: "var-xxxxxxxx")
Returns: The updated variable with all current settings and configuration
See: docs/tools/variables.md#update-variable-in-variable-set for reference documentation
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| varset_id | Yes | ||
| var_id | Yes | ||
| params | No |
Implementation Reference
- The core handler function that executes the tool by sending a PATCH request to the Terraform Cloud API to update the specified variable in the variable set.async def update_variable_in_variable_set( varset_id: str, var_id: str, params: Optional[VariableSetVariableParams] = None, ) -> APIResponse: """Update an existing variable in a variable set. Modifies the configuration of an existing variable within a variable set. Only specified attributes will be updated; unspecified attributes remain unchanged. API endpoint: PATCH /varsets/{varset_id}/relationships/vars/{var_id} Args: varset_id: The ID of the variable set (format: "varset-xxxxxxxx") var_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-variable-in-variable-set for reference documentation """ param_dict = params.model_dump(exclude_none=True) if params else {} payload = {"data": {"type": "vars", "attributes": param_dict}} return await api_request( f"varsets/{varset_id}/relationships/vars/{var_id}", method="PATCH", data=payload )
- Pydantic model defining the optional input parameters (key, value, description, category, hcl, sensitive) for updating a variable in a variable set.class VariableSetVariableParams(APIRequest): """Parameters for variable set variable operations without routing fields. This model provides all optional parameters for creating or updating variables within variable sets, separating configuration parameters from routing information like variable set ID and variable ID. Reference: https://developer.hashicorp.com/terraform/cloud-docs/api-docs/variable-sets 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", )
- terraform_cloud_mcp/server.py:144-144 (registration)FastMCP tool registration line that registers the update_variable_in_variable_set handler function with write permissions configuration.mcp.tool(**write_tool_config)(variables.update_variable_in_variable_set)