get_plan_logs
Retrieve raw log output from Terraform Cloud plan operations using the plan ID, enabling detailed analysis of the execution plan and infrastructure changes.
Instructions
Retrieve logs from a plan.
Gets the raw log output from a Terraform Cloud plan operation, providing detailed information about the execution plan.
API endpoint: Uses the log-read-url from GET /plans/{plan_id}
Args: plan_id: The ID of the plan to retrieve logs for (format: "plan-xxxxxxxx")
Returns: The raw logs from the plan operation. The redirect to the log file is automatically followed.
See: docs/tools/plan.md for reference documentation
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| plan_id | Yes |
Implementation Reference
- The main handler function for the 'get_plan_logs' tool. It fetches plan details to extract the log-read-url and then retrieves the raw logs from that URL, handling redirects and errors via decorators.@handle_api_errors async def get_plan_logs(plan_id: str) -> APIResponse: """Retrieve logs from a plan. Gets the raw log output from a Terraform Cloud plan operation, providing detailed information about the execution plan. API endpoint: Uses the log-read-url from GET /plans/{plan_id} Args: plan_id: The ID of the plan to retrieve logs for (format: "plan-xxxxxxxx") Returns: The raw logs from the plan operation. The redirect to the log file is automatically followed. See: docs/tools/plan.md for reference documentation """ # Validate parameters using existing model params = PlanRequest(plan_id=plan_id) # First get plan details to get the log URL plan_details = await api_request(f"plans/{params.plan_id}") # Extract log read URL log_read_url = ( plan_details.get("data", {}).get("attributes", {}).get("log-read-url") ) if not log_read_url: return {"error": "No log URL available for this plan"} # 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 (PlanRequest) used to validate the 'plan_id' parameter in the get_plan_logs handler.class PlanRequest(APIRequest): """Request model for retrieving a plan. Used to validate the plan ID parameter for API requests. Reference: https://developer.hashicorp.com/terraform/cloud-docs/api-docs/plans#show-a-plan See: docs/models/plan.md for reference """ plan_id: str = Field( ..., # No alias needed as field name matches API parameter description="The ID of the plan to retrieve", pattern=r"^plan-[a-zA-Z0-9]{16}$", # Standard plan ID pattern )
- terraform_cloud_mcp/server.py:86-86 (registration)Registration of the 'get_plan_logs' tool using FastMCP's mcp.tool() decorator, importing from the plans module.mcp.tool()(plans.get_plan_logs)