Skip to main content
Glama

create_workspace_variable

Create and configure Terraform or environment variables within a workspace, allowing customization of HCL code, descriptions, and sensitive value flags for enhanced infrastructure management.

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

Implementation Reference

  • The handler function that implements the core logic for creating a workspace variable by constructing an API payload and making a POST request to the Terraform Cloud API.
    @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 )
  • Registration of the create_workspace_variable tool in the MCP server with write permissions configuration.
    mcp.tool(**write_tool_config)(variables.create_workspace_variable)
  • Pydantic model defining the input parameters for workspace variables, used for validation in the create_workspace_variable tool.
    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", )

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