From 3d2b669accdbb9e65b1bc65eca24b75ba7d410d5 Mon Sep 17 00:00:00 2001 From: Jesper Fajers Date: Tue, 26 Mar 2024 11:39:42 +0000 Subject: [PATCH] Update --- src/functions/Invoke-AzOpsPush.ps1 | 6 ++++- .../functions/New-AzOpsDeployment.ps1 | 22 +++++++++++++------ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/functions/Invoke-AzOpsPush.ps1 b/src/functions/Invoke-AzOpsPush.ps1 index a75c1866..b831049d 100644 --- a/src/functions/Invoke-AzOpsPush.ps1 +++ b/src/functions/Invoke-AzOpsPush.ps1 @@ -462,7 +462,11 @@ #Starting deployment $WhatIfPreference = $WhatIfPreferenceState $uniqueProperties = 'Scope', 'DeploymentName', 'TemplateFilePath', 'TemplateParameterFilePath' - $uniqueDeployment = $deploymentList | Select-Object $uniqueProperties -Unique + $uniqueDeployment = $deploymentList | Select-Object $uniqueProperties -Unique | ForEach-Object { + $TemplateFileContent = [System.IO.File]::ReadAllText($_.TemplateFilePath) + $TemplateObject = ConvertFrom-Json $TemplateFileContent -AsHashtable + $_ | Add-Member -MemberType NoteProperty -Name 'TemplateObject' -Value $TemplateObject -PassThru + } $deploymentResult = @() if ($uniqueDeployment) { diff --git a/src/internal/functions/New-AzOpsDeployment.ps1 b/src/internal/functions/New-AzOpsDeployment.ps1 index 2d8d94e2..542630dd 100644 --- a/src/internal/functions/New-AzOpsDeployment.ps1 +++ b/src/internal/functions/New-AzOpsDeployment.ps1 @@ -9,6 +9,8 @@ Name under which to deploy the state. .PARAMETER TemplateFilePath Path where the ARM templates can be found. + .PARAMETER TemplateObject + TemplateObject where the templates content is stored in-memory. .PARAMETER TemplateParameterFilePath Path where the parameters of the ARM templates can be found. .PARAMETER Mode @@ -44,6 +46,10 @@ [string] $TemplateFilePath = (Get-PSFConfigValue -FullName 'AzOps.Core.MainTemplate'), + [Parameter(ValueFromPipelineByPropertyName = $true)] + [hashtable] + $TemplateObject, + [Parameter(ValueFromPipelineByPropertyName = $true)] [AllowEmptyString()] [AllowNull()] @@ -89,9 +95,11 @@ #endregion Resolve Scope #region Parse Content - $templateContent = Get-Content $TemplateFilePath | ConvertFrom-Json -AsHashtable - - if ($templateContent.metadata._generator.name -eq 'bicep') { + if ($null -eq $TemplateObject) { + $TemplateFileContent = [System.IO.File]::ReadAllText($TemplateFilePath) + $TemplateObject = ConvertFrom-Json $TemplateFileContent -AsHashtable + } + if ($TemplateObject.metadata._generator.name -eq 'bicep') { # Detect bicep templates $bicepTemplate = $true } @@ -101,7 +109,7 @@ # Configure variables/parameters and the WhatIf/Deployment cmdlets to be used per scope $defaultDeploymentRegion = (Get-PSFConfigValue -FullName 'AzOps.Core.DefaultDeploymentRegion') $parameters = @{ - 'TemplateFile' = $TemplateFilePath + 'TemplateObject' = $TemplateObject 'SkipTemplateParameterPrompt' = $true 'Location' = $defaultDeploymentRegion } @@ -109,7 +117,7 @@ $parameters.ResultFormat = $WhatIfResultFormat } # Resource Groups excluding Microsoft.Resources/resourceGroups that needs to be submitted at subscription scope - if ($scopeObject.resourcegroup -and $templateContent.resources[0].type -ne 'Microsoft.Resources/resourceGroups') { + if ($scopeObject.resourcegroup -and $TemplateObject.resources[0].type -ne 'Microsoft.Resources/resourceGroups') { Write-AzOpsMessage -LogLevel Verbose -LogString 'New-AzOpsDeployment.ResourceGroup.Processing' -LogStringValues $scopeObject -Target $scopeObject Set-AzOpsContext -ScopeObject $scopeObject $whatIfCommand = 'Get-AzResourceGroupDeploymentWhatIfResult' @@ -220,12 +228,12 @@ Write-AzOpsMessage -LogLevel Verbose -LogString 'New-AzOpsDeployment.WhatIfResults' -LogStringValues ($results | Out-String) -Target $scopeObject Write-AzOpsMessage -LogLevel InternalComment -LogString 'New-AzOpsDeployment.WhatIfFile' -Target $scopeObject if ($parameters.TemplateParameterFile) { - $deploymentResult.filePath = $parameters.TemplateFile + $deploymentResult.filePath = $TemplateFilePath $deploymentResult.parameterFilePath = $parameters.TemplateParameterFile $deploymentResult.results = $results } else { - $deploymentResult.filePath = $parameters.TemplateFile + $deploymentResult.filePath = $TemplateFilePath $deploymentResult.results = $results } }