Skip to content

Commit

Permalink
added random sufix to service names
Browse files Browse the repository at this point in the history
  • Loading branch information
cmendible committed Jan 24, 2024
1 parent 970de08 commit c15b83b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 22 deletions.
45 changes: 28 additions & 17 deletions infra/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,26 @@ resource "random_id" "random" {
byte_length = 8
}

resource "azurerm_resource_group" "rg" {
name = var.resource_group_name
location = var.location
locals {
sufix = var.use_random_suffix ? substr(lower(random_id.random.hex), 1, 4) : ""
name_sufix = var.use_random_suffix ? "-${local.sufix}" : ""
resource_group_name = "${var.resource_group_name}${local.name_sufix}"
storage_account_name = "${var.storage_account_name}${local.sufix}"
azopenai_name = "${var.azopenai_name}${local.name_sufix}"
content_safety_name = "${var.content_safety_name}${local.name_sufix}"
cognitive_services_name = "${var.cognitive_services_name}${local.name_sufix}"
speech_name = "${var.speech_name}${local.name_sufix}"
bing_name = "${var.bing_name}${local.name_sufix}"
search_name = "${var.search_name}${local.name_sufix}"
form_recognizer_name = "${var.form_recognizer_name}${local.name_sufix}"
apim_name = "${var.apim_name}${local.name_sufix}"
appi_name = "${var.appi_name}${local.name_sufix}"
log_name = "${var.log_name}${local.name_sufix}"
}

locals {
name_sufix = substr(lower(random_id.random.hex), 1, 4)
storage_account_name = "${var.storage_account_name}${local.name_sufix}"
resource "azurerm_resource_group" "rg" {
name = local.resource_group_name
location = var.location
}

module "vnet" {
Expand All @@ -37,7 +49,7 @@ module "apim" {
source = "./modules/apim"
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
apim_name = var.apim_name
apim_name = local.apim_name
apim_subnet_id = module.vnet.apim_subnet_id
publisher_name = var.publisher_name
publisher_email = var.publisher_email
Expand Down Expand Up @@ -68,29 +80,29 @@ module "search" {
source = "./modules/search"
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
search_name = var.search_name
search_name = local.search_name
principal_id = module.mi.principal_id
}

module "form_recognizer" {
source = "./modules/form"
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
form_recognizer_name = var.form_recognizer_name
form_recognizer_name = local.form_recognizer_name
}

module "log" {
source = "./modules/log"
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
log_name = var.log_name
log_name = local.log_name
}

module "appi" {
source = "./modules/appi"
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
appi_name = var.appi_name
appi_name = local.appi_name
log_id = module.log.log_id
}

Expand All @@ -106,8 +118,7 @@ module "openai" {
source = "./modules/openai"
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
secondary_location = var.secondary_location
azopenai_name = var.azopenai_name
azopenai_name = local.azopenai_name
principal_id = module.mi.principal_id
}

Expand All @@ -117,10 +128,10 @@ module "cog" {
resource_group_name = azurerm_resource_group.rg.name
resource_group_id = azurerm_resource_group.rg.id
principal_id = module.mi.principal_id
bing_name = var.bing_name
cognitive_services_name = var.cognitive_services_name
content_safety_name = var.content_safety_name
speech_name = var.speech_name
bing_name = local.bing_name
cognitive_services_name = local.cognitive_services_name
content_safety_name = local.content_safety_name
speech_name = local.speech_name
}

module "cae" {
Expand Down
1 change: 0 additions & 1 deletion infra/modules/openai/variables.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
variable "resource_group_name" {}
variable "location" {}
variable "secondary_location" {}
variable "azopenai_name" {}
variable "principal_id" {}
9 changes: 5 additions & 4 deletions infra/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ variable "resource_group_name" {
}

variable "location" {
default = "West Europe"
}

variable "secondary_location" {
default = "North Europe"
}

Expand Down Expand Up @@ -57,6 +53,7 @@ variable "appi_name" {
variable "publisher_name" {
default = "contoso"
}

variable "publisher_email" {
default = "[email protected]"
}
Expand Down Expand Up @@ -85,6 +82,10 @@ variable "ca_aihub_name" {
default = "ca-aihub-activate-genai"
}

variable "use_random_suffix" {
default = true
}

variable "enable_entra_id_authentication" {
default = true
}
Expand Down

0 comments on commit c15b83b

Please sign in to comment.