From 150d23d3c58246d123b6445d317774faad105936 Mon Sep 17 00:00:00 2001 From: Jesper Fajers Date: Wed, 13 Dec 2023 17:23:26 +0000 Subject: [PATCH] UpdateLogic --- docs/wiki/Frequently-Asked-Questions.md | 9 ++++++++ docs/wiki/Settings.md | 7 +++--- src/functions/Invoke-AzOpsPush.ps1 | 22 +++++++++++++++++++ src/internal/configurations/Core.ps1 | 1 + src/tests/integration/Repository.Tests.ps1 | 16 ++++++++++++++ src/tests/templates/deployallrtbase.bicep | 12 ++++++++++ .../deployallrtbase.x123.parameters.json | 9 ++++++++ .../templates/deployallrtbase.xabc.bicepparam | 3 +++ 8 files changed, 76 insertions(+), 3 deletions(-) create mode 100644 src/tests/templates/deployallrtbase.bicep create mode 100644 src/tests/templates/deployallrtbase.x123.parameters.json create mode 100644 src/tests/templates/deployallrtbase.xabc.bicepparam diff --git a/docs/wiki/Frequently-Asked-Questions.md b/docs/wiki/Frequently-Asked-Questions.md index 9ff9702b..ecc1f7b4 100644 --- a/docs/wiki/Frequently-Asked-Questions.md +++ b/docs/wiki/Frequently-Asked-Questions.md @@ -17,6 +17,7 @@ This article answers frequently asked questions relating to AzOps. - [**I want to discover and manage several Azure Firewall Policy's and rule collections spread out across several resource groups and subscriptions**](#i-want-to-discover-and-manage-several-azure-firewall-policys-and-rule-collections-spread-out-across-several-resource-groups-and-subscriptions) - [Push scenarios and settings](#push-scenarios-and-settings) - [**I want to have multiple different deployments at scope using the same template file but different parameter files**](#i-want-to-have-multiple-different-deployments-at-scope-using-the-same-template-file-but-different-parameter-files) + - [**I have AllowMultipleTemplateParameterFiles set to true and when changes are made to a template no deployment is performed**](#i-have-allowmultipletemplateparameterfiles-set-to-true-and-when-changes-are-made-to-a-template-no-deployment-is-performed) - [**I am getting: Missing defaultValue and no parameter file found, skip deployment**](#i-am-getting-missing-defaultvalue-and-no-parameter-file-found-skip-deployment) ## Subscriptions or resources not showing up in repository @@ -182,6 +183,14 @@ scope/ ``` > Note: To avoid having AzOps deploy the base `template.bicep` unintentionally, ensure you have at least one parameter without default value in `template.bicep` and no lingering 1:1 matching parameter file. +### **I have AllowMultipleTemplateParameterFiles set to true and when changes are made to a template no deployment is performed** + +When using a custom deployment templates with multiple corresponding parameter files, can I ensure that changes made to the template triggers AzOps to create separate deployments for each corresponding parameter file? + +Yes, ensure the following setting `Core.DeployAllMultipleTemplateParameterFiles` is set to `true`. + +> Note: By default, AzOps does not try to identify and deploy files that have not changed, by changing this setting AzOps will attempt to resolve matching parameter files for deployment based on deployment template. + ### **I am getting: Missing defaultValue and no parameter file found, skip deployment** To confirm if this applies to you, check the pipeline logs for the following message: diff --git a/docs/wiki/Settings.md b/docs/wiki/Settings.md index aa58160a..d37fa2ad 100644 --- a/docs/wiki/Settings.md +++ b/docs/wiki/Settings.md @@ -36,9 +36,10 @@ The following configuration values can be modified within the `settings.json` fi | 24 | SubscriptionsToIncludeResourceGroups | Filter which Subscription IDs should include Resource Groups in pull [Logic Updated in v2.0.0](https://github.com/Azure/AzOps/releases/tag/2.0.0) | `"Core.SubscriptionsToIncludeResourceGroups": ["*"]` | | 25 | TemplateParameterFileSuffix | Default template file suffix. *Not recommended to change* | `"Core.TemplateParameterFileSuffix": ".json"` | | 26 | AllowMultipleTemplateParameterFiles | Control multiple parameter file behaviour. *Not recommended to change* | `"Core.AllowMultipleTemplateParameterFiles": false` | -| 27 | MultipleTemplateParameterFileSuffix | Multiple parameter file suffix identifier. *Example mytemplate.x1.bicepparam* | `"Core.MultipleTemplateParameterFileSuffix": ".x"` | -| 28 | ThrottleLimit | Value declaring number of parallel threads. [Read more](https://github.com/azure/azops/wiki/performance-considerations) | `"Core.ThrottleLimit": 5` | -| 29 | WhatifExcludedChangeTypes | Exclude specific change types from WhatIf operations | `"Core.WhatifExcludedChangeTypes": ["NoChange","Ignore"]` | +| 27 | DeployAllMultipleTemplateParameterFiles | Control base template deployment behaviour with changes and un-changed multiple corresponding parameter files. | `"Core.DeployAllMultipleTemplateParameterFiles": false` | +| 28 | MultipleTemplateParameterFileSuffix | Multiple parameter file suffix identifier. *Example mytemplate.x1.bicepparam* | `"Core.MultipleTemplateParameterFileSuffix": ".x"` | +| 29 | ThrottleLimit | Value declaring number of parallel threads. [Read more](https://github.com/azure/azops/wiki/performance-considerations) | `"Core.ThrottleLimit": 5` | +| 30 | WhatifExcludedChangeTypes | Exclude specific change types from WhatIf operations | `"Core.WhatifExcludedChangeTypes": ["NoChange","Ignore"]` | ## Workflow / Pipeline Settings diff --git a/src/functions/Invoke-AzOpsPush.ps1 b/src/functions/Invoke-AzOpsPush.ps1 index 32966d52..90105c4c 100644 --- a/src/functions/Invoke-AzOpsPush.ps1 +++ b/src/functions/Invoke-AzOpsPush.ps1 @@ -175,6 +175,28 @@ Write-PSFMessage -Level Verbose @common -String 'Invoke-AzOpsPush.Resolve.ParameterFound' -StringValues $FilePath, $parameterPath $result.TemplateParameterFilePath = $parameterPath } + elseif ((Get-PSFConfigValue -FullName 'AzOps.Core.AllowMultipleTemplateParameterFiles') -eq $true -and (Get-PSFConfigValue -FullName 'AzOps.Core.DeployAllMultipleTemplateParameterFiles') -eq $true) { + # Check for multiple associated template parameter files + $paramFileList = Get-ChildItem -Path $fileItem.Directory | Where-Object { ($_.Name.Split('.')[-3] -match $(Get-PSFConfigValue -FullName 'AzOps.Core.MultipleTemplateParameterFileSuffix').Replace('.','')) -or ($_.Name.Split('.')[-2] -match $(Get-PSFConfigValue -FullName 'AzOps.Core.MultipleTemplateParameterFileSuffix').Replace('.','')) } + if ($paramFileList) { + $multiResult = @() + foreach ($paramFile in $paramFileList) { + # Process possible parameter files for template equivalent + if (($fileItem.FullName.Split('.')[-2] -eq $paramFile.FullName.Split('.')[-3]) -or ($fileItem.FullName.Split('.')[-2] -eq $paramFile.FullName.Split('.')[-4])) { + Write-PSFMessage -Level Verbose @common -String 'Invoke-AzOpsPush.Resolve.MultipleTemplateParameterFile' -StringValues $paramFile.FullName + $multiResult += Resolve-ArmFileAssociation -ScopeObject $scopeObject -FilePath $paramFile -AzOpsMainTemplate $AzOpsMainTemplate + } + } + if ($multiResult) { + # Return completed object + return $multiResult + } + else { + Write-PSFMessage -Level Verbose @common -String 'Invoke-AzOpsPush.Resolve.ParameterNotFound' -StringValues $FilePath, $parameterPath + } + + } + } else { Write-PSFMessage -Level Verbose @common -String 'Invoke-AzOpsPush.Resolve.ParameterNotFound' -StringValues $FilePath, $parameterPath if ((Get-PSFConfigValue -FullName 'AzOps.Core.AllowMultipleTemplateParameterFiles') -eq $true) { diff --git a/src/internal/configurations/Core.ps1 b/src/internal/configurations/Core.ps1 index 490a8146..8eebec11 100644 --- a/src/internal/configurations/Core.ps1 +++ b/src/internal/configurations/Core.ps1 @@ -27,6 +27,7 @@ Set-PSFConfig -Module AzOps -Name Core.State -Value (Join-Path $pwd -ChildPath " Set-PSFConfig -Module AzOps -Name Core.SubscriptionsToIncludeResourceGroups -Value @('*') -Initialize -Validation stringarray -Description 'Requires SkipResourceGroup to be false. Subscription ID or Display Name that matches the filter. Powershell filter that matches with like operator is supported.' Set-PSFConfig -Module AzOps -Name Core.TemplateParameterFileSuffix -Value '.json' -Initialize -Validation string -Description 'Parameter file suffix identifier' Set-PSFConfig -Module AzOps -Name Core.AllowMultipleTemplateParameterFiles -Value $false -Initialize -Validation string -Description 'Global flag to control multiple parameter file behaviour' +Set-PSFConfig -Module AzOps -Name Core.DeployAllMultipleTemplateParameterFiles -Value $false -Initialize -Validation string -Description 'Global flag to control base template deployment behaviour with changes and un-changed multiple corresponding parameter files' Set-PSFConfig -Module AzOps -Name Core.MultipleTemplateParameterFileSuffix -Value '.x' -Initialize -Validation string -Description 'Multiple parameter file suffix identifier' Set-PSFConfig -Module AzOps -Name Core.ThrottleLimit -Value 5 -Initialize -Validation integer -Description 'Throttle limit used in Foreach-Object -Parallel for resource/subscription discovery' Set-PSFConfig -Module AzOps -Name Core.WhatifExcludedChangeTypes -Value @('NoChange', 'Ignore') -Initialize -Validation stringarray -Description 'Exclude specific change types from WhatIf operations.' \ No newline at end of file diff --git a/src/tests/integration/Repository.Tests.ps1 b/src/tests/integration/Repository.Tests.ps1 index 6314c3df..8182511e 100644 --- a/src/tests/integration/Repository.Tests.ps1 +++ b/src/tests/integration/Repository.Tests.ps1 @@ -1074,6 +1074,7 @@ Describe "Repository" { "A`t$($script:bicepMultiParamPath.FullName[2])" ) {Invoke-AzOpsPush -ChangeSet $changeSet} | Should -Not -Throw + Start-Sleep -Seconds 5 $script:bicepMultiParamPathDeployment = Get-AzResource -ResourceGroupName $($script:resourceGroup).ResourceGroupName -ResourceType 'Microsoft.Network/routeTables' | Where-Object {$_.name -like "rtmultibasex*"} $script:bicepMultiParamPathDeployment.Count | Should -Be 2 } @@ -1098,6 +1099,21 @@ Describe "Repository" { {Invoke-AzOpsPush -ChangeSet $changeSet} | Should -Throw } #endregion + + #region Bicep template with change, AzOps set to resolve corresponding parameter files and create multiple deployments + It "Deploy Bicep template with change, AzOps set to resolve corresponding parameter files and create multiple deployments" { + Set-PSFConfig -FullName AzOps.Core.AllowMultipleTemplateParameterFiles -Value $true + Set-PSFConfig -FullName AzOps.Core.DeployAllMultipleTemplateParameterFiles -Value $true + $script:deployAllRtParamPath = Get-ChildItem -Path "$($global:testRoot)/templates/deployallrtbase*" | Copy-Item -Destination $script:resourceGroupDirectory -PassThru -Force + $changeSet = @( + "A`t$($script:deployAllRtParamPath.FullName[0])" + ) + {Invoke-AzOpsPush -ChangeSet $changeSet} | Should -Not -Throw + Start-Sleep -Seconds 5 + $script:deployAllRtParamPathDeployment = Get-AzResource -ResourceGroupName $($script:resourceGroup).ResourceGroupName -ResourceType 'Microsoft.Network/routeTables' | Where-Object {$_.name -like "deployallrtbasex*"} + $script:deployAllRtParamPathDeployment.Count | Should -Be 2 + } + #endregion } AfterAll { diff --git a/src/tests/templates/deployallrtbase.bicep b/src/tests/templates/deployallrtbase.bicep new file mode 100644 index 00000000..f790cbf7 --- /dev/null +++ b/src/tests/templates/deployallrtbase.bicep @@ -0,0 +1,12 @@ +param name string +param location string = resourceGroup().location + +resource symbolicname 'Microsoft.Network/routeTables@2023-04-01' = { + name: name + location: location + properties: { + disableBgpRoutePropagation: false + routes: [ + ] + } +} diff --git a/src/tests/templates/deployallrtbase.x123.parameters.json b/src/tests/templates/deployallrtbase.x123.parameters.json new file mode 100644 index 00000000..cf4c480b --- /dev/null +++ b/src/tests/templates/deployallrtbase.x123.parameters.json @@ -0,0 +1,9 @@ +{ + "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#", + "contentVersion": "1.0.0.0", + "parameters": { + "name": { + "value": "deployallrtbasex123" + } + } +} \ No newline at end of file diff --git a/src/tests/templates/deployallrtbase.xabc.bicepparam b/src/tests/templates/deployallrtbase.xabc.bicepparam new file mode 100644 index 00000000..2db0b566 --- /dev/null +++ b/src/tests/templates/deployallrtbase.xabc.bicepparam @@ -0,0 +1,3 @@ +using './deployallrtbase.bicep' + +param name = toLower('deployallrtbasexabc')