Skip to main content
Glama

create_variable_in_variable_set

Add a Terraform or environment variable to a variable set in Terraform Cloud. Specify sensitive values or HCL code. Use API endpoint POST /varsets/{varset_id}/relationships/vars.

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
categoryYes
keyYes
paramsNo
varset_idYes

Implementation Reference

  • The async handler function that executes the core logic: constructs payload from inputs and calls the Terraform Cloud API to create the variable.
    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 the optional input parameters (value, description, hcl, sensitive, etc.) for the tool, used for validation.
    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", )
  • Registers the tool with MCP server using the handler function from the variables module, with write permissions config.
    mcp.tool(**write_tool_config)(variables.create_variable_in_variable_set)

Other Tools

Related 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