Skip to content

Commit 9b87ab9

Browse files
Merge pull request #616 from microsoft/post-avm-script-fix
fix: updated post deployment script issue fix
2 parents 14eed6a + bc5c857 commit 9b87ab9

File tree

2 files changed

+47
-12
lines changed

2 files changed

+47
-12
lines changed

infra/scripts/Team-Config-And-Data.ps1

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,28 @@ function Get-ValuesFromAzdEnv {
4848
return $true
4949
}
5050

51+
function Get-DeploymentValue {
52+
param(
53+
[object]$DeploymentOutputs,
54+
[string]$PrimaryKey,
55+
[string]$FallbackKey
56+
)
57+
58+
$value = $null
59+
60+
# Try primary key first
61+
if ($DeploymentOutputs.PSObject.Properties[$PrimaryKey]) {
62+
$value = $DeploymentOutputs.$PrimaryKey.value
63+
}
64+
65+
# If primary key failed, try fallback key
66+
if (-not $value -and $DeploymentOutputs.PSObject.Properties[$FallbackKey]) {
67+
$value = $DeploymentOutputs.$FallbackKey.value
68+
}
69+
70+
return $value
71+
}
72+
5173
function Get-ValuesFromAzDeployment {
5274
Write-Host "Getting values from Azure deployment outputs..."
5375

@@ -67,12 +89,12 @@ function Get-ValuesFromAzDeployment {
6789
return $false
6890
}
6991

70-
# Extract specific outputs
71-
$script:storageAccount = $deploymentOutputs.azurE_STORAGE_ACCOUNT_NAME.value
72-
$script:blobContainer = $deploymentOutputs.azurE_STORAGE_CONTAINER_NAME.value
73-
$script:aiSearch = $deploymentOutputs.azurE_AI_SEARCH_NAME.value
74-
$script:aiSearchIndex = $deploymentOutputs.azurE_AI_SEARCH_INDEX_NAME.value
75-
$script:backendUrl = $deploymentOutputs.backenD_URL.value
92+
# Extract specific outputs with fallback logic
93+
$script:storageAccount = Get-DeploymentValue -DeploymentOutputs $deploymentOutputs -PrimaryKey "azurE_STORAGE_ACCOUNT_NAME" -FallbackKey "azureStorageAccountName"
94+
$script:blobContainer = Get-DeploymentValue -DeploymentOutputs $deploymentOutputs -PrimaryKey "azurE_STORAGE_CONTAINER_NAME" -FallbackKey "azureStorageContainerName"
95+
$script:aiSearch = Get-DeploymentValue -DeploymentOutputs $deploymentOutputs -PrimaryKey "azurE_AI_SEARCH_NAME" -FallbackKey "azureAiSearchName"
96+
$script:aiSearchIndex = Get-DeploymentValue -DeploymentOutputs $deploymentOutputs -PrimaryKey "azurE_AI_SEARCH_INDEX_NAME" -FallbackKey "azureAiSearchIndexName"
97+
$script:backendUrl = Get-DeploymentValue -DeploymentOutputs $deploymentOutputs -PrimaryKey "backenD_URL" -FallbackKey "backendUrl"
7698

7799
# Validate that we extracted all required values
78100
if (-not $script:storageAccount -or -not $script:blobContainer -or -not $script:aiSearch -or -not $script:aiSearchIndex -or -not $script:backendUrl) {

infra/scripts/team_config_and_data.sh

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,19 @@ get_values_from_azd_env() {
4747
return 0
4848
}
4949

50+
# Helper function to extract value with fallback
51+
extract_value() {
52+
local primary_key="$1"
53+
local fallback_key="$2"
54+
local result
55+
56+
result=$(echo "$deploymentOutputs" | grep -A 3 "\"$primary_key\"" | grep '"value"' | sed 's/.*"value": *"\([^"]*\)".*/\1/')
57+
if [ -z "$result" ]; then
58+
result=$(echo "$deploymentOutputs" | grep -A 3 "\"$fallback_key\"" | grep '"value"' | sed 's/.*"value": *"\([^"]*\)".*/\1/')
59+
fi
60+
echo "$result"
61+
}
62+
5063
get_values_from_az_deployment() {
5164
echo "Getting values from Azure deployment outputs..."
5265

@@ -66,12 +79,12 @@ get_values_from_az_deployment() {
6679
return 1
6780
fi
6881

69-
# Extract specific outputs
70-
storageAccount=$(echo "$deploymentOutputs" | grep -A 3 '"azurE_STORAGE_ACCOUNT_NAME"' | grep '"value"' | sed 's/.*"value": *"\([^"]*\)".*/\1/')
71-
blobContainer=$(echo "$deploymentOutputs" | grep -A 3 '"azurE_STORAGE_CONTAINER_NAME"' | grep '"value"' | sed 's/.*"value": *"\([^"]*\)".*/\1/')
72-
aiSearch=$(echo "$deploymentOutputs" | grep -A 3 '"azurE_AI_SEARCH_NAME"' | grep '"value"' | sed 's/.*"value": *"\([^"]*\)".*/\1/')
73-
aiSearchIndex=$(echo "$deploymentOutputs" | grep -A 3 '"azurE_AI_SEARCH_INDEX_NAME"' | grep '"value"' | sed 's/.*"value": *"\([^"]*\)".*/\1/')
74-
backendUrl=$(echo "$deploymentOutputs" | grep -A 3 '"backenD_URL"' | grep '"value"' | sed 's/.*"value": *"\([^"]*\)".*/\1/')
82+
# Extract all values using the helper function
83+
storageAccount=$(extract_value "azurE_STORAGE_ACCOUNT_NAME" "azureStorageAccountName")
84+
blobContainer=$(extract_value "azurE_STORAGE_CONTAINER_NAME" "azureStorageContainerName")
85+
aiSearch=$(extract_value "azurE_AI_SEARCH_NAME" "azureAiSearchName")
86+
aiSearchIndex=$(extract_value "azurE_AI_SEARCH_INDEX_NAME" "azureAiSearchIndexName")
87+
backendUrl=$(extract_value "backenD_URL" "backendUrl")
7588

7689
# Validate that we extracted all required values
7790
if [ -z "$storageAccount" ] || [ -z "$blobContainer" ] || [ -z "$aiSearch" ] || [ -z "$aiSearchIndex" ] || [ -z "$backendUrl" ]; then

0 commit comments

Comments
 (0)