1. Automating AI Model Deployment with User-assigned Managed Identities

    Python

    To automate AI model deployment in Azure with user-assigned managed identities using Pulumi, we will create a Cognitive Services account deployment that could host an AI model, and an Azure Virtual Machine (VM) where the model might run. We will then use a user-assigned managed identity to give the VM identity-based access to the Cognitive Services.

    Firstly, a user-assigned managed identity is an Azure identity resource that provides Azure services with an Azure Active Directory identity. This aids in providing secure access to Azure resources by allowing the service principle attached to the identity to authenticate to services that support Azure AD authentication.

    To keep it focused on the primary goal, we'll work with azure-native Pulumi provider resources. In this case, we're going to use:

    • azure-native.managedidentity.UserAssignedIdentity: This resource creates a user-assigned managed identity in Azure, which can be associated with a virtual machine to authenticate to other Azure services.

    • azure-native.compute.VirtualMachine: This resource will set up a new VM which will use the managed identity for authentication.

    • azure.cognitive.Deployment: This resource is used to create a deployment under a Cognitive Services Account for a specific AI model.

    Now, let's put together the Python program that creates these Azure resources using Pulumi.

    import pulumi import pulumi_azure as azure # Uses Azure Classic provider import pulumi_azure_native as azure_native # Create a user-assigned managed identity user_assigned_identity = azure_native.managedidentity.UserAssignedIdentity("aiModelUserIdentity", resource_group_name="myResourceGroup", # Replace with your resource group name location="East US") # Set up the virtual machine that will use the managed identity vm = azure_native.compute.VirtualMachine("aiModelVM", resource_group_name="myResourceGroup", # Replace with your resource group name location="East US", # The VM config goes here: OS, size, network interfaces, etc. # ... identity=azure_native.compute.VirtualMachineIdentityArgs( type="UserAssigned", user_assigned_identities={user_assigned_identity.id: {}}, )) # Create a Cognitive Services Account deployment for the AI model cognitive_deployment = azure.cognitive.Deployment("aiModelDeployment", name="myAIDeployment", cognitive_account_id="/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CognitiveServices/accounts/{accountName}", # Replace with actual IDs model=azure.cognitive.DeploymentModelArgs( name="myAIModel", format="Docker", version="1.0.0", ), scale=azure.cognitive.DeploymentScaleArgs( type="Kubernetes", size="Medium", tier="Standard", capacity=1, )) # Export the user-assigned identity ID and VM ID pulumi.export("user_assigned_identity_id", user_assigned_identity.id) pulumi.export("vm_id", vm.id)

    In the above program:

    1. We create a UserAssignedIdentity to grant your AI deployment access to other Azure resources without sharing credentials.
    2. We then declare a VirtualMachine resource specifying that it should use the created UserAssignedIdentity for its identity.
    3. The Deployment under azure.cognitive sets up the environment for an AI model to run within a Cognitive Services Account, which Azure may not have directly supported in a native Pulumi provider until the latest versions.

    Please note that you'll need to provide actual values for resource_group_name, cognitive_account_id, and the VM configuration (like the OS, size, and network interfaces) where indicated in the commented sections of the code.

    Be sure to replace placeholder text such as {subscriptionId}, {resourceGroupName}, and {accountName} with the actual IDs specific to your Azure subscription and resources. The cognitive_account_id you specify should point to an existing Cognitive Services Account that you set up separately or through another Pulumi stack.

    This script does not include the more granular steps of setting up the actual AI model, training it, or feeding it data, which would involve additional specifics about your chosen machine learning framework and the nature of your AI model. This script provides the infrastructure for such a deployment.

    Run this Pulumi program using the Pulumi CLI, after having logged into your Azure account and setting up the Pulumi Azure provider. This setup will provision resources on Azure Cloud that are capable of handling automated AI model deployment with user-assigned managed identities.