Skip to content

Commit 7deac87

Browse files
Refactor deployment output extraction in scripts for improved fallback handling
1 parent a88f892 commit 7deac87

File tree

3 files changed

+80
-46
lines changed

3 files changed

+80
-46
lines changed

docs/AVMPostDeploymentGuide.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,25 +83,25 @@ The post-deployment process is automated through a single PowerShell or Bash scr
8383
- **For PowerShell (Windows/Linux/macOS):**
8484

8585
```powershell
86-
.\infra\scripts\Team-Config-And-Data.ps1 -ResourceGroup "<your-resource-group-name>"
86+
infra\scripts\Selecting-Team-Config-And-Data.ps1 -ResourceGroup "<your-resource-group-name>"
8787
```
8888
8989
- **For Bash (Linux/macOS/WSL):**
9090
```bash
91-
bash infra/scripts/team_config_and_data.sh "<your-resource-group-name>"
91+
bash infra/scripts/selecting_team_config_and_data.sh --resource-group "<your-resource-group-name>"
9292
```
9393
9494
**If you deployed using `azd up` command:**
9595
9696
- **For PowerShell (Windows/Linux/macOS):**
9797
9898
```powershell
99-
.\infra\scripts\Team-Config-And-Data.ps1
99+
infra\scripts\Selecting-Team-Config-And-Data.ps1
100100
```
101101
102102
- **For Bash (Linux/macOS/WSL):**
103103
```bash
104-
bash infra/scripts/team_config_and_data.sh
104+
bash infra/scripts/selecting_team_config_and_data.sh
105105
```
106106
107107
> **Note**: Replace `<your-resource-group-name>` with the actual name of the resource group containing your deployed Azure resources.

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

Lines changed: 43 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,28 @@ function Get-ValuesFromAzdEnv {
7676
return $true
7777
}
7878

79+
function Get-DeploymentValue {
80+
param(
81+
[object]$DeploymentOutputs,
82+
[string]$PrimaryKey,
83+
[string]$FallbackKey
84+
)
85+
86+
$value = $null
87+
88+
# Try primary key first
89+
if ($DeploymentOutputs.PSObject.Properties[$PrimaryKey]) {
90+
$value = $DeploymentOutputs.$PrimaryKey.value
91+
}
92+
93+
# If primary key failed, try fallback key
94+
if (-not $value -and $DeploymentOutputs.PSObject.Properties[$FallbackKey]) {
95+
$value = $DeploymentOutputs.$FallbackKey.value
96+
}
97+
98+
return $value
99+
}
100+
79101
function Get-ValuesFromAzDeployment {
80102
Write-Host "Getting values from Azure deployment outputs..."
81103

@@ -95,30 +117,29 @@ function Get-ValuesFromAzDeployment {
95117
return $false
96118
}
97119

98-
# Extract specific outputs
99-
$script:storageAccount = $deploymentOutputs.azurE_STORAGE_ACCOUNT_NAME.value
100-
# $script:blobContainer = $deploymentOutputs.azurE_STORAGE_CONTAINER_NAME.value
101-
$script:blobContainerForRetailCustomer = $deploymentOutputs.azurE_STORAGE_CONTAINER_NAME_RETAIL_CUSTOMER.value
102-
$script:blobContainerForRetailOrder = $deploymentOutputs.azurE_STORAGE_CONTAINER_NAME_RETAIL_ORDER.value
103-
$script:blobContainerForRFPSummary = $deploymentOutputs.azurE_STORAGE_CONTAINER_NAME_RFP_SUMMARY.value
104-
$script:blobContainerForRFPRisk = $deploymentOutputs.azurE_STORAGE_CONTAINER_NAME_RFP_RISK.value
105-
$script:blobContainerForRFPCompliance = $deploymentOutputs.azurE_STORAGE_CONTAINER_NAME_RFP_COMPLIANCE.value
106-
$script:blobContainerForContractSummary = $deploymentOutputs.azurE_STORAGE_CONTAINER_NAME_CONTRACT_SUMMARY.value
107-
$script:blobContainerForContractRisk = $deploymentOutputs.azurE_STORAGE_CONTAINER_NAME_CONTRACT_RISK.value
108-
$script:blobContainerForContractCompliance = $deploymentOutputs.azurE_STORAGE_CONTAINER_NAME_CONTRACT_COMPLIANCE.value
109-
$script:aiSearchIndexForRetailCustomer = $deploymentOutputs.azurE_AI_SEARCH_INDEX_NAME_RETAIL_CUSTOMER.value
110-
$script:aiSearchIndexForRetailOrder = $deploymentOutputs.azurE_AI_SEARCH_INDEX_NAME_RETAIL_ORDER.value
111-
$script:aiSearchIndexForRFPSummary = $deploymentOutputs.azurE_AI_SEARCH_INDEX_NAME_RFP_SUMMARY.value
112-
$script:aiSearchIndexForRFPRisk = $deploymentOutputs.azurE_AI_SEARCH_INDEX_NAME_RFP_RISK.value
113-
$script:aiSearchIndexForRFPCompliance = $deploymentOutputs.azurE_AI_SEARCH_INDEX_NAME_RFP_COMPLIANCE.value
114-
$script:aiSearchIndexForContractSummary = $deploymentOutputs.azurE_AI_SEARCH_INDEX_NAME_CONTRACT_SUMMARY.value
115-
$script:aiSearchIndexForContractRisk = $deploymentOutputs.azurE_AI_SEARCH_INDEX_NAME_CONTRACT_RISK.value
116-
$script:aiSearchIndexForContractCompliance = $deploymentOutputs.azurE_AI_SEARCH_INDEX_NAME_CONTRACT_COMPLIANCE.value
117-
$script:aiSearch = $deploymentOutputs.azurE_AI_SEARCH_NAME.value
118-
$script:backendUrl = $deploymentOutputs.backenD_URL.value
120+
# Extract specific outputs with fallback logic
121+
$script:storageAccount = Get-DeploymentValue -DeploymentOutputs $deploymentOutputs -PrimaryKey "azurE_STORAGE_ACCOUNT_NAME" -FallbackKey "azureStorageAccountName"
122+
$script:blobContainerForRetailCustomer = Get-DeploymentValue -DeploymentOutputs $deploymentOutputs -PrimaryKey "azurE_STORAGE_CONTAINER_NAME_RETAIL_CUSTOMER" -FallbackKey "azureStorageContainerNameRetailCustomer"
123+
$script:blobContainerForRetailOrder = Get-DeploymentValue -DeploymentOutputs $deploymentOutputs -PrimaryKey "azurE_STORAGE_CONTAINER_NAME_RETAIL_ORDER" -FallbackKey "azureStorageContainerNameRetailOrder"
124+
$script:blobContainerForRFPSummary = Get-DeploymentValue -DeploymentOutputs $deploymentOutputs -PrimaryKey "azurE_STORAGE_CONTAINER_NAME_RFP_SUMMARY" -FallbackKey "azureStorageContainerNameRfpSummary"
125+
$script:blobContainerForRFPRisk = Get-DeploymentValue -DeploymentOutputs $deploymentOutputs -PrimaryKey "azurE_STORAGE_CONTAINER_NAME_RFP_RISK" -FallbackKey "azureStorageContainerNameRfpRisk"
126+
$script:blobContainerForRFPCompliance = Get-DeploymentValue -DeploymentOutputs $deploymentOutputs -PrimaryKey "azurE_STORAGE_CONTAINER_NAME_RFP_COMPLIANCE" -FallbackKey "azureStorageContainerNameRfpCompliance"
127+
$script:blobContainerForContractSummary = Get-DeploymentValue -DeploymentOutputs $deploymentOutputs -PrimaryKey "azurE_STORAGE_CONTAINER_NAME_CONTRACT_SUMMARY" -FallbackKey "azureStorageContainerNameContractSummary"
128+
$script:blobContainerForContractRisk = Get-DeploymentValue -DeploymentOutputs $deploymentOutputs -PrimaryKey "azurE_STORAGE_CONTAINER_NAME_CONTRACT_RISK" -FallbackKey "azureStorageContainerNameContractRisk"
129+
$script:blobContainerForContractCompliance = Get-DeploymentValue -DeploymentOutputs $deploymentOutputs -PrimaryKey "azurE_STORAGE_CONTAINER_NAME_CONTRACT_COMPLIANCE" -FallbackKey "azureStorageContainerNameContractCompliance"
130+
$script:aiSearchIndexForRetailCustomer = Get-DeploymentValue -DeploymentOutputs $deploymentOutputs -PrimaryKey "azurE_AI_SEARCH_INDEX_NAME_RETAIL_CUSTOMER" -FallbackKey "azureAiSearchIndexNameRetailCustomer"
131+
$script:aiSearchIndexForRetailOrder = Get-DeploymentValue -DeploymentOutputs $deploymentOutputs -PrimaryKey "azurE_AI_SEARCH_INDEX_NAME_RETAIL_ORDER" -FallbackKey "azureAiSearchIndexNameRetailOrder"
132+
$script:aiSearchIndexForRFPSummary = Get-DeploymentValue -DeploymentOutputs $deploymentOutputs -PrimaryKey "azurE_AI_SEARCH_INDEX_NAME_RFP_SUMMARY" -FallbackKey "azureAiSearchIndexNameRfpSummary"
133+
$script:aiSearchIndexForRFPRisk = Get-DeploymentValue -DeploymentOutputs $deploymentOutputs -PrimaryKey "azurE_AI_SEARCH_INDEX_NAME_RFP_RISK" -FallbackKey "azureAiSearchIndexNameRfpRisk"
134+
$script:aiSearchIndexForRFPCompliance = Get-DeploymentValue -DeploymentOutputs $deploymentOutputs -PrimaryKey "azurE_AI_SEARCH_INDEX_NAME_RFP_COMPLIANCE" -FallbackKey "azureAiSearchIndexNameRfpCompliance"
135+
$script:aiSearchIndexForContractSummary = Get-DeploymentValue -DeploymentOutputs $deploymentOutputs -PrimaryKey "azurE_AI_SEARCH_INDEX_NAME_CONTRACT_SUMMARY" -FallbackKey "azureAiSearchIndexNameContractSummary"
136+
$script:aiSearchIndexForContractRisk = Get-DeploymentValue -DeploymentOutputs $deploymentOutputs -PrimaryKey "azurE_AI_SEARCH_INDEX_NAME_CONTRACT_RISK" -FallbackKey "azureAiSearchIndexNameContractRisk"
137+
$script:aiSearchIndexForContractCompliance = Get-DeploymentValue -DeploymentOutputs $deploymentOutputs -PrimaryKey "azurE_AI_SEARCH_INDEX_NAME_CONTRACT_COMPLIANCE" -FallbackKey "azureAiSearchIndexNameContractCompliance"
138+
$script:aiSearch = Get-DeploymentValue -DeploymentOutputs $deploymentOutputs -PrimaryKey "azurE_AI_SEARCH_NAME" -FallbackKey "azureAiSearchName"
139+
$script:backendUrl = Get-DeploymentValue -DeploymentOutputs $deploymentOutputs -PrimaryKey "backenD_URL" -FallbackKey "backendUrl"
119140

120141
# Validate that we extracted all required values
121-
if (-not $script:storageAccount -or -not $script:blobContainer -or -not $script:aiSearch -or -not $script:aiSearchIndex -or -not $script:backendUrl) {
142+
if (-not $script:storageAccount -or -not $script:aiSearch -or -not $script:backendUrl) {
122143
Write-Host "Error: Could not extract all required values from deployment outputs."
123144
return $false
124145
}

infra/scripts/selecting_team_config_and_data.sh

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,19 @@ function get_values_from_azd_env() {
8686
return 0
8787
}
8888

89+
# Helper function to extract value with fallback
90+
extract_value() {
91+
local primary_key="$1"
92+
local fallback_key="$2"
93+
local result
94+
95+
result=$(echo "$deploymentOutputs" | grep -A 3 "\"$primary_key\"" | grep '"value"' | sed 's/.*"value": *"\([^"]*\)".*/\1/')
96+
if [ -z "$result" ]; then
97+
result=$(echo "$deploymentOutputs" | grep -A 3 "\"$fallback_key\"" | grep '"value"' | sed 's/.*"value": *"\([^"]*\)".*/\1/')
98+
fi
99+
echo "$result"
100+
}
101+
89102
function get_values_from_az_deployment() {
90103
echo "Getting values from Azure deployment outputs..."
91104

@@ -105,26 +118,26 @@ function get_values_from_az_deployment() {
105118
return 1
106119
fi
107120

108-
# Extract specific outputs using jq
109-
storageAccount=$(echo "$deploymentOutputs" | jq -r '.azurE_STORAGE_ACCOUNT_NAME.value')
110-
blobContainerForRetailCustomer=$(echo "$deploymentOutputs" | jq -r '.azurE_STORAGE_CONTAINER_NAME_RETAIL_CUSTOMER.value')
111-
blobContainerForRetailOrder=$(echo "$deploymentOutputs" | jq -r '.azurE_STORAGE_CONTAINER_NAME_RETAIL_ORDER.value')
112-
blobContainerForRFPSummary=$(echo "$deploymentOutputs" | jq -r '.azurE_STORAGE_CONTAINER_NAME_RFP_SUMMARY.value')
113-
blobContainerForRFPRisk=$(echo "$deploymentOutputs" | jq -r '.azurE_STORAGE_CONTAINER_NAME_RFP_RISK.value')
114-
blobContainerForRFPCompliance=$(echo "$deploymentOutputs" | jq -r '.azurE_STORAGE_CONTAINER_NAME_RFP_COMPLIANCE.value')
115-
blobContainerForContractSummary=$(echo "$deploymentOutputs" | jq -r '.azurE_STORAGE_CONTAINER_NAME_CONTRACT_SUMMARY.value')
116-
blobContainerForContractRisk=$(echo "$deploymentOutputs" | jq -r '.azurE_STORAGE_CONTAINER_NAME_CONTRACT_RISK.value')
117-
blobContainerForContractCompliance=$(echo "$deploymentOutputs" | jq -r '.azurE_STORAGE_CONTAINER_NAME_CONTRACT_COMPLIANCE.value')
118-
aiSearchIndexForRetailCustomer=$(echo "$deploymentOutputs" | jq -r '.azurE_AI_SEARCH_INDEX_NAME_RETAIL_CUSTOMER.value')
119-
aiSearchIndexForRetailOrder=$(echo "$deploymentOutputs" | jq -r '.azurE_AI_SEARCH_INDEX_NAME_RETAIL_ORDER.value')
120-
aiSearchIndexForRFPSummary=$(echo "$deploymentOutputs" | jq -r '.azurE_AI_SEARCH_INDEX_NAME_RFP_SUMMARY.value')
121-
aiSearchIndexForRFPRisk=$(echo "$deploymentOutputs" | jq -r '.azurE_AI_SEARCH_INDEX_NAME_RFP_RISK.value')
122-
aiSearchIndexForRFPCompliance=$(echo "$deploymentOutputs" | jq -r '.azurE_AI_SEARCH_INDEX_NAME_RFP_COMPLIANCE.value')
123-
aiSearchIndexForContractSummary=$(echo "$deploymentOutputs" | jq -r '.azurE_AI_SEARCH_INDEX_NAME_CONTRACT_SUMMARY.value')
124-
aiSearchIndexForContractRisk=$(echo "$deploymentOutputs" | jq -r '.azurE_AI_SEARCH_INDEX_NAME_CONTRACT_RISK.value')
125-
aiSearchIndexForContractCompliance=$(echo "$deploymentOutputs" | jq -r '.azurE_AI_SEARCH_INDEX_NAME_CONTRACT_COMPLIANCE.value')
126-
aiSearch=$(echo "$deploymentOutputs" | jq -r '.azurE_AI_SEARCH_NAME.value')
127-
backendUrl=$(echo "$deploymentOutputs" | jq -r '.backenD_URL.value')
121+
# Extract all values using the helper function
122+
storageAccount=$(extract_value "azurE_STORAGE_ACCOUNT_NAME" "azureStorageAccountName")
123+
blobContainerForRetailCustomer=$(extract_value "azurE_STORAGE_CONTAINER_NAME_RETAIL_CUSTOMER" "azureStorageContainerNameRetailCustomer")
124+
blobContainerForRetailOrder=$(extract_value "azurE_STORAGE_CONTAINER_NAME_RETAIL_ORDER" "azureStorageContainerNameRetailOrder")
125+
blobContainerForRFPSummary=$(extract_value "azurE_STORAGE_CONTAINER_NAME_RFP_SUMMARY" "azureStorageContainerNameRfpSummary")
126+
blobContainerForRFPRisk=$(extract_value "azurE_STORAGE_CONTAINER_NAME_RFP_RISK" "azureStorageContainerNameRfpRisk")
127+
blobContainerForRFPCompliance=$(extract_value "azurE_STORAGE_CONTAINER_NAME_RFP_COMPLIANCE" "azureStorageContainerNameRfpCompliance")
128+
blobContainerForContractSummary=$(extract_value "azurE_STORAGE_CONTAINER_NAME_CONTRACT_SUMMARY" "azureStorageContainerNameContractSummary")
129+
blobContainerForContractRisk=$(extract_value "azurE_STORAGE_CONTAINER_NAME_CONTRACT_RISK" "azureStorageContainerNameContractRisk")
130+
blobContainerForContractCompliance=$(extract_value "azurE_STORAGE_CONTAINER_NAME_CONTRACT_COMPLIANCE" "azureStorageContainerNameContractCompliance")
131+
aiSearchIndexForRetailCustomer=$(extract_value "azurE_AI_SEARCH_INDEX_NAME_RETAIL_CUSTOMER" "azureAiSearchIndexNameRetailCustomer")
132+
aiSearchIndexForRetailOrder=$(extract_value "azurE_AI_SEARCH_INDEX_NAME_RETAIL_ORDER" "azureAiSearchIndexNameRetailOrder")
133+
aiSearchIndexForRFPSummary=$(extract_value "azurE_AI_SEARCH_INDEX_NAME_RFP_SUMMARY" "azureAiSearchIndexNameRfpSummary")
134+
aiSearchIndexForRFPRisk=$(extract_value "azurE_AI_SEARCH_INDEX_NAME_RFP_RISK" "azureAiSearchIndexNameRfpRisk")
135+
aiSearchIndexForRFPCompliance=$(extract_value "azurE_AI_SEARCH_INDEX_NAME_RFP_COMPLIANCE" "azureAiSearchIndexNameRfpCompliance")
136+
aiSearchIndexForContractSummary=$(extract_value "azurE_AI_SEARCH_INDEX_NAME_CONTRACT_SUMMARY" "azureAiSearchIndexNameContractSummary")
137+
aiSearchIndexForContractRisk=$(extract_value "azurE_AI_SEARCH_INDEX_NAME_CONTRACT_RISK" "azureAiSearchIndexNameContractRisk")
138+
aiSearchIndexForContractCompliance=$(extract_value "azurE_AI_SEARCH_INDEX_NAME_CONTRACT_COMPLIANCE" "azureAiSearchIndexNameContractCompliance")
139+
aiSearch=$(extract_value "azurE_AI_SEARCH_NAME" "azureAiSearchName")
140+
backendUrl=$(extract_value "backenD_URL" "backendUrl")
128141

129142
# Validate that we extracted all required values
130143
if [[ -z "$storageAccount" || -z "$aiSearch" || -z "$backendUrl" ]]; then

0 commit comments

Comments
 (0)