get_apply_logs
Retrieve raw log output from Terraform Cloud apply operations to analyze resource changes and identify errors. Simplifies debugging by fetching detailed logs for specific apply IDs.
Instructions
Retrieve logs from an apply.
Gets the raw log output from a Terraform Cloud apply operation, providing detailed information about resource changes and any errors.
API endpoint: Uses the log-read-url from GET /applies/{apply_id}
Args: apply_id: The ID of the apply to retrieve logs for (format: "apply-xxxxxxxx")
Returns: The raw logs from the apply operation. The redirect to the log file is automatically followed.
See: docs/tools/apply.md for reference documentation
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| apply_id | Yes |
Implementation Reference
- The handler function that implements the get_apply_logs tool. It validates the apply_id, fetches apply details to get the log-read-url, and retrieves the raw logs.@handle_api_errors async def get_apply_logs(apply_id: str) -> APIResponse: """Retrieve logs from an apply. Gets the raw log output from a Terraform Cloud apply operation, providing detailed information about resource changes and any errors. API endpoint: Uses the log-read-url from GET /applies/{apply_id} Args: apply_id: The ID of the apply to retrieve logs for (format: "apply-xxxxxxxx") Returns: The raw logs from the apply operation. The redirect to the log file is automatically followed. See: docs/tools/apply.md for reference documentation """ # Validate parameters using existing model params = ApplyRequest(apply_id=apply_id) # First get apply details to get the log URL apply_details = await api_request(f"applies/{params.apply_id}") # Extract log read URL log_read_url = ( apply_details.get("data", {}).get("attributes", {}).get("log-read-url") ) if not log_read_url: return {"error": "No log URL available for this apply"} # Use the enhanced api_request to fetch logs from the external URL return await api_request(log_read_url, external_url=True, accept_text=True)
- terraform_cloud_mcp/server.py:91-91 (registration)Registration of the get_apply_logs tool in the MCP server.mcp.tool()(applies.get_apply_logs)
- Pydantic model ApplyRequest used for input validation of the apply_id parameter in the handler.class ApplyRequest(APIRequest): """Request model for retrieving an apply. Used to validate the apply ID parameter for API requests. Reference: https://developer.hashicorp.com/terraform/cloud-docs/api-docs/applies#show-an-apply 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 to retrieve", pattern=r"^apply-[a-zA-Z0-9]{16}$", # Standard apply ID pattern )