Skip to content

Commit

Permalink
Refactor Bing resource deployment and update module outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
cmendible committed Mar 7, 2024
1 parent d5fd31d commit 56b1321
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 27 deletions.
3 changes: 1 addition & 2 deletions infra/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ module "cog" {
resource_group_name = azurerm_resource_group.rg.name
resource_group_id = azurerm_resource_group.rg.id
bing_name = local.bing_name
deploy_bing = var.deploy_bing
cognitive_services_name = local.cognitive_services_name
content_safety_name = local.content_safety_name
speech_name = local.speech_name
Expand Down Expand Up @@ -220,7 +219,7 @@ module "ca_aihub" {
speech_key = module.cog.speech_key

storage_connection_string = module.st.connection_string
bing_key = var.bing_key
bing_key = module.cog.bing_key

tenant_id = data.azurerm_subscription.current.tenant_id
managed_identity_client_id = module.mi.client_id
Expand Down
74 changes: 58 additions & 16 deletions infra/modules/cog/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,66 @@ resource "azurerm_cognitive_account" "speech" {
custom_subdomain_name = var.speech_name
}

resource "azapi_resource" "bing" {
count = var.deploy_bing ? 1 : 0
name = var.bing_name
location = "global"
parent_id = var.resource_group_id
type = "Microsoft.Bing/accounts@2020-06-10"
schema_validation_enabled = false // Required for this service otherwise it will fail.

body = jsonencode({
kind = "Bing.Search.v7"
sku = {
name = "S1"
}
properties : {
statisticsEnabled = true
resource "azurerm_resource_group_template_deployment" "main" {
name = var.bing_name
resource_group_name = var.resource_group_name
deployment_mode = "Incremental"
parameters_content = jsonencode({
"name" = {
value = var.bing_name
},
"location" = {
value = "Global"
},
"sku" = {
value = S1
},
"kind" = {
value = "Bing.Search.v7"
}
})
response_export_values = ["properties.endpoint"]
template_content = <<TEMPLATE
{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"name": {
"type": "String"
},
"location": {
"type": "String"
},
"sku": {
"type": "String"
},
"kind": {
"type": "String"
}
},
"resources": [
{
"apiVersion": "2020-06-10",
"name": "[parameters('name')]",
"location": "[parameters('location')]",
"type": "Microsoft.Bing/accounts",
"kind": "[parameters('kind')]",
"sku": {
"name": "[parameters('sku')]"
}
}
],
"outputs": {
"accessKeys": {
"type": "object",
"value": {
"key1": "[listKeys(resourceId('Microsoft.Bing/accounts', parameters('name')), '2020-06-10').key1]",
"key2": "[listKeys(resourceId('Microsoft.Bing/accounts', parameters('name')), '2020-06-10').key2]"
}
}
}
}
TEMPLATE
}

resource "azurerm_role_assignment" "reader" {
Expand Down
4 changes: 4 additions & 0 deletions infra/modules/cog/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@ output "cognitive_service_key" {
output "speech_key" {
value = azurerm_cognitive_account.speech.primary_access_key
}

output "bing_key" {
value = jsondecode(azurerm_resource_group_template_deployment.main.output_content).accessKeys.value.key1
}
1 change: 0 additions & 1 deletion infra/modules/cog/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ variable "content_safety_name" {}
variable "cognitive_services_name" {}
variable "speech_name" {}
variable "bing_name" {}
variable "deploy_bing" {}
variable "content_safety_storage_resource_id" {}
8 changes: 0 additions & 8 deletions infra/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,6 @@ variable "enable_apim" {
default = false
}

variable "deploy_bing" {
default = false
}

variable "bing_key" {
default = "<replace with a valid bing key>"
}

variable "pbi_report_link" {
default = ""
}

0 comments on commit 56b1321

Please sign in to comment.