Skip to main content
Glama
severity1

terraform-cloud-mcp

create_variable_in_variable_set

Add Terraform or environment variables to variable sets in Terraform Cloud, with options to mark them as sensitive or include HCL code.

Instructions

Create a new variable in a variable set.

Creates a new Terraform or environment variable within a variable set. Variables can be marked as sensitive to hide their values.

API endpoint: POST /varsets/{varset_id}/relationships/vars

Args: varset_id: The ID of the variable set (format: "varset-xxxxxxxx") key: The variable name/key category: Variable category ("terraform" or "env")

params: Additional variable parameters (optional):
    - value: Variable value
    - description: Description of the variable
    - hcl: Whether the value is HCL code (terraform variables only)
    - sensitive: Whether the variable value is sensitive

Returns: The created variable with its configuration and metadata

See: docs/tools/variables.md#create-variable-in-variable-set for reference documentation

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
varset_idYes
keyYes
categoryYes
paramsNo

Implementation Reference

  • The core handler function that executes the tool logic: constructs payload from inputs and sends POST request to Terraform Cloud API endpoint /varsets/{varset_id}/relationships/vars to create a variable in the variable set.
    async def create_variable_in_variable_set(
        varset_id: str,
        key: str,
        category: str,
        params: Optional[VariableSetVariableParams] = None,
    ) -> APIResponse:
        """Create a new variable in a variable set.
    
        Creates a new Terraform or environment variable within a variable set.
        Variables can be marked as sensitive to hide their values.
    
        API endpoint: POST /varsets/{varset_id}/relationships/vars
    
        Args:
            varset_id: The ID of the variable set (format: "varset-xxxxxxxx")
            key: The variable name/key
            category: Variable category ("terraform" or "env")
    
            params: Additional variable parameters (optional):
                - value: Variable value
                - description: Description of the variable
                - hcl: Whether the value is HCL code (terraform variables only)
                - sensitive: Whether the variable value is sensitive
    
        Returns:
            The created variable with its configuration and metadata
    
        See:
            docs/tools/variables.md#create-variable-in-variable-set for reference documentation
        """
        # Create a temporary request-like structure for the variable
        # Note: We don't have specific models for variable set variables yet
        var_data = {
            "key": key,
            "category": VariableCategory(category).value,
        }
    
        if params:
            param_dict = params.model_dump(exclude_none=True)
            var_data.update(param_dict)
    
        payload = {"data": {"type": "vars", "attributes": var_data}}
    
        return await api_request(
            f"varsets/{varset_id}/relationships/vars", method="POST", data=payload
        )
  • Pydantic model defining optional input parameters (value, description, hcl, sensitive, etc.) for the create_variable_in_variable_set tool, used for validation and serialization.
    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",
        )
  • Registration of the tool in the MCP server using FastMCP, with write permissions config.
    mcp.tool(**write_tool_config)(variables.create_variable_in_variable_set)
Behavior4/5

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

The description adds valuable behavioral context beyond the readOnlyHint annotation. It explains that variables can be marked as sensitive to hide values, mentions the specific API endpoint being called, and provides reference documentation. While it doesn't cover rate limits or authentication needs, it adds meaningful operational context.

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 clear sections (purpose, parameters, returns, reference). While slightly longer than minimal, every sentence adds value. The front-loaded purpose statement is clear, and the parameter documentation is organized efficiently.

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

Completeness4/5

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

For a creation tool with no output schema and 0% schema description coverage, the description provides comprehensive context. It covers purpose, parameters, return value description, and reference documentation. The main gap is the lack of explicit error conditions or response format details, but overall it's quite complete.

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 providing detailed parameter information. It explains all 4 parameters, their purposes, formats, and optional sub-parameters. The description adds significant value beyond what the bare schema provides, making parameter usage clear.

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 ('Create a new variable'), resource ('in a variable set'), and scope ('Terraform or environment variable'). It distinguishes this tool from sibling tools like 'create_workspace_variable' by specifying it operates on variable sets rather than workspaces.

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

Usage Guidelines3/5

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

The description implies usage context by mentioning variable sets and variable types, but doesn't explicitly state when to use this tool versus alternatives like 'create_workspace_variable' or 'update_variable_in_variable_set'. It provides some guidance about sensitive variables but lacks explicit when/when-not directives.

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