How to create Azure AI services multi-service account using Terraform

475 views Asked by At

I am aware of Azure openai service can be created using azurerm_cognitive_account.

resource "azurerm_cognitive_account" "openai_services" {
  for_each                      = { for openai in var.openai_services : openai.name => openai }
  name                          = each.value.name
  location                      = each.value.location
  resource_group_name           = each.value.resource_group_name
  kind                          = "OpenAI"
  sku_name                      = each.value.sku_name
  public_network_access_enabled = each.value.public_network_access_enabled
  identity {
    type = "SystemAssigned"
  }
  tags = merge(var.default_tags, each.value.tags)
}

However, I am unware if facility exist for multi-service in Azure Terraform provider.

How to create Azure AI services multi-service account using Terraform?

1

There are 1 answers

0
Vinay B On BEST ANSWER

I tried to create an Azure AI services multi-service account using Terraform and I was able to provision the requirement successfully.

To achieve this configuration make sure you provide with necessary permissions to the contributor level.

The Only change that needs to take place here is kind = "CognitiveServices" This makes your Cognitive Services account act as multi service account.

The major changes among the two types of kinds are:

  • Multi-Service Account: Provides access to multiple Azure Cognitive Services (e.g., Text Analytics, Computer Vision, Face API) under a single subscription using one set of keys and endpoint.
  • Self-Service (Single-Service) Account: Dedicated to one specific Cognitive Service, requiring separate subscriptions and separate keys for each service.

My terraform configuration:

main.tf:

provider "azurerm" {
  features {}
}

resource "azurerm_resource_group" "example" {
  name     = var.resource_group_name
  location = var.location
}

resource "azurerm_cognitive_account" "example" {
  name                = var.cognitive_account_name
  location            = azurerm_resource_group.example.location
  resource_group_name = azurerm_resource_group.example.name
  kind                = "CognitiveServices" # This is for multi-service account

  sku_name = "S0"

  tags = {
    environment = "production"
  }
}

variable.tf:

variable "resource_group_name" {
  description = "The name of the resource group"
  type        = string
}

variable "location" {
  description = "The Azure Region in which all resources in this example should be created."
  type        = string
}

variable "cognitive_account_name" {
  description = "The name of the cognitive services account"
  type        = string
}

terraform.tfvars:

resource_group_name    = "vkCognitiveServicesRG"
location               = "East US"
cognitive_account_name = "vkCognitiveServiceAccount"

Output.tf:

output "cognitive_account_endpoint" {
  value = module.cognitive_account.endpoint
}

Output:

enter image description here

enter image description here