Skip to content

Commit 7e8e1f5

Browse files
Merge pull request #494 from microsoft/dev
fix: Merging dev to main
2 parents 4620f5d + b8685cb commit 7e8e1f5

File tree

1 file changed

+81
-37
lines changed

1 file changed

+81
-37
lines changed

Deployment/resourcedeployment.ps1

Lines changed: 81 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,23 @@ function PromptForParameters {
102102
$params = PromptForParameters -email $email
103103
$email = $params.email
104104

105+
$script:alreadyLoggedIn = $false
106+
105107
function LoginAzure([string]$tenantId, [string]$subscriptionID) {
106108
Write-Host "Log in to Azure.....`r`n" -ForegroundColor Yellow
109+
if ([string]::IsNullOrEmpty($tenantId) -or [string]::IsNullOrEmpty($subscriptionID)) {
110+
az login
111+
if ($LASTEXITCODE -ne 0) {
112+
Write-Host "Failed to log in to Azure. Please check your credentials." -ForegroundColor Red
113+
failureBanner
114+
exit 1
115+
}
116+
else{
117+
Write-Host "Logged in to Azure successfully." -ForegroundColor Green
118+
$script:alreadyLoggedIn = $true
119+
return
120+
}
121+
}
107122
if ($env:CI -eq "true"){
108123
az login --service-principal `
109124
--username $env:AZURE_CLIENT_ID `
@@ -353,59 +368,85 @@ class DeploymentResult {
353368
Write-Error "Deployment name not found in the resource group tags."
354369
exit 1
355370
}
356-
371+
357372
$deploymentOutputs=$(az deployment group show --resource-group "$resourceGroupName" --name "$deploymentName" --query "properties.outputs" -o json | ConvertFrom-Json)
358-
359-
$this.TenantId = $deploymentOutputs.azurE_TENANT_ID.value
373+
374+
# Helper function to get value from deployment outputs with fallback
375+
function Get-DeploymentOutputValue {
376+
param (
377+
[Parameter(Mandatory=$true)]
378+
$outputs,
379+
[Parameter(Mandatory=$true)]
380+
[string]$primaryKey,
381+
[Parameter(Mandatory=$true)]
382+
[string]$fallbackKey
383+
)
384+
385+
$value = $null
386+
387+
# Try primary key first (old convention)
388+
if ($outputs.PSObject.Properties.Name -contains $primaryKey) {
389+
$value = $outputs.$primaryKey.value
390+
}
391+
392+
# If not found or empty, try fallback key (new convention)
393+
if ([string]::IsNullOrEmpty($value) -and ($outputs.PSObject.Properties.Name -contains $fallbackKey)) {
394+
$value = $outputs.$fallbackKey.value
395+
}
396+
397+
return $value
398+
}
399+
400+
# Tenant ID
401+
$this.TenantId = Get-DeploymentOutputValue -outputs $deploymentOutputs -primaryKey "azurE_TENANT_ID" -fallbackKey "azureTenantId"
360402
if (!$this.TenantId) {
361403
$this.TenantId = $(az account show --query tenantId -o tsv)
362404
}
363-
364-
$this.SubscriptionId = $(az account show --query id -o tsv)
365-
405+
406+
$this.SubscriptionId = $(az account show --query id -o tsv)
407+
366408
# Resource Group
367-
$this.ResourceGroupName = $resourceGroupName
368-
$this.ResourceGroupId = $deploymentOutputs.azurE_RESOURCE_GROUP_ID.value
409+
$this.ResourceGroupName = $resourceGroupName
410+
$this.ResourceGroupId = Get-DeploymentOutputValue -outputs $deploymentOutputs -primaryKey "azurE_RESOURCE_GROUP_ID" -fallbackKey "azureResourceGroupId"
369411
if (!$this.ResourceGroupId) {
370-
Write-Error "Required value 'AZURE_RESOURCE_GROUP_ID' not found in the deployment outputs."
412+
Write-Error "Required value 'AZURE_RESOURCE_GROUP_ID' or 'azureResourceGroupId' not found in the deployment outputs."
371413
exit 1
372414
}
373-
415+
374416
# Storage Account
375-
$this.StorageAccountName = $deploymentOutputs.storagE_ACCOUNT_NAME.value
376-
417+
$this.StorageAccountName = Get-DeploymentOutputValue -outputs $deploymentOutputs -primaryKey "storagE_ACCOUNT_NAME" -fallbackKey "storageAccountName"
418+
377419
# Search Service
378-
$this.AzSearchServiceName = $deploymentOutputs.azurE_SEARCH_SERVICE_NAME.value
379-
$this.AzSearchServicEndpoint = "https://$($this.AzSearchServiceName).search.windows.net"
380-
420+
$this.AzSearchServiceName = Get-DeploymentOutputValue -outputs $deploymentOutputs -primaryKey "azurE_SEARCH_SERVICE_NAME" -fallbackKey "azureSearchServiceName"
421+
$this.AzSearchServicEndpoint = "https://$($this.AzSearchServiceName).search.windows.net"
422+
381423
# AKS
382-
$this.AksName = $deploymentOutputs.azurE_AKS_NAME.value
383-
$this.AksMid = $deploymentOutputs.azurE_AKS_MI_ID.value
384-
424+
$this.AksName = Get-DeploymentOutputValue -outputs $deploymentOutputs -primaryKey "azurE_AKS_NAME" -fallbackKey "azureAksName"
425+
$this.AksMid = Get-DeploymentOutputValue -outputs $deploymentOutputs -primaryKey "azurE_AKS_MI_ID" -fallbackKey "azureAksMiId"
426+
385427
# Container Registry
386-
$this.AzContainerRegistryName = $deploymentOutputs.azurE_CONTAINER_REGISTRY_NAME.value
387-
428+
$this.AzContainerRegistryName = Get-DeploymentOutputValue -outputs $deploymentOutputs -primaryKey "azurE_CONTAINER_REGISTRY_NAME" -fallbackKey "azureContainerRegistryName"
429+
388430
# Cognitive Service - Azure AI Document Intelligence Service
389-
$this.AzCognitiveServiceName = $deploymentOutputs.azurE_COGNITIVE_SERVICE_NAME.value
390-
$this.AzCognitiveServiceEndpoint = $deploymentOutputs.azurE_COGNITIVE_SERVICE_ENDPOINT.value
391-
431+
$this.AzCognitiveServiceName = Get-DeploymentOutputValue -outputs $deploymentOutputs -primaryKey "azurE_COGNITIVE_SERVICE_NAME" -fallbackKey "azureCognitiveServiceName"
432+
$this.AzCognitiveServiceEndpoint = Get-DeploymentOutputValue -outputs $deploymentOutputs -primaryKey "azurE_COGNITIVE_SERVICE_ENDPOINT" -fallbackKey "azureCognitiveServiceEndpoint"
433+
392434
# Open AI Service
393-
$this.AzOpenAiServiceName = $deploymentOutputs.azurE_OPENAI_SERVICE_NAME.value
394-
$this.AzOpenAiServiceEndpoint = $deploymentOutputs.azurE_OPENAI_SERVICE_ENDPOINT.value
395-
435+
$this.AzOpenAiServiceName = Get-DeploymentOutputValue -outputs $deploymentOutputs -primaryKey "azurE_OPENAI_SERVICE_NAME" -fallbackKey "azureOpenAiServiceName"
436+
$this.AzOpenAiServiceEndpoint = Get-DeploymentOutputValue -outputs $deploymentOutputs -primaryKey "azurE_OPENAI_SERVICE_ENDPOINT" -fallbackKey "azureOpenAiServiceEndpoint"
437+
396438
# Cosmos DB
397-
$this.AzCosmosDBName = $deploymentOutputs.azurE_COSMOSDB_NAME.value
398-
439+
$this.AzCosmosDBName = Get-DeploymentOutputValue -outputs $deploymentOutputs -primaryKey "azurE_COSMOSDB_NAME" -fallbackKey "azureCosmosDbName"
440+
399441
# Open AI Service Models
400-
$this.AzGPT4oModelName = $deploymentOutputs.aZ_GPT4O_MODEL_NAME.value
401-
$this.AzGPT4oModelId = $deploymentOutputs.aZ_GPT4O_MODEL_ID.value
402-
$this.AzGPTEmbeddingModelName = $deploymentOutputs.aZ_GPT_EMBEDDING_MODEL_NAME.value
403-
$this.AzGPTEmbeddingModelId = $deploymentOutputs.aZ_GPT_EMBEDDING_MODEL_ID.value
404-
442+
$this.AzGPT4oModelName = Get-DeploymentOutputValue -outputs $deploymentOutputs -primaryKey "aZ_GPT4O_MODEL_NAME" -fallbackKey "azGpt4oModelName"
443+
$this.AzGPT4oModelId = Get-DeploymentOutputValue -outputs $deploymentOutputs -primaryKey "aZ_GPT4O_MODEL_ID" -fallbackKey "azGpt4oModelId"
444+
$this.AzGPTEmbeddingModelName = Get-DeploymentOutputValue -outputs $deploymentOutputs -primaryKey "aZ_GPT_EMBEDDING_MODEL_NAME" -fallbackKey "azGptEmbeddingModelName"
445+
$this.AzGPTEmbeddingModelId = Get-DeploymentOutputValue -outputs $deploymentOutputs -primaryKey "aZ_GPT_EMBEDDING_MODEL_ID" -fallbackKey "azGptEmbeddingModelId"
446+
405447
# App Configuration
406-
$this.AzAppConfigEndpoint = $deploymentOutputs.azurE_APP_CONFIG_ENDPOINT.value
407-
$this.AzAppConfigName = $deploymentOutputs.azurE_APP_CONFIG_NAME.value
408-
448+
$this.AzAppConfigEndpoint = Get-DeploymentOutputValue -outputs $deploymentOutputs -primaryKey "azurE_APP_CONFIG_ENDPOINT" -fallbackKey "azureAppConfigEndpoint"
449+
$this.AzAppConfigName = Get-DeploymentOutputValue -outputs $deploymentOutputs -primaryKey "azurE_APP_CONFIG_NAME" -fallbackKey "azureAppConfigName"
409450
}
410451
}
411452

@@ -452,13 +493,16 @@ try {
452493

453494
# Map the deployment result to DeploymentResult object from .env file
454495
if ($ResourceGroupName) {
496+
LoginAzure "" ""
455497
$deploymentResult.MapResultAz($ResourceGroupName.Trim())
456498
}
457499
else {
458500
$deploymentResult.MapResultAzd()
459501
}
460502

461-
LoginAzure $deploymentResult.TenantId $deploymentResult.SubscriptionId
503+
if (-not $script:alreadyLoggedIn) {
504+
LoginAzure $deploymentResult.TenantId $deploymentResult.SubscriptionId
505+
}
462506

463507
# Display the deployment result
464508
DisplayResult($deploymentResult)

0 commit comments

Comments
 (0)