lock_workspace
Prevent changes to infrastructure by locking a workspace. Use this tool to halt new runs during maintenance or manual adjustments without interrupting active operations.
Instructions
Lock a workspace.
Locks a workspace to prevent runs from being queued. This is useful when you want to prevent changes to infrastructure while performing maintenance or making manual adjustments. Locking a workspace does not affect currently running plans or applies.
API endpoint: POST /workspaces/{workspace_id}/actions/lock
Args: workspace_id: The ID of the workspace to lock (format: "ws-xxxxxxxx") reason: Optional reason for locking
Returns: The workspace with updated lock status and related metadata
See: docs/tools/workspace.md for reference documentation
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| reason | No | ||
| workspace_id | Yes |
Implementation Reference
- The main handler function that implements the lock_workspace tool by making a POST request to the Terraform Cloud API to lock the specified workspace.@handle_api_errors async def lock_workspace(workspace_id: str, reason: str = "") -> APIResponse: """Lock a workspace. Locks a workspace to prevent runs from being queued. This is useful when you want to prevent changes to infrastructure while performing maintenance or making manual adjustments. Locking a workspace does not affect currently running plans or applies. API endpoint: POST /workspaces/{workspace_id}/actions/lock Args: workspace_id: The ID of the workspace to lock (format: "ws-xxxxxxxx") reason: Optional reason for locking Returns: The workspace with updated lock status and related metadata See: docs/tools/workspace.md for reference documentation """ payload = {} if reason: payload = {"reason": reason} return await api_request( f"workspaces/{workspace_id}/actions/lock", method="POST", data=payload )
- terraform_cloud_mcp/server.py:59-59 (registration)Registers the lock_workspace tool with the MCP server using the mcp.tool decorator and write_tool_config.mcp.tool(**write_tool_config)(workspaces.lock_workspace)
- terraform_cloud_mcp/server.py:39-42 (helper)Configuration used for registering write tools like lock_workspace, including enabling conditions and annotations.write_tool_config = { "enabled": not read_only_mode, "annotations": {"readOnlyHint": False} }