Skip to main content
Glama
AgentWong
by AgentWong

update_resource_schema

Modify Terraform resource schemas and related metadata to maintain accurate Infrastructure-as-Code documentation and version tracking.

Instructions

Update an existing Terraform resource's schema and related information

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
resource_idYesResource ID
new_schemaYesNew schema
new_versionNoNew version
new_doc_urlNoNew documentation URL

Implementation Reference

  • The core handler function that updates the schema of a Terraform resource in the database. This implements the main logic for the 'update_resource_schema' tool.
    def update_resource_schema(
        db: DatabaseManager,
        resource_id: str,
        new_schema: str,
        new_version: Optional[str] = None,
        new_doc_url: Optional[str] = None,
    ) -> bool:
        """Update a Terraform resource's schema and optional fields."""
        logger.info(
            "Updating resource schema",
            extra={
                "resource_id": resource_id,
                "has_new_version": bool(new_version),
                "has_new_doc_url": bool(new_doc_url),
                "operation": "update_resource_schema",
            },
        )
        try:
            updates = ["schema = ?"]
            params = [new_schema]
    
            if new_version:
                updates.append("version = ?")
                params.append(new_version)
            if new_doc_url:
                updates.append("doc_url = ?")
                params.append(new_doc_url)
    
            updates.append("updated_at = CURRENT_TIMESTAMP")
            params.append(resource_id)
    
            with db.get_connection() as conn:
                cursor = conn.execute(
                    f"""UPDATE terraform_resources
                    SET {', '.join(updates)}
                    WHERE id = ?""",
                    tuple(params),
                )
                return cursor.rowcount > 0
        except sqlite3.Error as e:
            error_msg = f"Failed to update resource schema: {str(e)}"
            logger.error(error_msg)
            raise DatabaseError(error_msg)
  • JSON schema defining the input parameters and validation for the update_resource_schema tool.
    "update_resource_schema": {
        "type": "object",
        "description": "Update an existing Terraform resource's schema and related information",
        "required": ["resource_id", "new_schema"],
        "properties": {
            "resource_id": {"type": "string", "description": "Resource ID"},
            "new_schema": {"type": "string", "description": "New schema"},
            "new_version": {"type": "string", "description": "New version"},
            "new_doc_url": {"type": "string", "description": "New documentation URL"},
        },
    },
  • Import and export of the update_resource_schema function in the db package __init__.py, making it available for use in tool handlers.
        add_terraform_provider,
        add_terraform_resource,
        get_provider_resources,
        get_resource_info,
        update_provider_version,
        update_resource_schema,
    )
  • Supporting method in DatabaseManager class that duplicates the resource schema update logic.
    def update_resource_schema(
        self,
        resource_id: str,
        new_schema: str,
        new_version: str | None = None,
        new_doc_url: str | None = None,
    ) -> bool:
        """Update a resource's schema."""
        try:
            with self.get_connection() as conn:
                conn.execute("BEGIN IMMEDIATE")
                try:
                    # Build update query dynamically
                    updates = ["schema = ?"]
                    params = [new_schema]
    
                    if new_version:
                        updates.append("version = ?")
                        params.append(new_version)
                    if new_doc_url:
                        updates.append("doc_url = ?")
                        params.append(new_doc_url)
    
                    updates.append("updated_at = CURRENT_TIMESTAMP")
                    params.append(resource_id)  # Add resource_id last
    
                    query = f"""UPDATE terraform_resources 
                              SET {', '.join(updates)}
                              WHERE id = ?"""
    
                    cursor = conn.execute(query, tuple(params))
                    conn.commit()
                    return cursor.rowcount > 0
                except Exception:
                    conn.rollback()
                    raise
        except sqlite3.Error as e:
            raise DatabaseError(f"Failed to update resource schema: {str(e)}")

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/AgentWong/iac-memory-mcp-server-project'

If you have feedback or need assistance with the MCP directory API, please join our Discord server