From 2f17431ec7e6ce71463b0995cd8a3c332e2b7a7b Mon Sep 17 00:00:00 2001 From: Andy Aviles Date: Fri, 21 Jun 2024 12:29:29 -0400 Subject: [PATCH] matching contributor guidelines --- quickstart/101-ai-studio/connections.tf | 20 --- quickstart/101-ai-studio/dependent.tf | 66 --------- quickstart/101-ai-studio/hub.tf | 36 ----- quickstart/101-ai-studio/main.tf | 170 +++++++++++++++++++++--- quickstart/101-ai-studio/output.tf | 5 +- quickstart/101-ai-studio/project.tf | 19 --- quickstart/101-ai-studio/providers.tf | 33 +++++ quickstart/101-ai-studio/variables.tf | 23 ++-- 8 files changed, 198 insertions(+), 174 deletions(-) delete mode 100644 quickstart/101-ai-studio/connections.tf delete mode 100644 quickstart/101-ai-studio/dependent.tf delete mode 100644 quickstart/101-ai-studio/hub.tf delete mode 100644 quickstart/101-ai-studio/project.tf create mode 100644 quickstart/101-ai-studio/providers.tf diff --git a/quickstart/101-ai-studio/connections.tf b/quickstart/101-ai-studio/connections.tf deleted file mode 100644 index 2ab70ee88..000000000 --- a/quickstart/101-ai-studio/connections.tf +++ /dev/null @@ -1,20 +0,0 @@ -//Create an AI Services connection. -resource "azapi_resource" "AIServicesConnection" { - type = "Microsoft.MachineLearningServices/workspaces/connections@2024-04-01-preview" - name = "Default_AIServices" - parent_id = azapi_resource.hub.id - - body = jsonencode({ - properties = { - category = "AIServices", - target = jsondecode(azapi_resource.AIServicesResource.output).properties.endpoint, - authType = "AAD", - isSharedToAll = true, - metadata = { - ApiType = "Azure", - ResourceId = azapi_resource.AIServicesResource.id - } - } - }) - response_export_values = ["*"] -} \ No newline at end of file diff --git a/quickstart/101-ai-studio/dependent.tf b/quickstart/101-ai-studio/dependent.tf deleted file mode 100644 index 9e95287e2..000000000 --- a/quickstart/101-ai-studio/dependent.tf +++ /dev/null @@ -1,66 +0,0 @@ - -resource "azurerm_resource_group" "default" { - name = "rg-${var.names}" - location = var.location -} - -resource "azurerm_storage_account" "default" { - name = "${var.names}storage${random_string.suffix.result}" - 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_key_vault" "default" { - name = "${var.names}keyvault${random_string.suffix.result}" - 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 = "standard" - purge_protection_enabled = false -} - -// AzAPI AIServices -resource "azapi_resource" "AIServicesResource"{ - type = "Microsoft.CognitiveServices/accounts@2023-10-01-preview" - name = "${var.names}AIServicesResource" - location = azurerm_resource_group.default.location - parent_id = azurerm_resource_group.default.id - - identity { - type = "SystemAssigned" - } - - body = jsonencode({ - properties = { - apiProperties = { - statisticsEnabled = false - } - } - kind = "AIServices" - sku = { - name = var.sku - } - }) - - response_export_values = ["*"] -} - -/* The following resources are OPTIONAL. -resource "azurerm_application_insights" "default" { - name = "${var.names}appinsights" - location = azurerm_resource_group.default.location - resource_group_name = azurerm_resource_group.default.name - application_type = "web" -} - -resource "azurerm_container_registry" "default" { - name = "${var.names}contreg" - resource_group_name = azurerm_resource_group.default.name - location = azurerm_resource_group.default.location - sku = "premium" - admin_enabled = true -} -*/ \ No newline at end of file diff --git a/quickstart/101-ai-studio/hub.tf b/quickstart/101-ai-studio/hub.tf deleted file mode 100644 index 565ca7c19..000000000 --- a/quickstart/101-ai-studio/hub.tf +++ /dev/null @@ -1,36 +0,0 @@ -resource "azapi_resource" "hub" { - type = "Microsoft.MachineLearningServices/workspaces@2024-04-01-preview" - name = "my-ai-hub" - location = azurerm_resource_group.default.location - parent_id = azurerm_resource_group.default.id - - identity { - type = "SystemAssigned" - } - - body = jsonencode({ - properties = { - description = "This is my Azure AI hub" - friendlyName = "My Hub" - storageAccount = azurerm_storage_account.default.id - keyVault = azurerm_key_vault.default.id - - /* Optional: To enable these field, the corresponding dependent resources need to be uncommented. - applicationInsight = azurerm_application_insights.default.id - containerRegistry = azurerm_container_registry.default.id - */ - - /*Optional: To enable Customer Managed Keys, the corresponding - encryption = { - status = var.encryption_status - keyVaultProperties = { - keyVaultArmId = azurerm_key_vault.default.id - keyIdentifier = var.cmk_keyvault_key_uri - } - } - */ - - } - kind = "hub" - }) -} \ No newline at end of file diff --git a/quickstart/101-ai-studio/main.tf b/quickstart/101-ai-studio/main.tf index c6ad21da8..ca348732e 100644 --- a/quickstart/101-ai-studio/main.tf +++ b/quickstart/101-ai-studio/main.tf @@ -1,32 +1,160 @@ -terraform { - required_version = ">= 1.0" +resource "random_pet" "rg_name" { + prefix = var.resource_group_name_prefix +} + +// RESOURCE GROUP +resource "azurerm_resource_group" "rg" { + location = var.resource_group_location + name = random_pet.rg_name.id +} + +data "azurerm_client_config" "current" { +} + +// STORAGE ACCOUNT +resource "azurerm_storage_account" "default" { + name = "${var.prefix}storage${random_string.suffix.result}" + location = azurerm_resource_group.rg.location + resource_group_name = azurerm_resource_group.rg.name + account_tier = "Standard" + account_replication_type = "GRS" + allow_nested_items_to_be_public = false +} - required_providers { - azurerm = { - source = "hashicorp/azurerm" - version = ">= 3.0, < 4.0" +// KEY VAULT +resource "azurerm_key_vault" "default" { + name = "${var.prefix}keyvault${random_string.suffix.result}" + location = azurerm_resource_group.rg.location + resource_group_name = azurerm_resource_group.rg.name + tenant_id = data.azurerm_client_config.current.tenant_id + sku_name = "standard" + purge_protection_enabled = false +} + +// AzAPI AIServices +resource "azapi_resource" "AIServicesResource"{ + type = "Microsoft.CognitiveServices/accounts@2023-10-01-preview" + name = "AIServicesResource${random_string.suffix.result}" + location = azurerm_resource_group.rg.location + parent_id = azurerm_resource_group.rg.id + + identity { + type = "SystemAssigned" + } + + body = jsonencode({ + name = "AIServicesResource${random_string.suffix.result}" + properties = { + //restore = true + customSubDomainName = "${random_string.suffix.result}domain" + apiProperties = { + statisticsEnabled = false + } } - azapi = { - source = "azure/azapi" + kind = "AIServices" + sku = { + name = var.sku } - } + }) + + response_export_values = ["*"] } -provider "azurerm" { - features { - key_vault { - recover_soft_deleted_key_vaults = false - purge_soft_delete_on_destroy = false - purge_soft_deleted_keys_on_destroy = false - } - resource_group { - prevent_deletion_if_contains_resources = false +// Azure AI Hub +resource "azapi_resource" "hub" { + type = "Microsoft.MachineLearningServices/workspaces@2024-04-01-preview" + name = "${random_pet.rg_name.id}-aih" + location = azurerm_resource_group.rg.location + parent_id = azurerm_resource_group.rg.id + + identity { + type = "SystemAssigned" + } + + body = jsonencode({ + properties = { + description = "This is my Azure AI hub" + friendlyName = "My Hub" + storageAccount = azurerm_storage_account.default.id + keyVault = azurerm_key_vault.default.id + + /* Optional: To enable these field, the corresponding dependent resources need to be uncommented. + applicationInsight = azurerm_application_insights.default.id + containerRegistry = azurerm_container_registry.default.id + */ + + /*Optional: To enable Customer Managed Keys, the corresponding + encryption = { + status = var.encryption_status + keyVaultProperties = { + keyVaultArmId = azurerm_key_vault.default.id + keyIdentifier = var.cmk_keyvault_key_uri + } + } + */ + } + kind = "hub" + }) +} + +// Azure AI Project +resource "azapi_resource" "project" { + type = "Microsoft.MachineLearningServices/workspaces@2024-04-01-preview" + name = "my-ai-project${random_string.suffix.result}" + location = azurerm_resource_group.rg.location + parent_id = azurerm_resource_group.rg.id + + identity { + type = "SystemAssigned" } + + body = jsonencode({ + properties = { + description = "This is my Azure AI PROJECT" + friendlyName = "My Project" + hubResourceId = azapi_resource.hub.id + } + kind = "project" + }) } -provider "azapi" { +// AzAPI AI Services Connection +resource "azapi_resource" "AIServicesConnection" { + type = "Microsoft.MachineLearningServices/workspaces/connections@2024-04-01-preview" + name = "Default_AIServices${random_string.suffix.result}" + parent_id = azapi_resource.hub.id + + body = jsonencode({ + properties = { + category = "AIServices", + target = jsondecode(azapi_resource.AIServicesResource.output).properties.endpoint, + authType = "AAD", + isSharedToAll = true, + metadata = { + ApiType = "Azure", + ResourceId = azapi_resource.AIServicesResource.id + } + } + }) + response_export_values = ["*"] } -data "azurerm_client_config" "current" { -} \ No newline at end of file +/* The following resources are OPTIONAL. +// APPLICATION INSIGHTS +resource "azurerm_application_insights" "default" { + name = "${var.prefix}appinsights${random_string.suffix.result}" + location = azurerm_resource_group.rg.location + resource_group_name = azurerm_resource_group.rg.name + application_type = "web" +} + +// CONTAINER REGISTRY +resource "azurerm_container_registry" "default" { + name = "${var.prefix}contreg${random_string.suffix.result}" + resource_group_name = azurerm_resource_group.rg.name + location = azurerm_resource_group.rg.location + sku = "premium" + admin_enabled = true +} +*/ \ No newline at end of file diff --git a/quickstart/101-ai-studio/output.tf b/quickstart/101-ai-studio/output.tf index c24deefa3..ae3666a1f 100644 --- a/quickstart/101-ai-studio/output.tf +++ b/quickstart/101-ai-studio/output.tf @@ -1,5 +1,5 @@ output "ResourceGroup" { - value = azurerm_resource_group.default.id + value = azurerm_resource_group.rg.id } output "HubId" { @@ -12,5 +12,4 @@ output "ProjectId" { output "endpoint" { value = jsondecode(azapi_resource.AIServicesResource.output).properties.endpoint -} - +} \ No newline at end of file diff --git a/quickstart/101-ai-studio/project.tf b/quickstart/101-ai-studio/project.tf deleted file mode 100644 index 96aee1cc2..000000000 --- a/quickstart/101-ai-studio/project.tf +++ /dev/null @@ -1,19 +0,0 @@ -resource "azapi_resource" "project" { - type = "Microsoft.MachineLearningServices/workspaces@2024-04-01-preview" - name = "my-ai-project" - location = azurerm_resource_group.default.location - parent_id = azurerm_resource_group.default.id - - identity { - type = "SystemAssigned" - } - - body = jsonencode({ - properties = { - description = "This is my Azure AI PROJECT" - friendlyName = "My Project" - hubResourceId = azapi_resource.hub.id - } - kind = "project" - }) -} \ No newline at end of file diff --git a/quickstart/101-ai-studio/providers.tf b/quickstart/101-ai-studio/providers.tf new file mode 100644 index 000000000..f802a3690 --- /dev/null +++ b/quickstart/101-ai-studio/providers.tf @@ -0,0 +1,33 @@ +terraform { + required_version = ">= 1.0" + + required_providers { + azurerm = { + source = "hashicorp/azurerm" + version = "~>3.0" + } + azapi = { + source = "azure/azapi" + } + random = { + source = "hashicorp/random" + version = "~>3.0" + } + } +} + +provider "azurerm" { + features { + key_vault { + recover_soft_deleted_key_vaults = false + purge_soft_delete_on_destroy = false + purge_soft_deleted_keys_on_destroy = false + } + resource_group { + prevent_deletion_if_contains_resources = false + } + } +} + +provider "azapi" { +} \ No newline at end of file diff --git a/quickstart/101-ai-studio/variables.tf b/quickstart/101-ai-studio/variables.tf index 2a4016840..8d6d24841 100644 --- a/quickstart/101-ai-studio/variables.tf +++ b/quickstart/101-ai-studio/variables.tf @@ -1,14 +1,19 @@ -// Names and Try are used for naming conventions in hub.tf and depende -variable "names" { - type = string - description="This variable is used to name the hub, project, and dependent resources." - default = "tftemplate" +variable "resource_group_location" { + type = string + default = "eastus" + description = "Location of the resource group." } -variable "location" { +variable "resource_group_name_prefix" { + type = string + default = "rg" + description = "Prefix of the resource group name that's combined with a random ID so name is unique in your Azure subscription." +} + +variable "prefix" { type = string - description = "This is the location for all resources" - default = "East US 2" + description="This variable is used to name the hub, project, and dependent resources." + default = "ai" } variable "sku" { @@ -23,7 +28,7 @@ resource "random_string" "suffix" { upper = false } -/*Optional: For Customer Managed Keys, uncomment this part AND the corresponding section in hub.tf +/*Optional: For Customer Managed Keys, uncomment this part AND the corresponding section in main.tf variable "cmk_keyvault_key_uri" { description = "Key vault uri to access the encryption key." }