get_errored_state
Retrieve and access state data from a failed Terraform apply for recovery. Use the tool to fetch errored state information via the apply ID, ensuring continued infrastructure management.
Instructions
Retrieve the errored state from a failed apply.
Gets information about a state file that failed to upload during an apply, providing access to the state data for recovery purposes.
API endpoint: GET /applies/{apply_id}/errored-state
Args: apply_id: The ID of the apply with a failed state upload (format: "apply-xxxxxxxx")
Returns: Information about the errored state including access details. The redirect to the state file is automatically followed.
See: docs/tools/apply.md for reference documentation
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| apply_id | Yes |
Implementation Reference
- The main handler function that implements the logic for retrieving the errored state from a failed Terraform Cloud apply. It validates the input using ApplyErroredStateRequest and calls the API endpoint.@handle_api_errors async def get_errored_state(apply_id: str) -> APIResponse: """Retrieve the errored state from a failed apply. Gets information about a state file that failed to upload during an apply, providing access to the state data for recovery purposes. API endpoint: GET /applies/{apply_id}/errored-state Args: apply_id: The ID of the apply with a failed state upload (format: "apply-xxxxxxxx") Returns: Information about the errored state including access details. The redirect to the state file is automatically followed. See: docs/tools/apply.md for reference documentation """ # Validate parameters params = ApplyErroredStateRequest(apply_id=apply_id) # Make API request - redirect handling happens automatically in the API client return await api_request(f"applies/{params.apply_id}/errored-state")
- Pydantic input schema model used for validating the apply_id parameter in the get_errored_state tool.class ApplyErroredStateRequest(APIRequest): """Request model for retrieving an apply's errored state. Used to validate the apply ID parameter for errored state API requests. Reference: https://developer.hashicorp.com/terraform/cloud-docs/api-docs/applies#recover-a-failed-state-upload-after-applying See: docs/models/apply.md for reference """ apply_id: str = Field( ..., # No alias needed as field name matches API parameter description="The ID of the apply with a failed state upload", pattern=r"^apply-[a-zA-Z0-9]{16}$", # Standard apply ID pattern )
- terraform_cloud_mcp/server.py:90-90 (registration)Tool registration in the MCP server using the FastMCP decorator, importing the handler from tools.applies.mcp.tool()(applies.get_errored_state)