move_workspaces_to_project
Move Terraform Cloud workspaces into a specified project by providing project and workspace IDs. Organize infrastructure management by grouping related workspaces together.
Instructions
Move workspaces into a project.
Moves one or more workspaces into a project. The user must have permission to move workspaces on both source and destination projects.
API endpoint: POST /projects/{project_id}/relationships/workspaces
Args: project_id: The ID of the destination project (format: "prj-xxxxxxxx") workspace_ids: List of workspace IDs to move (format: ["ws-xxxxxxxx", ...])
Returns: Empty response with HTTP 204 status code if successful
See: docs/tools/project.md for reference documentation
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| project_id | Yes | ||
| workspace_ids | Yes |
Implementation Reference
- The main handler function that implements the tool logic by validating inputs with WorkspaceMoveRequest model and making a POST API request to move workspaces into the specified project.@handle_api_errors async def move_workspaces_to_project( project_id: str, workspace_ids: List[str] ) -> APIResponse: """Move workspaces into a project. Moves one or more workspaces into a project. The user must have permission to move workspaces on both source and destination projects. API endpoint: POST /projects/{project_id}/relationships/workspaces Args: project_id: The ID of the destination project (format: "prj-xxxxxxxx") workspace_ids: List of workspace IDs to move (format: ["ws-xxxxxxxx", ...]) Returns: Empty response with HTTP 204 status code if successful See: docs/tools/project.md for reference documentation """ # Create request using Pydantic model request = WorkspaceMoveRequest(project_id=project_id, workspace_ids=workspace_ids) # Create payload payload: Dict[str, List[Dict[str, str]]] = {"data": []} for workspace_id in request.workspace_ids: payload["data"].append({"type": "workspaces", "id": workspace_id}) # Make API request return await api_request( f"projects/{project_id}/relationships/workspaces", method="POST", data=payload )
- Pydantic model defining the input schema for the tool, including required project_id and list of workspace_ids with descriptions and validation.class WorkspaceMoveRequest(APIRequest): """Request model for moving workspaces into a project. This model is used for the POST /projects/{project_id}/relationships/workspaces endpoint, which allows moving one or more workspaces into a project. Reference: https://developer.hashicorp.com/terraform/cloud-docs/api-docs/projects#move-workspaces-into-a-project See: docs/models/project.md for reference """ project_id: str = Field( ..., description="The ID of the destination project", ) workspace_ids: List[str] = Field( ..., description="The IDs of workspaces to move into the project", )
- terraform_cloud_mcp/server.py:101-101 (registration)Registers the move_workspaces_to_project function as an MCP tool with write permissions using the FastMCP decorator.mcp.tool(**write_tool_config)(projects.move_workspaces_to_project)