@@ -74,6 +74,8 @@ function ValidateVariableIsNullOrEmpty {
7474function PromptForParameters {
7575 param (
7676 [string ]$subscriptionID ,
77+ [string ]$environmentName ,
78+ [string ]$resourceGroupName ,
7779 [string ]$location ,
7880 [string ]$modelLocation ,
7981 [string ]$email
@@ -105,6 +107,16 @@ function PromptForParameters {
105107 $subscriptionID = Read-Host - Prompt ' > '
106108 }
107109
110+ if (-not $environmentName ) {
111+ Write-Host " Please enter Environment name" - ForegroundColor Cyan
112+ $environmentName = Read-Host - Prompt ' > '
113+ }
114+
115+ if (-not $resourceGroupName ) {
116+ Write-Host " Please enter your Azure Resource Group Name to deploy your resources (leave blank to auto-generate one)" - ForegroundColor Cyan
117+ $resourceGroupName = Read-Host - Prompt ' > '
118+ }
119+
108120 if (-not $location ) {
109121 Write-Host " Please enter the Azure Data Center Region to deploy your resources" - ForegroundColor Cyan
110122 Write-Host " Available regions are:" - ForegroundColor Cyan
@@ -125,37 +137,41 @@ function PromptForParameters {
125137 }
126138
127139 return @ {
128- subscriptionID = $subscriptionID
129- location = $location
130- modelLocation = $modelLocation
131- email = $email
140+ subscriptionID = $subscriptionID
141+ environmentName = $environmentName
142+ resourceGroupName = $resourceGroupName
143+ location = $location
144+ modelLocation = $modelLocation
145+ email = $email
132146 }
133147}
134148
135149# Prompt for parameters with kind messages
136- $params = PromptForParameters - subscriptionID $subscriptionID - location $location - modelLocation $modelLocation - email $email
150+ $params = PromptForParameters - subscriptionID $subscriptionID - environmentName $environmentName - resourceGroupName $resourceGroupName - location $location - modelLocation $modelLocation - email $email
137151# Assign the parameters to variables
138152$subscriptionID = $params.subscriptionID
153+ $environmentName = $params.environmentName
154+ $resourceGroupName = $params.resourceGroupName
139155$location = $params.location
140156$modelLocation = $params.modelLocation
141157$email = $params.email
142158
143159function LoginAzure ([string ]$subscriptionID ) {
144- Write-Host " Log in to Azure.....`r`n " - ForegroundColor Yellow
160+ Write-Host " Log in to Azure.....`r`n " - ForegroundColor Yellow
145161 if ($env: CI -eq " true" ){
146162
147163 az login -- service- principal `
148- -- username $env: AZURE_CLIENT_ID `
149- -- password $env: AZURE_CLIENT_SECRET `
150- -- tenant $env: AZURE_TENANT_ID
164+ -- username $env: AZURE_CLIENT_ID `
165+ -- password $env: AZURE_CLIENT_SECRET `
166+ -- tenant $env: AZURE_TENANT_ID
151167 write-host " CI deployment mode"
152- }
168+ }
153169 else {
154- az login
170+ az login
155171 write-host " manual deployment mode"
156- }
157- az account set -- subscription $subscriptionID
158- Write-Host " Switched subscription to '$subscriptionID ' `r`n " - ForegroundColor Yellow
172+ }
173+ az account set -- subscription $subscriptionID
174+ Write-Host " Switched subscription to '$subscriptionID ' `r`n " - ForegroundColor Yellow
159175}
160176
161177function DeployAzureResources ([string ]$location , [string ]$modelLocation ) {
@@ -169,9 +185,53 @@ function DeployAzureResources([string]$location, [string]$modelLocation) {
169185 # Make deployment name unique by appending random number
170186 $deploymentName = " KM_SA_Deployment$randomNumberPadded "
171187
188+
189+ if (-not $resourceGroupName ) {
190+ # Generate a new RG name using your existing logic
191+
192+ # Load abbreviation from abbreviations.json (optional)
193+ $abbrs = Get-Content - Raw - Path " ./abbreviations.json" | ConvertFrom-Json
194+ if (-not $abbrs -or -not $abbrs.managementGovernance.resourceGroup ) {
195+ Write-Host " abbreviations.json is missing or malformed."
196+ failureBanner
197+ exit 1
198+ }
199+ $rgPrefix = $abbrs.managementGovernance.resourceGroup # e.g., "rg-"
200+
201+ # Constants
202+ $resourceprefix_name = " kmgs"
203+
204+ # Call Bicep to generate resourcePrefix
205+ $resourcePrefix = az deployment sub create `
206+ -- location $location `
207+ -- name $deploymentName `
208+ -- template- file ./ resourcePrefix.bicep `
209+ -- parameters environmentName= $environmentName location= $location `
210+ -- query " properties.outputs.resourcePrefix.value" `
211+ - o tsv
212+
213+ # Final Resource Group Name
214+ $resourceGroupName = " $rgPrefix$resourceprefix_name$resourcePrefix "
215+
216+ Write-Host " Generated Resource Group Name: $resourceGroupName "
217+
218+ Write-Host " No RG provided. Creating new RG: $resourceGroupName " - ForegroundColor Yellow
219+ az group create -- name $resourceGroupName -- location $location -- tags EnvironmentName= $environmentName | Out-Null
220+ }
221+ else {
222+ $exists = az group exists -- name $resourceGroupName | ConvertFrom-Json
223+ if (-not $exists ) {
224+ Write-Host " Specified RG does not exist. Creating RG: $resourceGroupName " - ForegroundColor Yellow
225+ az group create -- name $resourceGroupName -- location $location -- tags EnvironmentName= $environmentName | Out-Null
226+ }
227+ else {
228+ Write-Host " Using existing RG: $resourceGroupName " - ForegroundColor Green
229+ }
230+ }
231+
172232 # Perform a what-if deployment to preview changes
173233 Write-Host " Evaluating Deployment resource availabilities to preview changes..." - ForegroundColor Yellow
174- $whatIfResult = az deployment sub what- if -- template- file .\main.bicep -- location $location -- name $deploymentName -- parameters modeldatacenter= $modelLocation
234+ $whatIfResult = az deployment group what- if -- resource - group $resourceGroupName -- template- file .\main.bicep -- name $deploymentName -- parameters modeldatacenter= $modelLocation location = $location environmentName = $environmentName
175235
176236 if ($LASTEXITCODE -ne 0 ) {
177237 Write-Host " There might be something wrong with your deployment." - ForegroundColor Red
@@ -181,7 +241,8 @@ function DeployAzureResources([string]$location, [string]$modelLocation) {
181241 }
182242 # Proceed with the actual deployment
183243 Write-Host " Proceeding with Deployment..." - ForegroundColor Yellow
184- $deploymentResult = az deployment sub create -- template- file .\main.bicep -- location $location -- name $deploymentName -- parameters modeldatacenter= $modelLocation
244+ Write-Host " Resource Group Name: $resourceGroupName " - ForegroundColor Yellow
245+ $deploymentResult = az deployment group create -- resource- group $resourceGroupName -- template- file .\main.bicep -- name $deploymentName -- parameters modeldatacenter= $modelLocation location= $location environmentName= $environmentName
185246 # Check if deploymentResult is valid
186247 ValidateVariableIsNullOrEmpty - variableValue $deploymentResult - variableName " Deployment Result"
187248 if ($LASTEXITCODE -ne 0 ) {
@@ -391,7 +452,7 @@ class DeploymentResult {
391452 # Azure App Configuration
392453 $this.AzAppConfigEndpoint = $jsonString.properties.outputs.gs_appconfig_endpoint.value
393454 # App Config Name
394- $this.AzAppConfigName = " appconfig" + $this .ResourceGroupName
455+ $this.AzAppConfigName = " appconfig- " + $jsonString .properties.outputs.gs_solution_prefix.value
395456
396457 }
397458}
@@ -438,6 +499,9 @@ try {
438499 Write-Host " Deploying Azure resources in $location region.....`r`n " - ForegroundColor Yellow
439500
440501 $resultJson = DeployAzureResources - location $location - modelLocation $modelLocation
502+
503+ # Ensure ResourceGroupName is set correctly
504+ $deploymentResult.ResourceGroupName = $resourceGroupName
441505 # Map the deployment result to DeploymentResult object
442506 $deploymentResult.MapResult ($resultJson )
443507 # Display the deployment result
@@ -530,7 +594,7 @@ try {
530594 ' {gpt-4o-modelname}' = $deploymentResult.AzGPT4oModelName
531595 ' {azureopenaiembedding-deployment}' = $deploymentResult.AzGPTEmbeddingModelName
532596 ' {kernelmemory-endpoint}' = " http://kernelmemory-service"
533- }
597+ }
534598
535599 # # Load and update the AI service configuration template
536600 $aiServiceConfigTemplate = Get-Content - Path .\appconfig\aiservice\appconfig.jsonl - Raw
@@ -550,7 +614,7 @@ try {
550614 $filePath = Join-Path $scriptDirectory " .\appconfig\aiservice\appsettings.dev.jsonl"
551615
552616 # # Other variables
553- $appConfigName = $deploymentResult.AzAppConfigName -replace " rg- " , " - "
617+ $appConfigName = $deploymentResult.AzAppConfigName
554618
555619 # # Output the file path for verification
556620 # write-host "Using file path: $filePath"
@@ -731,7 +795,7 @@ try {
731795 # Validate if System Assigned Identity is null or empty
732796 ValidateVariableIsNullOrEmpty - variableValue $systemAssignedIdentity - variableName " System-assigned managed identity"
733797
734- # Validate if ResourceGroupId is null or empty
798+ # Validate if ResourceGroupId is null or empty
735799 ValidateVariableIsNullOrEmpty - variableValue $deploymentResult.ResourceGroupId - variableName " ResourceGroupId"
736800
737801 # Assign the role for aks system assigned managed identity to App Configuration Data Reader role with the scope of Resourcegroup
@@ -848,7 +912,7 @@ try {
848912 Wait-ForCertManager
849913
850914
851- # ======================================================================================================================================================================
915+ # ======================================================================================================================================================================
852916 # Validate AzAppConfigEndpoint IsNull Or Empty.
853917 ValidateVariableIsNullOrEmpty - variableValue $deploymentResult.AzAppConfigEndpoint - variableName " Azure App Configuration Endpoint"
854918 # App Deployment after finishing the AKS infrastructure setup
@@ -933,7 +997,7 @@ try {
933997 docker build " ../App/frontend-app/." -- no- cache - t $acrFrontAppTag
934998 docker push $acrFrontAppTag
935999
936- # ======================================================================================================================================================================
1000+ # ======================================================================================================================================================================
9371001
9381002 # 7.2. Deploy ClusterIssuer in Kubernetes for SSL/TLS certificate
9391003 kubectl apply -f " ./kubernetes/deploy.certclusterissuer.yaml"
@@ -962,12 +1026,12 @@ try {
9621026 successBanner
9631027
9641028 $messageString = " Please find the deployment details below: `r`n " +
965- " 1. Check Front Web Application with this URL - https://${fqdn} `n`r " +
966- " 2. Check GPT Model's TPM rate in your resource group - $ ( $deploymentResult.ResourceGroupName ) `n`r " +
967- " Please set each value high as much as you can set`n`r " +
968- " `t - Open AI Resource Name - $ ( $deploymentResult.AzOpenAiServiceName ) `n`r " +
969- " `t - GPT4o Model - $ ( $deploymentResult.AzGPT4oModelName ) `n`r " +
970- " `t - GPT Embedding Model - $ ( $deploymentResult.AzGPTEmbeddingModelName ) `n`r "
1029+ " 1. Check Front Web Application with this URL - https://${fqdn} `n`r " +
1030+ " 2. Check GPT Model's TPM rate in your resource group - $ ( $deploymentResult.ResourceGroupName ) `n`r " +
1031+ " Please set each value high as much as you can set`n`r " +
1032+ " `t - Open AI Resource Name - $ ( $deploymentResult.AzOpenAiServiceName ) `n`r " +
1033+ " `t - GPT4o Model - $ ( $deploymentResult.AzGPT4oModelName ) `n`r " +
1034+ " `t - GPT Embedding Model - $ ( $deploymentResult.AzGPTEmbeddingModelName ) `n`r "
9711035 Write-Host $messageString - ForegroundColor Yellow
9721036 Write-Host " Don't forget to control the TPM rate for your GPT and Embedding Model in Azure Open AI Studio Deployments section." - ForegroundColor Red
9731037 Write-Host " After controlling the TPM rate for your GPT and Embedding Model, let's start Data file import process with this command." - ForegroundColor Yellow
0 commit comments