Terraform을 사용하여 Azure Machine Learning 작업 영역 관리

이 문서에서는 Terraform 구성 파일을 사용하여 Azure Machine Learning 작업 영역을 만들고 관리하는 방법을 알아봅니다. Terraform의 템플릿 기반 구성 파일을 사용하면 반복 가능하고 예측 가능한 방식으로 Azure 리소스를 정의하고, 만들고, 구성할 수 있습니다. Terraform은 리소스 상태를 추적하고 리소스를 정리 및 삭제할 수 있습니다.

Terraform 구성은 배포에 필요한 리소스를 정의하는 문서입니다. 배포 변수를 지정할 수도 있습니다. 변수는 구성을 사용할 때 입력 값을 제공하는 데 사용됩니다.

필수 구성 요소

제한 사항

  • 새 작업 영역을 만들 때 작업 영역에 필요한 서비스를 자동으로 만들거나 기존 서비스를 사용할 수 있습니다. 작업 영역과 다른 Azure 구독의 기존 서비스를 사용하려면 해당 서비스가 포함된 구독에 Azure Machine Learning 네임스페이스를 등록해야 합니다. 예를 들어, 구독 B의 스토리지 계정을 사용하는 구독 A에서 작업 영역을 만드는 경우 작업 영역에서 스토리지 계정을 사용하려면 먼저 Azure Machine Learning 네임스페이스를 구독 B에 등록해야 합니다.

    Azure Machine Learning의 리소스 공급자는 Microsoft.MachineLearningServices입니다. 등록 여부를 확인하는 방법 및 등록하는 방법에 대한 자세한 내용은 Azure 리소스 공급자 및 형식 문서를 참조하세요.

    Important

    이는 Azure Storage Accounts, Azure Container Register, Azure Key Vault 및 Application Insights 등의 작업 영역을 만드는 동안 제공된 리소스에만 적용됩니다.

Azure Application Insights 인스턴스는 작업 영역을 만들 때 만들어집니다. 원하는 경우 클러스터를 만든 후 Application Insights 인스턴스를 삭제할 수 있습니다. 이 인스턴스를 삭제하면 작업 영역에서 수집되는 정보가 제한되며, 문제를 해결하기가 더 어려워질 수 있습니다. 작업 영역에서 만든 Application Insights 인스턴스를 삭제하는 경우 작업 영역을 삭제하고 다시 만들어야만 인스턴스를 다시 만들 수 없습니다.

이 Application Insights 인스턴스 사용에 대한 자세한 내용은 Machine Learning 웹 서비스 엔드포인트에서 데이터 모니터링 및 수집을 참조하세요.

Azure 공급자 선언

Azure 공급자를 선언하는 Terraform 구성 파일을 만듭니다.

  1. 이름이 main.tf인 새 파일을 만듭니다. Azure Cloud Shell을 사용하는 경우 bash를 사용합니다.

    code main.tf
    
  2. 다음 코드를 편집기에 붙여 넣습니다.

    main.tf:

    data "azurerm_client_config" "current" {}
    
    resource "azurerm_resource_group" "default" {
      name     = "${random_pet.prefix.id}-rg"
      location = var.location
    }
    
    resource "random_pet" "prefix" {
      prefix = var.prefix
      length = 2
    }
    
    resource "random_integer" "suffix" {
      min = 10000000
      max = 99999999
    }
    
  3. 파일을 저장(<Ctrl>S)하고 편집기를 종료(<Ctrl>Q)합니다.

작업 영역 배포

다음 Terraform 구성을 사용하여 Azure Machine Learning 작업 영역을 만들 수 있습니다. Azure Machine Learning 작업 영역을 만들 때 다양한 다른 서비스가 종속성으로 필요합니다. 템플릿은 작업 영역에 연결된 이러한 리소스도 지정합니다. 필요에 따라 공용 또는 프라이빗 네트워크 연결로 리소스를 만드는 템플릿을 사용하도록 선택할 수 있습니다.

Azure의 일부 리소스에는 전역적으로 고유한 이름이 필요합니다. 다음 템플릿을 사용하여 리소스를 배포하기 전에 name 변수를 고유한 값으로 설정합니다.

variables.tf:

variable "environment" {
  type        = string
  description = "Name of the environment"
  default     = "dev"
}

variable "location" {
  type        = string
  description = "Location of the resources"
  default     = "eastus"
}

variable "prefix" {
  type        = string
  description = "Prefix of the resource name"
  default     = "ml"
}

workspace.tf:

# Dependent resources for Azure Machine Learning
resource "azurerm_application_insights" "default" {
  name                = "${random_pet.prefix.id}-appi"
  location            = azurerm_resource_group.default.location
  resource_group_name = azurerm_resource_group.default.name
  application_type    = "web"
}

resource "azurerm_key_vault" "default" {
  name                     = "${var.prefix}${var.environment}${random_integer.suffix.result}kv"
  location                 = azurerm_resource_group.default.location
  resource_group_name      = azurerm_resource_group.default.name
  tenant_id                = data.azurerm_client_config.current.tenant_id
  sku_name                 = "premium"
  purge_protection_enabled = false
}

resource "azurerm_storage_account" "default" {
  name                            = "${var.prefix}${var.environment}${random_integer.suffix.result}st"
  location                        = azurerm_resource_group.default.location
  resource_group_name             = azurerm_resource_group.default.name
  account_tier                    = "Standard"
  account_replication_type        = "GRS"
  allow_nested_items_to_be_public = false
}

resource "azurerm_container_registry" "default" {
  name                = "${var.prefix}${var.environment}${random_integer.suffix.result}cr"
  location            = azurerm_resource_group.default.location
  resource_group_name = azurerm_resource_group.default.name
  sku                 = "Premium"
  admin_enabled       = true
}

# Machine Learning workspace
resource "azurerm_machine_learning_workspace" "default" {
  name                          = "${random_pet.prefix.id}-mlw"
  location                      = azurerm_resource_group.default.location
  resource_group_name           = azurerm_resource_group.default.name
  application_insights_id       = azurerm_application_insights.default.id
  key_vault_id                  = azurerm_key_vault.default.id
  storage_account_id            = azurerm_storage_account.default.id
  container_registry_id         = azurerm_container_registry.default.id
  public_network_access_enabled = true

  identity {
    type = "SystemAssigned"
  }
}

문제 해결

리소스 공급자 오류

Azure Machine Learning 작업 영역 또는 작업 영역에서 사용하는 리소스를 만들 때 다음 메시지와 유사한 오류가 발생할 수 있습니다.

  • No registered resource provider found for location {location}
  • The subscription is not registered to use namespace {resource-provider-namespace}

대부분의 리소스 공급자는 자동으로 등록되지만, 전부는 아닙니다. 이 메시지가 표시되면 언급된 제공자를 등록해야 합니다.

다음 표에는 Azure Machine Learning에 필요한 리소스 공급자 목록이 있습니다.

리소스 공급자 필요한 이유
Microsoft.MachineLearningServices Azure Machine Learning 작업 영역을 만듭니다.
Microsoft.Storage Azure Storage 계정은 작업 영역의 기본 스토리지로 사용됩니다.
Microsoft.ContainerRegistry Azure Container Registry는 작업 영역이 Docker 이미지를 빌드하는 데 사용됩니다.
Microsoft.KeyVault Azure Key Vault는 작업 영역에서 비밀을 저장하는 데 사용됩니다.
Microsoft.Notebooks Azure Machine Learning 컴퓨팅 인스턴스의 통합 Notebook.
Microsoft.ContainerService Azure Kubernetes Services에 학습된 모델을 배포하려는 경우.

Azure Machine Learning에서 고객 관리형 키를 사용하려는 경우 다음 서비스 공급자를 등록해야 합니다.

리소스 공급자 필요한 이유
Microsoft.DocumentDB 작업 영역의 메타데이터를 기록하는 Azure CosmosDB 인스턴스입니다.
Microsoft.Search Azure Search는 작업 영역에 대한 인덱싱 기능을 제공합니다.

Azure Machine Learning에서 관리형 가상 네트워크를 사용하려는 경우 Microsoft.Network 리소스 공급자를 등록해야 합니다. 이 리소스 공급자는 관리형 가상 네트워크에 대한 프라이빗 엔드포인트를 만들 때 작업 영역에서 사용됩니다.

리소스 공급자 등록에 대한 자세한 내용은 리소스 공급자 등록 오류 해결을 참조하세요.

다음 단계