Search code examples
azureterraformazure-machine-learning-service

How to create Azure ML Registry using Terraform?


How do I create Azure ML registry using terraform? I see we have a way to create Azure ML workspace (azurerm_machine_learning_workspace) and ACR as well. But I don't see a way to explicitly create ML registry or am I something? Can someone help me with it please?


Solution

  • Another option, using the azapi resource

    terraform {
      required_providers {
        azapi = {
          source  = "azure/azapi"
          version = "~> 2.0"
        }
      }
    }
    
    provider "azapi" {
      # subscription_id = "..."
    }
    
    locals {
      location            = "East US" # Note: Update these as appropriate
      resource_group_name = "myrg"
      registry_name       = "my-registry"
    }
    
    resource "azurerm_resource_group" "default" {
      name     = local.resource_group_name
      location = local.location
    }
    
    resource "azapi_resource" "ml_registry" {
      type      = "Microsoft.MachineLearningServices/registries@2024-04-01"
      name      = local.registry_name
      location  = azurerm_resource_group.default.location
      parent_id = azurerm_resource_group.default.id
    
      identity {
        type = "SystemAssigned"
      }
    
      body = {
        properties = {
          regionDetails = [
            {
              location = azurerm_resource_group.default.location
              storageAccountDetails = [
                {
                  systemCreatedStorageAccount = {
                    storageAccountType = "Standard_LRS"
                  }
                }
              ],
              acrDetails = [
                {
                  systemCreatedAcrAccount = {
                    acrAccountSku = "Premium"
                  }
                }
              ]
            }
          ]
        }
      }
    }