cancel_run
Stop an in-progress Terraform Cloud run during planning or applying phases to halt resource consumption or terminate long-running operations.
Instructions
Cancel a run that is currently planning or applying
Gracefully stops an in-progress run during planning or applying phases. Use this when you need to stop a run that's taking too long, consuming too many resources, or needs to be stopped for any reason. The operation attempts to cleanly terminate the run by sending an interrupt signal.
API endpoint: POST /runs/{run_id}/actions/cancel
Args: run_id: The ID of the run to cancel (format: "run-xxxxxxxx") comment: An optional explanation for why the run was canceled
Returns: Run status update with canceled state, timestamp of cancellation, and any provided comment in the response metadata
See: docs/tools/run.md for reference documentation
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| run_id | Yes | ||
| comment | No |
Implementation Reference
- The handler function that implements the cancel_run tool logic by making a POST request to Terraform Cloud's /runs/{run_id}/actions/cancel endpoint with an optional comment payload.async def cancel_run(run_id: str, comment: str = "") -> APIResponse: """Cancel a run that is currently planning or applying Gracefully stops an in-progress run during planning or applying phases. Use this when you need to stop a run that's taking too long, consuming too many resources, or needs to be stopped for any reason. The operation attempts to cleanly terminate the run by sending an interrupt signal. API endpoint: POST /runs/{run_id}/actions/cancel Args: run_id: The ID of the run to cancel (format: "run-xxxxxxxx") comment: An optional explanation for why the run was canceled Returns: Run status update with canceled state, timestamp of cancellation, and any provided comment in the response metadata See: docs/tools/run.md for reference documentation """ request = RunActionRequest(run_id=run_id, comment=comment) # Create payload if comment is provided payload = {} if request.comment: payload = {"comment": request.comment} # Make API request return await api_request( f"runs/{run_id}/actions/cancel", method="POST", data=payload )
- terraform_cloud_mcp/server.py:70-70 (registration)The line where the cancel_run tool is registered with FastMCP using the write_tool_config.mcp.tool(**write_tool_config)(runs.cancel_run)
- terraform_cloud_mcp/server.py:15-15 (registration)Import of the runs module containing the cancel_run function, necessary for registration.from terraform_cloud_mcp.tools import runs
- terraform_cloud_mcp/server.py:39-42 (helper)Configuration used for registering write tools like cancel_run, conditionally enabling based on read-only mode.write_tool_config = { "enabled": not read_only_mode, "annotations": {"readOnlyHint": False} }