From 4ccbe99971e9d1cd50192972f82557a02c8608ab Mon Sep 17 00:00:00 2001 From: kevindelmont <133667252+kevindelmont@users.noreply.github.com> Date: Tue, 19 Nov 2024 11:25:46 +0100 Subject: [PATCH] Add cognitive deployment (#43) --- .../standalone-scenarios-additional.json | 1 + .../configuration.tfvars | 46 +++++++++++++++++++ .../cognitive_service_account.tf | 26 ++++++++++- .../cognitive_services_account/output.tf | 5 ++ 4 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 examples/cognitive_services/200-cognitive-services-deployment/configuration.tfvars diff --git a/.github/workflows/standalone-scenarios-additional.json b/.github/workflows/standalone-scenarios-additional.json index 61d601e344..e7d3569327 100644 --- a/.github/workflows/standalone-scenarios-additional.json +++ b/.github/workflows/standalone-scenarios-additional.json @@ -2,6 +2,7 @@ "config_files": [ "cognitive_services/100-cognitive-services-account", "cognitive_services/101-cognitive-services-account-managed-identity", + "cognitive_services/200-cognitive-services-deployment", "compute/batch/batch_certificate/100-batch-certificate - path", "compute/batch/batch_job/100-batch-job - quotas", "compute/batch/batch_pool/100-batch-pool - quotas", diff --git a/examples/cognitive_services/200-cognitive-services-deployment/configuration.tfvars b/examples/cognitive_services/200-cognitive-services-deployment/configuration.tfvars new file mode 100644 index 0000000000..edf62035a2 --- /dev/null +++ b/examples/cognitive_services/200-cognitive-services-deployment/configuration.tfvars @@ -0,0 +1,46 @@ +global_settings = { + default_region = "region1" + regions = { + region1 = "westus" + } + random_length = 5 +} + +resource_groups = { + test-rg = { + name = "rg-alz-caf-test-1" + } +} + +cognitive_services_account = { + test_account-1 = { + resource_group = { + # accepts either id or key to get resource group id + # id = "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resourceGroup1" + # lz_key = "examples" + key = "test-rg" + } + name = "cs-alz-caf-test-1" + kind = "OpenAI" + sku_name = "S0" + tags = { + env = "test" + } + # you must first agree to the Responsible AI terms for that resource type in your Azure subscription. This is a legal agreement that must be accepted in the Azure Portal before you can proceed with deployment via Terraform. + # https://learn.microsoft.com/en-us/legal/cognitive-services/openai/limited-access + deployment = { + gpt-35-turbo = { + name = "gpt-35-turbo" + model = { + name = "gpt-35-turbo" + format = "OpenAI" + version = "0301" + } + scale = { + type = "Standard" + capacity = 1 + } + } + } + } +} diff --git a/modules/cognitive_services/cognitive_services_account/cognitive_service_account.tf b/modules/cognitive_services/cognitive_services_account/cognitive_service_account.tf index 2f3a24ff40..d68f73ed90 100644 --- a/modules/cognitive_services/cognitive_services_account/cognitive_service_account.tf +++ b/modules/cognitive_services/cognitive_services_account/cognitive_service_account.tf @@ -52,4 +52,28 @@ resource "azurerm_cognitive_account" "service" { } } } -} \ No newline at end of file +} + +resource "azurerm_cognitive_deployment" "deployment" { + depends_on = [azurerm_cognitive_account.service] + + for_each = var.settings.deployment + name = each.value.name + cognitive_account_id = azurerm_cognitive_account.service.id + rai_policy_name = try(each.value.rai_policy, null) + version_upgrade_option = try(each.value.version_upgrade_option, null) + + model { + name = each.value.model.name + format = each.value.model.format + version = try(each.value.model.version, null) + } + + scale { + type = each.value.scale.type + tier = try(each.value.scale.tier, null) + size = try(each.value.scale.size, null) + family = try(each.value.scale.family, null) + capacity = try(each.value.scale.capacity, null) + } +} diff --git a/modules/cognitive_services/cognitive_services_account/output.tf b/modules/cognitive_services/cognitive_services_account/output.tf index c548874b0b..ed64efa3fc 100644 --- a/modules/cognitive_services/cognitive_services_account/output.tf +++ b/modules/cognitive_services/cognitive_services_account/output.tf @@ -26,3 +26,8 @@ output "rbac_id" { output "identity" { value = try(azurerm_cognitive_account.service.identity, null) } + +output "deployment_id" { + description = "The ID of the Deployment for Azure Cognitive Services Account." + value = azurerm_cognitive_deployment.id +}