Skip to content

Commit dd933a2

Browse files
Merge pull request #195 from microsoft/psl-dev-US-13877
refactor: validated the isnull or empty variable
2 parents aa14d56 + d365b3f commit dd933a2

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

Deployment/resourcedeployment.ps1

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,15 +176,18 @@ function DeployAzureResources([string]$location, [string]$modelLocation) {
176176
if ($LASTEXITCODE -ne 0) {
177177
Write-Host "There might be something wrong with your deployment." -ForegroundColor Red
178178
Write-Host $whatIfResult -ForegroundColor Red
179+
failureBanner
179180
exit 1
180181
}
181182
# Proceed with the actual deployment
182183
Write-Host "Proceeding with Deployment..." -ForegroundColor Yellow
183184
$deploymentResult = az deployment sub create --template-file .\main.bicep --location $location --name $deploymentName --parameters modeldatacenter=$modelLocation
184-
185+
# Check if deploymentResult is valid
186+
ValidateVariableIsNullOrEmpty -variableValue $deploymentResult -variableName "Deployment Result"
185187
if ($LASTEXITCODE -ne 0) {
186188
Write-Host "Deployment failed. Stopping execution." -ForegroundColor Red
187189
Write-Host $deploymentResult -ForegroundColor Red
190+
failureBanner
188191
exit 1
189192
}
190193

@@ -197,6 +200,7 @@ function DeployAzureResources([string]$location, [string]$modelLocation) {
197200
Write-Host $_.Exception.Message -ForegroundColor Red
198201
Write-Host $_.InvocationInfo.PositionMessage -ForegroundColor Red
199202
Write-Host $_.ScriptStackTrace -ForegroundColor Red
203+
failureBanner
200204
exit 1
201205
}
202206
}
@@ -410,6 +414,7 @@ function Check-Docker {
410414
# Check if Docker is running before proceeding
411415
if (-not (Check-Docker)) {
412416
Write-Host "Docker is not running. Please start Docker and try again." -ForegroundColor Red
417+
failureBanner
413418
exit 1
414419
}
415420

@@ -439,6 +444,9 @@ try {
439444
# Step 2 : Get Secrets from Azure resources
440445
Show-Banner -Title "Step 2 : Get Secrets from Azure resources"
441446
###############################################################
447+
# Validate if the Storage Account Name is empty or null
448+
ValidateVariableIsNullOrEmpty -variableValue $deploymentResult.StorageAccountName -variableName "Storage Account Name"
449+
442450
# Get the storage account key
443451
$storageAccountKey = az storage account keys list --account-name $deploymentResult.StorageAccountName --resource-group $deploymentResult.ResourceGroupName --query "[0].value" -o tsv
444452

@@ -596,6 +604,7 @@ try {
596604

597605
if ($retryCount -eq $maxRetries) {
598606
Write-Host "Max retries reached. Failed to update the AKS cluster." -ForegroundColor Red
607+
failureBanner
599608
exit 1
600609
}
601610

@@ -615,6 +624,7 @@ try {
615624
Write-Host "Error details:" -ForegroundColor Red
616625
Write-Host $_.Exception.Message -ForegroundColor Red
617626
Write-Host $_.Exception.StackTrace -ForegroundColor Red
627+
failureBanner
618628
exit 1
619629
}
620630

@@ -630,6 +640,7 @@ try {
630640
Write-Host "Error details:" -ForegroundColor Red
631641
Write-Host $_.Exception.Message -ForegroundColor Red
632642
Write-Host $_.Exception.StackTrace -ForegroundColor Red
643+
failureBanner
633644
exit 1
634645
}
635646

@@ -650,6 +661,7 @@ try {
650661
Write-Host "Error details:" -ForegroundColor Red
651662
Write-Host $_.Exception.Message -ForegroundColor Red
652663
Write-Host $_.Exception.StackTrace -ForegroundColor Red
664+
failureBanner
653665
exit 1
654666
}
655667

@@ -716,6 +728,9 @@ try {
716728
# Validate if System Assigned Identity is null or empty
717729
ValidateVariableIsNullOrEmpty -variableValue $systemAssignedIdentity -variableName "System-assigned managed identity"
718730

731+
# Validate if ResourceGroupId is null or empty
732+
ValidateVariableIsNullOrEmpty -variableValue $deploymentResult.ResourceGroupId -variableName "ResourceGroupId"
733+
719734
# Assign the role for aks system assigned managed identity to App Configuration Data Reader role with the scope of Resourcegroup
720735
az role assignment create --assignee $systemAssignedIdentity --role "App Configuration Data Reader" --scope $deploymentResult.ResourceGroupId
721736

@@ -743,6 +758,7 @@ try {
743758
Write-Host "Error details:" -ForegroundColor Red
744759
Write-Host $_.Exception.Message -ForegroundColor Red
745760
Write-Host $_.Exception.StackTrace -ForegroundColor Red
761+
failureBanner
746762
exit 1
747763
}
748764

@@ -772,12 +788,21 @@ try {
772788

773789

774790
# 5.3 Update deploy.deployment.yaml.template file and save as deploy.deployment.yaml
791+
# Validate AzContainerRegistryName IsNull Or Empty.
792+
ValidateVariableIsNullOrEmpty -variableValue $deploymentResult.AzContainerRegistryName -variableName "Azure Container Registry Name"
793+
775794
## Define Image Tags
776795
$acrNamespace = "kmgs"
777796
$acrAIServiceTag = "$($deploymentResult.AzContainerRegistryName).azurecr.io/$acrNamespace/aiservice"
778797
$acrKernelMemoryTag = "$($deploymentResult.AzContainerRegistryName).azurecr.io/$acrNamespace/kernelmemory"
779798
$acrFrontAppTag = "$($deploymentResult.AzContainerRegistryName).azurecr.io/$acrNamespace/frontapp"
780-
799+
800+
# Validate AI Service Tag IsNull Or Empty.
801+
ValidateVariableIsNullOrEmpty -variableValue $acrAIServiceTag -variableName "AI Service Tag"
802+
# Validate Kernel Memory Tag IsNull Or Empty.
803+
ValidateVariableIsNullOrEmpty -variableValue $acrKernelMemoryTag -variableName "Kernel Memory Tag"
804+
# Validate Front App Tag IsNull Or Empty.
805+
ValidateVariableIsNullOrEmpty -variableValue $acrFrontAppTag -variableName "Front App Tag"
781806

782807
$deploymentTemplatePlaceholders = @{
783808
'{{ aiservice-imagepath }}' = $acrAIServiceTag
@@ -821,8 +846,9 @@ try {
821846

822847

823848
#======================================================================================================================================================================
849+
# Validate AzAppConfigEndpoint IsNull Or Empty.
850+
ValidateVariableIsNullOrEmpty -variableValue $deploymentResult.AzAppConfigEndpoint -variableName "Azure App Configuration Endpoint"
824851
# App Deployment after finishing the AKS infrastructure setup
825-
826852
$appConfigServicePlaceholders = @{
827853
'{{ appconfig-url }}' = $deploymentResult.AzAppConfigEndpoint
828854
}

0 commit comments

Comments
 (0)