1. Structured Resource Hierarchies for AI in OCI Compartments

    Python

    In Oracle Cloud Infrastructure (OCI), compartments are used to organize and isolate cloud resources. This allows for the structuring of resources in a hierarchy that mirrors your organization, making it easier to manage access and segregate duties. To implement AI services within OCI, you can create projects and associate different AI resources like data assets, models, and others within compartments.

    Here's how you would set up such a structure using Pulumi with Python:

    1. Compartment: Create a new compartment to contain all AI-related resources.
    2. AI Vision Project: Within the compartment, create an AI project which serves as a logical grouping for AI Vision resources.
    3. Data Assets: Define data assets within the AI Vision project which are the sources of data for AI processing (e.g., an Object Storage bucket).
    4. AI Model: Create an AI model within the AI Vision project to build custom vision models for tasks like image recognition.

    Let's see how we can implement this structure in code:

    import pulumi import pulumi_oci as oci # Replace these variables with actual values compartment_display_name = "AI_Services" compartment_description = "Compartment for AI-related resources" project_display_name = "AI_Vision_Project" project_description = "AI project for vision models" data_asset_display_name = "AI_Data_Asset" data_asset_description = "Data asset for AI processing" # Initialize a new compartment for AI services ai_compartment = oci.identity.Compartment("aiServicesCompartment", compartment_id=oci.config.tenancy(), # root compartment description=compartment_description, name=compartment_display_name, ) # Initialize an AI Vision project within the compartment ai_vision_project = oci.aivision.Project("aiVisionProject", compartment_id=ai_compartment.id, display_name=project_display_name, description=project_description, ) # Define a data asset within the AI Vision project and compartment # Assuming the data source to be an Object Storage bucket which is set up separately data_asset = oci.aianomalydetection.DataAsset("aiDataAsset", compartment_id=ai_compartment.id, project_id=ai_vision_project.id, display_name=data_asset_display_name, description=data_asset_description, data_source_details=oci.aianomalydetection.DataAssetDataSourceDetailsObjectStorageArgs( bucket="bucket_name_here", # Replace with actual bucket name namespace="namespace_here", # Replace with actual namespace object="object_name_here", # Replace with actual object name ), ) # Export the compartment's OCID and project's OCID for further reference or cross-stack usage pulumi.export("compartment_id", ai_compartment.id) pulumi.export("project_id", ai_vision_project.id)

    In this program, we:

    • Import the necessary Pulumi OCI package.
    • Define a compartment, which will contain all of our AI-related resources. A compartment is a fundamental building block of OCI's resource model and provides isolation of cloud resources.
    • To create a compartment, we provide a description, name, and specify the parent compartment's compartment_id. In this case, I'm using the root compartment's ID by pulling it from the OCI Pulumi provider configuration, which would be set when you configure your Pulumi environment.
    • Next, we create an AI Vision project, which groups the AI resources. The project is associated with the compartment_id of the AI compartment we just created.
    • For AI processing, we define a DataAsset that represents the source of our data. In this case, the details assume that we are using an Oracle Cloud Infrastructure Object Storage bucket.

    The pulumi.export lines at the end of the script will output the Compartment ID and Project ID when the Pulumi program is executed, which can be helpful for interfacing with other Pulumi programs or querying the Pulumi stack’s output.

    Remember, to run this Pulumi program, you'd need to have the Pulumi CLI installed and properly set up with Oracle Cloud Infrastructure credentials and configuration. Then, a single pulumi up command will apply these configurations to OCI, provisioning the resources as specified.