@@ -41,6 +41,35 @@ function successBanner(){
4141 Write-Host " |_| |___/ "
4242}
4343
44+ function failureBanner (){
45+ Write-Host " _____ _ _ "
46+ Write-Host " | __ \ | | | | "
47+ Write-Host " | | | | ___ _ __ | | ___ _ _ _ __ ___ ___ _ __ | |_ "
48+ Write-Host " | | | |/ _ \ '_ \| |/ _ \| | | | '_ ` _ \ / _ \ '_ \| __| "
49+ Write-Host " | |__| | __/ |_) | | (_) | |_| | | | | | | __/ | | | |_ "
50+ Write-Host " |_____/ \___| .__/|_|\___/ \__, |_| |_| |_|\___|_| |_|\__| "
51+ Write-Host " | | __/ | "
52+ Write-Host " ______ _|_| _ |___/ "
53+ Write-Host " | ____| (_) | | | "
54+ Write-Host " | |__ __ _ _| | ___ __| | "
55+ Write-Host " | __/ _` | | |/ _ \/ _` | "
56+ Write-Host " | | | (_| | | | __/ (_| | "
57+ Write-Host " |_| \__,_|_|_|\___|\__,_| "
58+ }
59+
60+ # Common function to check if a variable is null or empty
61+ function ValidateVariableIsNullOrEmpty {
62+ param (
63+ [string ]$variableValue ,
64+ [string ]$variableName
65+ )
66+
67+ if ([string ]::IsNullOrEmpty($variableValue )) {
68+ Write-Host " Error: $variableName is null or empty." - ForegroundColor Red
69+ failureBanner
70+ exit 1
71+ }
72+ }
4473# Function to prompt for parameters with kind messages
4574function PromptForParameters {
4675 param (
@@ -112,8 +141,19 @@ $modelLocation = $params.modelLocation
112141$email = $params.email
113142
114143function LoginAzure ([string ]$subscriptionID ) {
115- Write-Host " Log in to Azure.....`r`n " - ForegroundColor Yellow
116- az login
144+ Write-Host " Log in to Azure.....`r`n " - ForegroundColor Yellow
145+ if ($env: CI -eq " true" ){
146+
147+ az login -- service- principal `
148+ -- username $env: AZURE_CLIENT_ID `
149+ -- password $env: AZURE_CLIENT_SECRET `
150+ -- tenant $env: AZURE_TENANT_ID
151+ write-host " CI deployment mode"
152+ }
153+ else {
154+ az login
155+ write-host " manual deployment mode"
156+ }
117157 az account set -- subscription $subscriptionID
118158 Write-Host " Switched subscription to '$subscriptionID ' `r`n " - ForegroundColor Yellow
119159}
@@ -163,9 +203,12 @@ function DeployAzureResources([string]$location, [string]$modelLocation) {
163203
164204function DisplayResult ([pscustomobject ]$jsonString ) {
165205 $resourcegroupName = $jsonString.properties.outputs.gs_resourcegroup_name.value
206+ $solutionPrefix = $jsonString.properties.outputs.gs_solution_prefix.value
207+
166208 $storageAccountName = $jsonString.properties.outputs.gs_storageaccount_name.value
167209 $azsearchServiceName = $jsonString.properties.outputs.gs_azsearch_name.value
168210 $aksName = $jsonString.properties.outputs.gs_aks_name.value
211+
169212 $containerRegistryName = $jsonString.properties.outputs.gs_containerregistry_name.value
170213 $azcognitiveserviceName = $jsonString.properties.outputs.gs_azcognitiveservice_name.value
171214 $azopenaiServiceName = $jsonString.properties.outputs.gs_openaiservice_name.value
@@ -186,6 +229,9 @@ function DisplayResult([pscustomobject]$jsonString) {
186229 Write-Host " * Azure Storage Account " - ForegroundColor Yellow - NoNewline; Write-Host " $storageAccountName " - ForegroundColor Green
187230 Write-Host " * Azure Cosmos DB " - ForegroundColor Yellow - NoNewline; Write-Host " $azcosmosDBName " - ForegroundColor Green
188231 Write-Host " * Azure App Configuration Endpoint " - ForegroundColor Yellow - NoNewline; Write-Host " $azappConfigEndpoint " - ForegroundColor Green
232+ Write-Output " rg_name=$resourcegroupName " >> $Env: GITHUB_ENV
233+
234+ Write-Output " SOLUTION_PREFIX=$solutionPrefix " >> $Env: GITHUB_ENV
189235}
190236
191237# Function to replace placeholders in a template with actual values
@@ -395,10 +441,33 @@ try {
395441 # ##############################################################
396442 # Get the storage account key
397443 $storageAccountKey = az storage account keys list -- account- name $deploymentResult.StorageAccountName -- resource- group $deploymentResult.ResourceGroupName -- query " [0].value" - o tsv
444+
445+ # Validate if the storage account key is empty or null
446+ ValidateVariableIsNullOrEmpty - variableValue $storageAccountKey - variableName " Storage account key"
447+
398448 # # Construct the connection string manually
399449 $storageAccountConnectionString = " DefaultEndpointsProtocol=https;AccountName=$ ( $deploymentResult.StorageAccountName ) ;AccountKey=$storageAccountKey ;EndpointSuffix=core.windows.net"
450+ # Validate if the Storage Account Connection String is empty or null
451+ ValidateVariableIsNullOrEmpty - variableValue $storageAccountConnectionString - variableName " Storage Account Connection String"
452+
400453 # # Assign the connection string to the deployment result object
401- $deploymentResult.StorageAccountConnectionString = $storageAccountConnectionString
454+ $deploymentResult.StorageAccountConnectionString = $storageAccountConnectionString
455+
456+ # Check if ResourceGroupName is valid
457+ ValidateVariableIsNullOrEmpty - variableValue $deploymentResult.ResourceGroupName - variableName " Resource group name"
458+
459+ # Check if AzCosmosDBName is valid
460+ ValidateVariableIsNullOrEmpty - variableValue $deploymentResult.AzCosmosDBName - variableName " Az Cosmos DB name"
461+
462+ # Check if AzCognitiveServiceName is valid
463+ ValidateVariableIsNullOrEmpty - variableValue $deploymentResult.AzCognitiveServiceName - variableName " Az Cognitive Service name"
464+
465+ # Check if AzSearchServiceName is valid
466+ ValidateVariableIsNullOrEmpty - variableValue $deploymentResult.AzSearchServiceName - variableName " Az Search Service name"
467+
468+ # Check if AzOpenAiServiceName is valid
469+ ValidateVariableIsNullOrEmpty - variableValue $deploymentResult.AzOpenAiServiceName - variableName " Az OpenAI Service name"
470+
402471 # Get MongoDB connection string
403472 $deploymentResult.AzCosmosDBConnectionString = az cosmosdb keys list -- name $deploymentResult.AzCosmosDBName -- resource- group $deploymentResult.ResourceGroupName -- type connection- strings -- query " connectionStrings[0].connectionString" - o tsv
404473 # Get Azure Cognitive Service API Key
@@ -538,6 +607,8 @@ try {
538607 Write-Host " Getting the Kubernetes resource group..." - ForegroundColor Cyan
539608 $aksResourceGroupName = $ (az aks show -- resource- group $deploymentResult.ResourceGroupName -- name $deploymentResult.AksName -- query nodeResourceGroup -- output tsv)
540609 Write-Host " Kubernetes resource group: $aksResourceGroupName " - ForegroundColor Green
610+ Write-Output " krg_name=$aksResourceGroupName " >> $Env: GITHUB_ENV
611+
541612 }
542613 catch {
543614 Write-Host " Failed to get the Kubernetes resource group." - ForegroundColor Red
@@ -601,26 +672,49 @@ try {
601672 # 6-1. Get Az Network resource Name with the public IP address
602673 Write-Host " Assign DNS Name to the public IP address" - ForegroundColor Green
603674 $publicIpName = $ (az network public- ip list -- query " [?ipAddress=='$externalIP '].name" -- output tsv)
604-
605675 # 6-2. Generate Unique backend API fqdn Name - esgdocanalysis-3 digit random number with padding 0
606676 $dnsName = " kmgs$ ( $ (Get-Random - Minimum 0 - Maximum 9999 ).ToString(" D4" )) "
677+
678+ # Validate if the AKS Resource Group Name, Public IP name and DNS Name are provided
679+ ValidateVariableIsNullOrEmpty - variableValue $aksResourceGroupName - variableName " AKS Resource Group name"
680+
681+ ValidateVariableIsNullOrEmpty - variableValue $publicIpName - variableName " Public IP name"
607682
683+ ValidateVariableIsNullOrEmpty - variableValue $dnsName - variableName " DNS Name"
684+
608685 # 6-3. Assign DNS Name to the public IP address
609686 az network public- ip update -- resource- group $aksResourceGroupName -- name $publicIpName -- dns- name $dnsName
610- # 6-4. Get FQDN for the public IP address
611- $fqdn = az network public- ip show -- resource- group $aksResourceGroupName -- name $publicIpName -- query " dnsSettings.fqdn" -- output tsv
612- Write-Host " FQDN for the public IP address is: $fqdn " - ForegroundColor Green
613687
688+ # 6-4. Get FQDN for the public IP address
689+ $fqdn = az network public- ip show -- resource- group $aksResourceGroupName -- name $publicIpName -- query " dnsSettings.fqdn" -- output tsv
690+
691+ # Validate if the FQDN is null or empty
692+ ValidateVariableIsNullOrEmpty - variableValue $fqdn - variableName " FQDN"
693+
614694 # 7. Assign the role for aks system assigned managed identity to App Configuration Data Reader role with the scope of Resourcegroup
615695 Write-Host " Assign the role for aks system assigned managed identity to App Configuration Data Reader role" - ForegroundColor Green
696+ # Ensure that the required fields are not null or empty
697+ ValidateVariableIsNullOrEmpty - variableValue $deploymentResult.ResourceGroupName - variableName " Resource group name"
698+
699+ ValidateVariableIsNullOrEmpty - variableValue $deploymentResult.AksName - variableName " AKS cluster name"
700+
616701 # Get vmss resource group name
617702 $vmssResourceGroupName = $ (az aks show -- resource- group $deploymentResult.ResourceGroupName -- name $deploymentResult.AksName -- query nodeResourceGroup -- output tsv)
703+
704+ # Validate if vmss Resource Group Name is null or empty
705+ ValidateVariableIsNullOrEmpty - variableValue $vmssResourceGroupName - variableName " VMSS resource group"
706+
618707 # Get vmss name
619708 $vmssName = $ (az vmss list -- resource- group $vmssResourceGroupName -- query " [0].name" -- output tsv)
709+
710+ # Validate if vmss Name is null or empty
711+ ValidateVariableIsNullOrEmpty - variableValue $vmssName - variableName " VMSS name"
712+
620713 # Create System Assigned Managed Identity
621714 $systemAssignedIdentity = $ (az vmss identity assign -- resource- group $vmssResourceGroupName -- name $vmssName -- query systemAssignedIdentity -- output tsv)
622715
623-
716+ # Validate if System Assigned Identity is null or empty
717+ ValidateVariableIsNullOrEmpty - variableValue $systemAssignedIdentity - variableName " System-assigned managed identity"
624718
625719 # Assign the role for aks system assigned managed identity to App Configuration Data Reader role with the scope of Resourcegroup
626720 az role assignment create -- assignee $systemAssignedIdentity -- role " App Configuration Data Reader" -- scope $deploymentResult.ResourceGroupId
@@ -641,6 +735,7 @@ try {
641735 Write-Host " Upgrading node pool: $nodePool " - ForegroundColor Cyan
642736 Write-Host " Node pool $nodePool upgrade initiated." - ForegroundColor Green
643737 az aks nodepool upgrade -- resource- group $deploymentResult.ResourceGroupName -- cluster- name $deploymentResult.AksName -- name $nodePool
738+
644739 }
645740 }
646741 catch {
0 commit comments