Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KyleWerts/7279-Bing-Search-KeyVault #599

Merged
merged 15 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions infra/core/ai/bingSearch/bingSearch.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ data "template_file" "workflow" {
}

resource "azurerm_resource_group_template_deployment" "bing_search" {
count = var.enableWebChat ? 1 : 0
resource_group_name = var.resourceGroupName
parameters_content = jsonencode({
"name" = { value = "${var.name}" },
Expand All @@ -23,4 +24,10 @@ resource "azurerm_resource_group_template_deployment" "bing_search" {
# this ensures the keys are up-to-date
name = "bingsearch-${filemd5(local.arm_file_path)}"
deployment_mode = "Incremental"
}
dayland marked this conversation as resolved.
Show resolved Hide resolved

resource "azurerm_key_vault_secret" "bing_search_key" {
name = "BINGSEARCH-KEY"
value = var.enableWebChat ? jsondecode(azurerm_resource_group_template_deployment.bing_search[0].output_content).key1.value : ""
key_vault_id = var.keyVaultId
}
6 changes: 3 additions & 3 deletions infra/core/ai/bingSearch/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
output "id" {
value = jsondecode(azurerm_resource_group_template_deployment.bing_search.output_content).id.value
value = var.enableWebChat ? jsondecode(azurerm_resource_group_template_deployment.bing_search[0].output_content).id.value : ""
}

output "endpoint" {
value = jsondecode(azurerm_resource_group_template_deployment.bing_search.output_content).endpoint.value
value = var.enableWebChat ? jsondecode(azurerm_resource_group_template_deployment.bing_search[0].output_content).endpoint.value : ""
}

output "key" {
value = jsondecode(azurerm_resource_group_template_deployment.bing_search.output_content).key1.value
value = var.enableWebChat ? jsondecode(azurerm_resource_group_template_deployment.bing_search[0].output_content).key1.value : ""
}
11 changes: 10 additions & 1 deletion infra/core/ai/bingSearch/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,16 @@ variable "sku" {
type = string
}


variable "arm_template_schema_mgmt_api" {
type = string
}

variable "keyVaultId" {
type = string
sensitive = true
}

variable "enableWebChat" {
description = "A flag to enable or disable web chat."
type = bool
}
11 changes: 6 additions & 5 deletions infra/core/host/webapp/webapp.tf
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,12 @@ resource "azurerm_linux_web_app" "app_service" {
"SCM_DO_BUILD_DURING_DEPLOYMENT" = lower(tostring(var.scmDoBuildDuringDeployment))
"ENABLE_ORYX_BUILD" = lower(tostring(var.enableOryxBuild))
"APPLICATIONINSIGHTS_CONNECTION_STRING" = var.applicationInsightsConnectionString
"AZURE_SEARCH_SERVICE_KEY" = "@Microsoft.KeyVault(SecretUri=${var.keyVaultUri}secrets/AZURE-SEARCH-SERVICE-KEY)"
"COSMOSDB_KEY" = "@Microsoft.KeyVault(SecretUri=${var.keyVaultUri}secrets/COSMOSDB-KEY)"
"AZURE_BLOB_STORAGE_KEY" = "@Microsoft.KeyVault(SecretUri=${var.keyVaultUri}secrets/AZURE-BLOB-STORAGE-KEY)"
"ENRICHMENT_KEY" = "@Microsoft.KeyVault(SecretUri=${var.keyVaultUri}secrets/ENRICHMENT-KEY)"
"AZURE_OPENAI_SERVICE_KEY" = "@Microsoft.KeyVault(SecretUri=${var.keyVaultUri}secrets/AZURE-OPENAI-SERVICE-KEY)"
"AZURE_SEARCH_SERVICE_KEY" = "@Microsoft.KeyVault(SecretUri=${var.keyVaultUri}secrets/AZURE-SEARCH-SERVICE-KEY)"
dayland marked this conversation as resolved.
Show resolved Hide resolved
"COSMOSDB_KEY" = "@Microsoft.KeyVault(SecretUri=${var.keyVaultUri}secrets/COSMOSDB-KEY)"
"BING_SEARCH_KEY" = "@Microsoft.KeyVault(SecretUri=${var.keyVaultUri}secrets/BINGSEARCH-KEY)"
"AZURE_BLOB_STORAGE_KEY" = "@Microsoft.KeyVault(SecretUri=${var.keyVaultUri}secrets/AZURE-BLOB-STORAGE-KEY)"
"ENRICHMENT_KEY" = "@Microsoft.KeyVault(SecretUri=${var.keyVaultUri}secrets/ENRICHMENT-KEY)"
"AZURE_OPENAI_SERVICE_KEY" = "@Microsoft.KeyVault(SecretUri=${var.keyVaultUri}secrets/AZURE-OPENAI-SERVICE-KEY)"
}
)

Expand Down
6 changes: 3 additions & 3 deletions infra/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,7 @@ module "backend" {
APPLICATION_TITLE = var.applicationtitle == "" ? "Information Assistant, built with Azure OpenAI" : var.applicationtitle
AZURE_AI_TRANSLATION_DOMAIN = var.azure_ai_translation_domain
USE_SEMANTIC_RERANKER = var.use_semantic_reranker
BING_SEARCH_ENDPOINT = var.enableWebChat ? module.bingSearch[0].endpoint : ""
BING_SEARCH_KEY = var.enableWebChat ? module.bingSearch[0].key : ""
BING_SEARCH_ENDPOINT = var.enableWebChat ? module.bingSearch.endpoint : ""
ENABLE_WEB_CHAT = var.enableWebChat
ENABLE_BING_SAFE_SEARCH = var.enableBingSafeSearch
ENABLE_UNGROUNDED_CHAT = var.enableUngroundedChat
Expand Down Expand Up @@ -475,13 +474,14 @@ module "kvModule" {
}

module "bingSearch" {
count = var.enableWebChat ? 1 : 0
source = "./core/ai/bingSearch"
name = "infoasst-bing-${random_string.random.result}"
resourceGroupName = azurerm_resource_group.rg.name
tags = local.tags
sku = "S1" //supported SKUs can be found at https://www.microsoft.com/en-us/bing/apis/pricing
arm_template_schema_mgmt_api = var.arm_template_schema_mgmt_api
keyVaultId = module.kvModule.keyVaultId
enableWebChat = var.enableWebChat
}

// DEPLOYMENT OF AZURE CUSTOMER ATTRIBUTION TAG
Expand Down
4 changes: 2 additions & 2 deletions infra/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,11 @@ output "AZURE_ENVIRONMENT" {
}

output "BING_SEARCH_ENDPOINT" {
value = var.enableWebChat ? module.bingSearch[0].endpoint : ""
value = var.enableWebChat ? module.bingSearch.endpoint : ""
}

output "BING_SEARCH_KEY" {
value = var.enableWebChat ? module.bingSearch[0].key : ""
value = var.enableWebChat ? module.bingSearch.key : ""
}

output "ENABLE_BING_SAFE_SEARCH" {
Expand Down
2 changes: 1 addition & 1 deletion scripts/json-to-env.webapp.debug.sh
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ fi
keyVaultName=$(cat inf_output.json | jq -r .DEPLOYMENT_KEYVAULT_NAME.value)

# Names of your secrets
secretNames=("AZURE-SEARCH-SERVICE-KEY" "AZURE-BLOB-STORAGE-KEY" "BLOB-CONNECTION-STRING" "COSMOSDB-KEY" "AZURE-OPENAI-SERVICE-KEY" "AZURE-CLIENT-SECRET" "ENRICHMENT-KEY")
secretNames=("AZURE-SEARCH-SERVICE-KEY" "AZURE-BLOB-STORAGE-KEY" "BLOB-CONNECTION-STRING" "COSMOSDB-KEY" "BINGSEARCH-KEY" "AZURE-OPENAI-SERVICE-KEY" "AZURE-CLIENT-SECRET" "ENRICHMENT-KEY")

# Retrieve and export each secret
for secretName in "${secretNames[@]}"; do
Expand Down
Loading