get_apply_logs
Retrieve detailed logs from Terraform Cloud apply operations to monitor resource changes and identify errors during infrastructure deployment.
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 core handler function for the get_apply_logs tool. It validates the apply_id using ApplyRequest model, fetches apply details to extract the log-read-url, and retrieves the logs via API request.@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)
- Pydantic input schema model ApplyRequest used to validate 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 )
- terraform_cloud_mcp/server.py:91-91 (registration)MCP tool registration for the get_apply_logs function using FastMCP's tool decorator.mcp.tool()(applies.get_apply_logs)