From 1a2a4aac2469a816dd2db687f92678137cd28201 Mon Sep 17 00:00:00 2001 From: Harsh-Microsoft Date: Wed, 31 Dec 2025 14:09:40 +0530 Subject: [PATCH 1/4] Addrd fallback function to retrieve values using resource naming convention suffix --- infra/main.bicep | 1 + infra/main_custom.bicep | 1 + .../Selecting-Team-Config-And-Data.ps1 | 81 ++++++++++++++++++- .../scripts/selecting_team_config_and_data.sh | 81 ++++++++++++++++++- 4 files changed, 158 insertions(+), 6 deletions(-) diff --git a/infra/main.bicep b/infra/main.bicep index eaaaff3d4..4f6070948 100644 --- a/infra/main.bicep +++ b/infra/main.bicep @@ -241,6 +241,7 @@ resource resourceGroupTags 'Microsoft.Resources/tags@2021-04-01' = { Type: enablePrivateNetworking ? 'WAF' : 'Non-WAF' CreatedBy: createdBy DeploymentName: deployment().name + SolutionSuffix: solutionSuffix } } } diff --git a/infra/main_custom.bicep b/infra/main_custom.bicep index b46637b1b..eaaf02a96 100644 --- a/infra/main_custom.bicep +++ b/infra/main_custom.bicep @@ -239,6 +239,7 @@ resource resourceGroupTags 'Microsoft.Resources/tags@2021-04-01' = { Type: enablePrivateNetworking ? 'WAF' : 'Non-WAF' CreatedBy: createdBy DeploymentName: deployment().name + SolutionSuffix: solutionSuffix } } } diff --git a/infra/scripts/Selecting-Team-Config-And-Data.ps1 b/infra/scripts/Selecting-Team-Config-And-Data.ps1 index 62dbf90f7..20ffb0305 100644 --- a/infra/scripts/Selecting-Team-Config-And-Data.ps1 +++ b/infra/scripts/Selecting-Team-Config-And-Data.ps1 @@ -148,6 +148,70 @@ function Get-ValuesFromAzDeployment { return $true } +function Get-ValuesUsingSolutionSuffix { + Write-Host "Getting values from resource naming convention using solution suffix..." + + # Get the solution suffix from resource group tags + $solutionSuffix = az group show --name $ResourceGroup --query "tags.SolutionSuffix" -o tsv + if (-not $solutionSuffix) { + Write-Host "Error: Could not find SolutionSuffix tag in resource group." + return $false + } + + Write-Host "Found solution suffix: $solutionSuffix" + + # Reconstruct resource names using same naming convention as Bicep + $script:storageAccount = "st$solutionSuffix" -replace '-', '' # Remove dashes like Bicep does + $script:aiSearch = "srch-$solutionSuffix" + $containerAppName = "ca-$solutionSuffix" + + # Query dynamic value (backend URL) from Container App + Write-Host "Querying backend URL from Container App..." + $backendFqdn = az containerapp show ` + --name $containerAppName ` + --resource-group $ResourceGroup ` + --query "properties.configuration.ingress.fqdn" ` + -o tsv 2>$null + + if (-not $backendFqdn) { + Write-Host "Error: Could not get Container App FQDN. Container App may not be deployed yet." + return $false + } + + $script:backendUrl = "https://$backendFqdn" + + # Hardcoded container names (These don't follow the suffix pattern in Bicep, hence need to be changed here if changed in Bicep) + $script:blobContainerForRetailCustomer = "retail-dataset-customer" + $script:blobContainerForRetailOrder = "retail-dataset-order" + $script:blobContainerForRFPSummary = "rfp-summary-dataset" + $script:blobContainerForRFPRisk = "rfp-risk-dataset" + $script:blobContainerForRFPCompliance = "rfp-compliance-dataset" + $script:blobContainerForContractSummary = "contract-summary-dataset" + $script:blobContainerForContractRisk = "contract-risk-dataset" + $script:blobContainerForContractCompliance = "contract-compliance-dataset" + + # Hardcoded index names (These don't follow the suffix pattern in Bicep, hence need to be changed here if changed in Bicep) + $script:aiSearchIndexForRetailCustomer = "macae-retail-customer-index" + $script:aiSearchIndexForRetailOrder = "macae-retail-order-index" + $script:aiSearchIndexForRFPSummary = "macae-rfp-summary-index" + $script:aiSearchIndexForRFPRisk = "macae-rfp-risk-index" + $script:aiSearchIndexForRFPCompliance = "macae-rfp-compliance-index" + $script:aiSearchIndexForContractSummary = "contract-summary-doc-index" + $script:aiSearchIndexForContractRisk = "contract-risk-doc-index" + $script:aiSearchIndexForContractCompliance = "contract-compliance-doc-index" + + $script:directoryPath = "data/agent_teams" + + # Validate that we got all critical values + if (-not $script:storageAccount -or -not $script:aiSearch -or -not $script:backendUrl) { + Write-Host "Error: Failed to reconstruct all required resource names." + return $false + } + + Write-Host "Successfully reconstructed values from resource naming convention." + return $true +} + # Authenticate with Azure try { $null = az account show 2>$null @@ -233,12 +297,23 @@ if (-not $ResourceGroup) { exit 1 } } else { - # Resource group provided - use deployment outputs + # Resource group provided - try deployment outputs first, then fallback to naming convention Write-Host "Resource group provided: $ResourceGroup" if (-not (Get-ValuesFromAzDeployment)) { - Write-Host "Failed to get values from deployment outputs." - exit 1 + Write-Host "" + Write-Host "Warning: Could not retrieve values from deployment outputs (deployment may be deleted)." + Write-Host "Attempting fallback method: reconstructing values from resource naming convention..." + Write-Host "" + + if (-not (Get-ValuesUsingSolutionSuffix)) { + Write-Host "" + Write-Host "Error: Both methods failed to retrieve configuration values." + Write-Host "Please ensure:" + Write-Host " 1. The deployment exists and has a DeploymentName tag, OR" + Write-Host " 2. The resource group has a SolutionSuffix tag" + exit 1 + } } } diff --git a/infra/scripts/selecting_team_config_and_data.sh b/infra/scripts/selecting_team_config_and_data.sh index 3ccaba4c5..3c0edff91 100644 --- a/infra/scripts/selecting_team_config_and_data.sh +++ b/infra/scripts/selecting_team_config_and_data.sh @@ -149,6 +149,70 @@ function get_values_from_az_deployment() { return 0 } +function get_values_using_solution_suffix() { + echo "Getting values from resource naming convention using solution suffix..." + + # Get the solution suffix from resource group tags + solutionSuffix=$(az group show --name "$ResourceGroup" --query "tags.SolutionSuffix" -o tsv) + if [[ -z "$solutionSuffix" ]]; then + echo "Error: Could not find SolutionSuffix tag in resource group." + return 1 + fi + + echo "Found solution suffix: $solutionSuffix" + + # Reconstruct resource names using same naming convention as Bicep + storageAccount=$(echo "st${solutionSuffix}" | tr -d '-') # Remove dashes like Bicep does + aiSearch="srch-${solutionSuffix}" + containerAppName="ca-${solutionSuffix}" + + # Query dynamic value (backend URL) from Container App + echo "Querying backend URL from Container App..." + backendFqdn=$(az containerapp show \ + --name "$containerAppName" \ + --resource-group "$ResourceGroup" \ + --query "properties.configuration.ingress.fqdn" \ + -o tsv 2>/dev/null) + + if [[ -z "$backendFqdn" ]]; then + echo "Error: Could not get Container App FQDN. Container App may not be deployed yet." + return 1 + fi + + backendUrl="https://${backendFqdn}" + + # Hardcoded container names (These don't follow the suffix pattern in Bicep, hence need to be changed here if changed in Bicep) + blobContainerForRetailCustomer="retail-dataset-customer" + blobContainerForRetailOrder="retail-dataset-order" + blobContainerForRFPSummary="rfp-summary-dataset" + blobContainerForRFPRisk="rfp-risk-dataset" + blobContainerForRFPCompliance="rfp-compliance-dataset" + blobContainerForContractSummary="contract-summary-dataset" + blobContainerForContractRisk="contract-risk-dataset" + blobContainerForContractCompliance="contract-compliance-dataset" + + # Hardcoded index names (These don't follow the suffix pattern in Bicep, hence need to be changed here if changed in Bicep) + aiSearchIndexForRetailCustomer="macae-retail-customer-index" + aiSearchIndexForRetailOrder="macae-retail-order-index" + aiSearchIndexForRFPSummary="macae-rfp-summary-index" + aiSearchIndexForRFPRisk="macae-rfp-risk-index" + aiSearchIndexForRFPCompliance="macae-rfp-compliance-index" + aiSearchIndexForContractSummary="contract-summary-doc-index" + aiSearchIndexForContractRisk="contract-risk-doc-index" + aiSearchIndexForContractCompliance="contract-compliance-doc-index" + + directoryPath="data/agent_teams" + + # Validate that we got all critical values + if [[ -z "$storageAccount" || -z "$aiSearch" || -z "$backendUrl" ]]; then + echo "Error: Failed to reconstruct all required resource names." + return 1 + fi + + echo "Successfully reconstructed values from resource naming convention." + return 0 +} + # Authenticate with Azure if az account show &> /dev/null; then echo "Already authenticated with Azure." @@ -231,12 +295,23 @@ if [[ -z "$ResourceGroup" ]]; then exit 1 fi else - # Resource group provided - use deployment outputs + # Resource group provided - use deployment outputs, then fallback to naming convention echo "Resource group provided: $ResourceGroup" if ! get_values_from_az_deployment; then - echo "Failed to get values from deployment outputs." - exit 1 + echo "" + echo "Warning: Could not retrieve values from deployment outputs (deployment may be deleted)." + echo "Attempting fallback method: reconstructing values from resource naming convention..." + echo "" + + if ! get_values_using_solution_suffix; then + echo "" + echo "Error: Both methods failed to retrieve configuration values." + echo "Please ensure:" + echo " 1. The deployment exists and has a DeploymentName tag, OR" + echo " 2. The resource group has a SolutionSuffix tag" + exit 1 + fi fi fi From a805c7441c3928a258d3b21224c800605344f9fb Mon Sep 17 00:00:00 2001 From: Harsh-Microsoft Date: Wed, 31 Dec 2025 13:38:56 +0000 Subject: [PATCH 2/4] Add sleep delay after enabling public access for storage account and search service --- infra/scripts/selecting_team_config_and_data.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/infra/scripts/selecting_team_config_and_data.sh b/infra/scripts/selecting_team_config_and_data.sh index 3c0edff91..e5de18a57 100644 --- a/infra/scripts/selecting_team_config_and_data.sh +++ b/infra/scripts/selecting_team_config_and_data.sh @@ -480,6 +480,7 @@ if [[ "$useCaseSelection" == "1" || "$useCaseSelection" == "2" || "$useCaseSelec stIsPublicAccessDisabled=true echo "Enabling public access for storage account: $storageAccount" az storage account update --name "$storageAccount" --public-network-access enabled --default-action Allow --output none + sleep 60 if [[ $? -ne 0 ]]; then echo "Error: Failed to enable public access for storage account." exit 1 @@ -493,6 +494,7 @@ if [[ "$useCaseSelection" == "1" || "$useCaseSelection" == "2" || "$useCaseSelec srchIsPublicAccessDisabled=true echo "Enabling public access for search service: $aiSearch" az search service update --name "$aiSearch" --resource-group "$ResourceGroup" --public-network-access enabled --output none + sleep 60 if [[ $? -ne 0 ]]; then echo "Error: Failed to enable public access for search service." exit 1 From 357fc0931e682cea2235e8b2fe03dbfdca0c3852 Mon Sep 17 00:00:00 2001 From: Harsh-Microsoft Date: Thu, 1 Jan 2026 04:54:42 +0000 Subject: [PATCH 3/4] Add sleep delay after enabling public access for storage account and search service --- infra/scripts/Selecting-Team-Config-And-Data.ps1 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/infra/scripts/Selecting-Team-Config-And-Data.ps1 b/infra/scripts/Selecting-Team-Config-And-Data.ps1 index 20ffb0305..70d05fe49 100644 --- a/infra/scripts/Selecting-Team-Config-And-Data.ps1 +++ b/infra/scripts/Selecting-Team-Config-And-Data.ps1 @@ -505,6 +505,7 @@ if($useCaseSelection -eq "1"-or $useCaseSelection -eq "2" -or $useCaseSelection $stIsPublicAccessDisabled = $true Write-Host "Enabling public access for storage account: $storageAccount" az storage account update --name $storageAccount --public-network-access enabled --default-action Allow --output none + Start-Sleep -Seconds 60 if ($LASTEXITCODE -ne 0) { Write-Host "Error: Failed to enable public access for storage account." exit 1 @@ -519,6 +520,7 @@ if($useCaseSelection -eq "1"-or $useCaseSelection -eq "2" -or $useCaseSelection $srchIsPublicAccessDisabled = $true Write-Host "Enabling public access for search service: $aiSearch" az search service update --name $aiSearch --resource-group $ResourceGroup --public-network-access enabled --output none + Start-Sleep -Seconds 60 if ($LASTEXITCODE -ne 0) { Write-Host "Error: Failed to enable public access for search service." exit 1 From 1ad02ae6e4d55baee2a4741136da2d4ee52eb33a Mon Sep 17 00:00:00 2001 From: Harsh-Microsoft Date: Thu, 1 Jan 2026 13:49:38 +0530 Subject: [PATCH 4/4] Add sleep delay after enabling public access for storage account and search service --- infra/scripts/Selecting-Team-Config-And-Data.ps1 | 4 ++-- infra/scripts/selecting_team_config_and_data.sh | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/infra/scripts/Selecting-Team-Config-And-Data.ps1 b/infra/scripts/Selecting-Team-Config-And-Data.ps1 index 70d05fe49..68d39580e 100644 --- a/infra/scripts/Selecting-Team-Config-And-Data.ps1 +++ b/infra/scripts/Selecting-Team-Config-And-Data.ps1 @@ -505,11 +505,11 @@ if($useCaseSelection -eq "1"-or $useCaseSelection -eq "2" -or $useCaseSelection $stIsPublicAccessDisabled = $true Write-Host "Enabling public access for storage account: $storageAccount" az storage account update --name $storageAccount --public-network-access enabled --default-action Allow --output none - Start-Sleep -Seconds 60 if ($LASTEXITCODE -ne 0) { Write-Host "Error: Failed to enable public access for storage account." exit 1 } + Start-Sleep -Seconds 60 } else { Write-Host "Public access is already enabled for storage account: $storageAccount" @@ -520,11 +520,11 @@ if($useCaseSelection -eq "1"-or $useCaseSelection -eq "2" -or $useCaseSelection $srchIsPublicAccessDisabled = $true Write-Host "Enabling public access for search service: $aiSearch" az search service update --name $aiSearch --resource-group $ResourceGroup --public-network-access enabled --output none - Start-Sleep -Seconds 60 if ($LASTEXITCODE -ne 0) { Write-Host "Error: Failed to enable public access for search service." exit 1 } + Start-Sleep -Seconds 60 } else { Write-Host "Public access is already enabled for search service: $AiSearch" diff --git a/infra/scripts/selecting_team_config_and_data.sh b/infra/scripts/selecting_team_config_and_data.sh index e5de18a57..17551239e 100644 --- a/infra/scripts/selecting_team_config_and_data.sh +++ b/infra/scripts/selecting_team_config_and_data.sh @@ -480,11 +480,11 @@ if [[ "$useCaseSelection" == "1" || "$useCaseSelection" == "2" || "$useCaseSelec stIsPublicAccessDisabled=true echo "Enabling public access for storage account: $storageAccount" az storage account update --name "$storageAccount" --public-network-access enabled --default-action Allow --output none - sleep 60 if [[ $? -ne 0 ]]; then echo "Error: Failed to enable public access for storage account." exit 1 fi + sleep 60 else echo "Public access is already enabled for storage account: $storageAccount" fi @@ -494,11 +494,11 @@ if [[ "$useCaseSelection" == "1" || "$useCaseSelection" == "2" || "$useCaseSelec srchIsPublicAccessDisabled=true echo "Enabling public access for search service: $aiSearch" az search service update --name "$aiSearch" --resource-group "$ResourceGroup" --public-network-access enabled --output none - sleep 60 if [[ $? -ne 0 ]]; then echo "Error: Failed to enable public access for search service." exit 1 fi + sleep 60 else echo "Public access is already enabled for search service: $aiSearch" fi