@@ -10,16 +10,16 @@ param (
1010 $Configuration = " Debug" ,
1111
1212 [string ]
13- $ResourceGroupName = ' rg-pub-dbt-extension' ,
13+ $resourceGroupName = ' rg-pub-dbt-extension' ,
1414
1515 [string ]
16- $Location = ' westeurope' ,
16+ $location = ' westeurope' ,
1717
1818 [string ]
19- $ContainerRegistryName = " acrdbtextension" ,
19+ $containerRegistryName = " acrdbtextension" ,
2020
2121 [string ]
22- $DatabricksWorkspaceName = ' dbt-pub-dbt-extension' ,
22+ $databricksWorkspaceName = ' dbt-pub-dbt-extension' ,
2323
2424 [switch ]
2525 $Bootstrap ,
@@ -122,14 +122,77 @@ $projectPath = getProjectPath $ProjectName
122122
123123if ($Bootstrap.IsPresent )
124124{
125- $result = New-AzDeployment - TemplateFile (Join-Path $PSScriptRoot ' infrastructure' ' main.bicep' ) `
126- - TemplateParameterFile (Join-Path $PSScriptRoot ' infrastructure' ' main.bicepparam.json' ) `
127- - Location $Location `
125+ $bicepFile = Join-Path $PSScriptRoot ' infrastructure' ' main.bicep'
126+ $bicepParameterFile = Join-Path $PSScriptRoot ' infrastructure' ' main.bicepparam'
127+
128+ # Go through existing to see if user provided different parameters
129+ $currentParameters = $PSBoundParameters
130+ if ($currentParameters.ContainsKey (' ResourceGroupName' ) -or $currentParameters.ContainsKey (' Location' ) -or $currentParameters.ContainsKey (' ContainerRegistryName' ) -or $currentParameters.ContainsKey (' DatabricksWorkspaceName' )){
131+ $bicepExe = testBicepExe
132+ if ($bicepExe ) {
133+ $randomFileName = [System.IO.Path ]::GetRandomFileName()
134+ $fileExtension = [System.IO.Path ]::GetExtension($randomFileName )
135+ $randomFileName = $randomFileName.Replace ($fileExtension , ' .json' )
136+ $tempJsonPath = Join-Path $env: TEMP $randomFileName
137+
138+ # Using outfile instead of stdout which has large outpus
139+ & $bicepExe build-params (Join-Path $PSScriptRoot ' infrastructure' ' main.bicepparam' ) `
140+ -- outfile $tempJsonPath
141+
142+ $existingParameters = Get-Content - Path $tempJsonPath - Raw | ConvertFrom-Json - AsHashtable
143+
144+ # Set new content
145+ $setContent = $false
146+ foreach ($key in $currentParameters.Keys ) {
147+ Write-Verbose " Processing parameter '$key ' with value '$ ( $currentParameters [$key ]) '"
148+ if ($existingParameters.parameters.ContainsKey ($key )) {
149+ Write-Verbose - Message " Parameter '$key ' already exists with value '$ ( $existingParameters.parameters [$key ].value) '"
150+ if ($existingParameters.parameters [$key ].value -ne $currentParameters [$key ]) {
151+ $setContent = $true
152+ Write-Verbose " Updating parameter '$key ' from '$ ( $existingParameters.parameters [$key ].value) ' to '$ ( $currentParameters [$key ]) '"
153+ $existingParameters.parameters [$key ].value = $currentParameters [$key ]
154+ }
155+ }
156+ }
157+
158+ if ($setContent ) {
159+ Write-Verbose " Updating parameters in '$tempJsonPath '"
160+ Set-Content - Path $tempJsonPath - Value ($existingParameters | ConvertTo-Json - Depth 10 ) - Encoding UTF8 - Force
161+
162+ $randomFileName = [System.IO.Path ]::GetRandomFileName()
163+ $fileExtension = [System.IO.Path ]::GetExtension($randomFileName )
164+ $randomFileName = $randomFileName.Replace ($fileExtension , ' .bicepparam' )
165+ $tempBicepParameterFile = Join-Path (Split-Path $bicepParameterFile - Parent) $randomFileName
166+ & $bicepExe decompile- params $tempJsonPath `
167+ -- outfile $tempBicepParameterFile `
168+ -- bicep- file $bicepFile
169+ Write-Verbose " Decompiled parameters to '$tempBicepParameterFile '"
170+
171+ # Reset bicepParameterFile to the new file
172+ $bicepParameterFile = $tempBicepParameterFile
173+ }
174+ }
175+
176+ }
177+
178+ $params = @ {
179+ TemplateFile = $bicepFile
180+ TemplateParameterFile = $bicepParameterFile
181+ Location = $location
182+ }
183+
184+ Write-Verbose " Deploying Bicep template with parameters:" - Verbose
185+ Write-Verbose ($params | ConvertTo-Json | Out-String ) - Verbose
186+ $result = New-AzDeployment @params
128187
129188 $environment = @ {
130189 ContainerRegistryUrl = ([System.String ]::Concat($result.Outputs.containerLoginServer.value , ' .azurecr.io' ))
131190 WorkspaceUrl = (' https://' + $result.Outputs.dbtWorkspaceUrl.value )
132191 }
192+
193+ if ($setContent ) {
194+ Remove-Item - Path $tempBicepParameterFile - Force - ErrorAction Ignore
195+ }
133196}
134197
135198if ($Clean.IsPresent )
0 commit comments