get_current_state_version
Retrieve the current state version for a Terraform workspace to access input state details and download URLs, essential for managing infrastructure operations with Terraform Cloud.
Instructions
Get the current state version for a workspace.
Retrieves the current state version for a workspace, which is the input state when running terraform operations.
API endpoint: GET /workspaces/:workspace_id/current-state-version
Args: workspace_id: The ID of the workspace (format: "ws-xxxxxxxx")
Returns: The current state version including details and download URLs
See: docs/tools/state_versions.md for reference documentation
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| workspace_id | Yes |
Implementation Reference
- The main handler function that executes the tool logic: validates the workspace_id using CurrentStateVersionRequest model and makes an API request to /workspaces/{workspace_id}/current-state-version to fetch the current state version.@handle_api_errors async def get_current_state_version(workspace_id: str) -> APIResponse: """Get the current state version for a workspace. Retrieves the current state version for a workspace, which is the input state when running terraform operations. API endpoint: GET /workspaces/:workspace_id/current-state-version Args: workspace_id: The ID of the workspace (format: "ws-xxxxxxxx") Returns: The current state version including details and download URLs See: docs/tools/state_versions.md for reference documentation """ # Validate parameters params = CurrentStateVersionRequest(workspace_id=workspace_id) # Make API request return await api_request(f"workspaces/{params.workspace_id}/current-state-version")
- Pydantic model for input schema validation: defines and validates the workspace_id parameter with regex pattern for workspace IDs.class CurrentStateVersionRequest(APIRequest): """Request model for retrieving a workspace's current state version. Used to validate the workspace ID parameter for current state version API requests. Reference: https://developer.hashicorp.com/terraform/cloud-docs/api-docs/state-versions#get-current-state-version See: docs/models/state_versions.md for reference """ workspace_id: str = Field( ..., description="The ID of the workspace to retrieve the current state version for", pattern=r"^ws-[a-zA-Z0-9]{16}$", # Standard workspace ID pattern )
- terraform_cloud_mcp/server.py:114-114 (registration)Registers the get_current_state_version function from the state_versions module as an MCP tool using FastMCP's tool decorator.mcp.tool()(state_versions.get_current_state_version)