Skip to main content
Glama
severity1

terraform-cloud-mcp

create_workspace_variable

Add Terraform or environment variables to a workspace, optionally marking them as sensitive to protect values.

Instructions

Create a new variable in a workspace.

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

API endpoint: POST /workspaces/{workspace_id}/vars

Args: workspace_id: The ID of the workspace (format: "ws-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-workspace-variable for reference documentation

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
workspace_idYes
keyYes
categoryYes
paramsNo

Implementation Reference

  • The async handler function implementing the core logic for creating a workspace variable via Terraform Cloud API, using Pydantic models for input validation and API payload construction.
    @handle_api_errors
    async def create_workspace_variable(
        workspace_id: str,
        key: str,
        category: str,
        params: Optional[WorkspaceVariableParams] = None,
    ) -> APIResponse:
        """Create a new variable in a workspace.
    
        Creates a new Terraform or environment variable within a workspace.
        Variables can be marked as sensitive to hide their values.
    
        API endpoint: POST /workspaces/{workspace_id}/vars
    
        Args:
            workspace_id: The ID of the workspace (format: "ws-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-workspace-variable for reference documentation
        """
        param_dict = params.model_dump(exclude_none=True) if params else {}
        request = WorkspaceVariableCreateRequest(
            workspace_id=workspace_id,
            key=key,
            category=VariableCategory(category),
            **param_dict,
        )
    
        payload = create_api_payload(
            resource_type="vars", model=request, exclude_fields={"workspace_id"}
        )
    
        return await api_request(
            f"workspaces/{workspace_id}/vars", method="POST", data=payload
        )
  • Pydantic model defining optional parameters (value, description, hcl, sensitive) for workspace variable creation, used in the tool handler for input schema and validation.
    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",
        )
  • Enum defining valid category values ('terraform', 'env') for workspace variables, used in input validation.
    class VariableCategory(str, Enum):
        """Variable category options for workspace variables.
    
        Defines the type of variable:
        - TERRAFORM: Terraform input variables available in configuration
        - ENV: Environment variables available during plan/apply operations
    
        Reference: https://developer.hashicorp.com/terraform/cloud-docs/api-docs/workspace-variables
    
        See:
            docs/models/variables.md for reference
        """
    
        TERRAFORM = "terraform"
        ENV = "env"
  • Tool registration in the FastMCP server using the create_workspace_variable handler function, configured with write permissions.
    mcp.tool(**write_tool_config)(variables.create_workspace_variable)
Behavior4/5

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

Annotations only provide readOnlyHint=false, confirming this is a mutation. The description adds valuable behavioral context: it specifies the API endpoint (POST method), mentions sensitive value handling, and describes the return format. It doesn't cover rate limits, authentication needs, or error conditions, but provides solid operational context beyond annotations.

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?

Well-structured with clear sections (purpose, API endpoint, args, params, returns, reference). Most sentences earn their place by providing essential information. Slightly verbose with the 'See' reference line, but overall efficient for a complex creation tool.

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 mutation tool with no output schema and 0% schema description coverage, the description provides strong coverage: clear purpose, parameter details, return format, and API endpoint. Missing elements include error handling, authentication requirements, and rate limits, but it's substantially complete for core functionality.

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 carries full burden. It comprehensively explains all 4 parameters: workspace_id format, key purpose, category options, and details all params sub-fields with their purposes. The description provides complete parameter semantics that the schema lacks.

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 workspace'), and scope ('Terraform or environment variable'). It distinguishes from sibling tools like 'create_variable_in_variable_set' by specifying workspace context and from 'update_workspace_variable' by being a creation operation.

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 about when to use this tool (creating new workspace variables) and mentions key capabilities like marking variables as sensitive. However, it doesn't explicitly state when NOT to use it or name specific alternatives like 'create_variable_in_variable_set' for variable sets instead of workspaces.

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