Skip to content

Commit

Permalink
Update (#870)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jefajers authored Mar 28, 2024
1 parent 2451859 commit f3b5da7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
6 changes: 5 additions & 1 deletion src/functions/Invoke-AzOpsPush.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
22 changes: 15 additions & 7 deletions src/internal/functions/New-AzOpsDeployment.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -44,6 +46,10 @@
[string]
$TemplateFilePath = (Get-PSFConfigValue -FullName 'AzOps.Core.MainTemplate'),

[Parameter(ValueFromPipelineByPropertyName = $true)]
[hashtable]
$TemplateObject,

[Parameter(ValueFromPipelineByPropertyName = $true)]
[AllowEmptyString()]
[AllowNull()]
Expand Down Expand Up @@ -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
}
Expand All @@ -101,15 +109,15 @@
# 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
}
if ($WhatIfResultFormat) {
$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'
Expand Down Expand Up @@ -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
}
}
Expand Down

0 comments on commit f3b5da7

Please sign in to comment.