Skip to content

Commit

Permalink
Correctly resolve template file from parameter files when suffix appe…
Browse files Browse the repository at this point in the history
…ars multiple times in path
  • Loading branch information
Kasper Schultz Davidsen committed May 31, 2024
1 parent 0a85ba5 commit ded04c4
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/functions/Invoke-AzOpsPush.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@
{ $_.EndsWith('.parameters.json') } {
if ((Get-PSFConfigValue -FullName 'AzOps.Core.AllowMultipleTemplateParameterFiles') -eq $true -and $fileItem.FullName.Split('.')[-3] -match $(Get-PSFConfigValue -FullName 'AzOps.Core.MultipleTemplateParameterFileSuffix').Replace('.','')) {
Write-AzOpsMessage -LogLevel Debug -LogString 'Invoke-AzOpsPush.Resolve.MultipleTemplateParameterFile' -LogStringValues $FilePath
$templatePath = $fileItem.FullName -replace (".$($fileItem.FullName.Split('.')[-3])"), '' -replace '\.parameters.json', '.json'
$bicepTemplatePath = $fileItem.FullName -replace (".$($fileItem.FullName.Split('.')[-3])"), '' -replace '.parameters.json', '.bicep'
$templatePath = $fileItem.FullName -replace "\.$($fileItem.FullName.Split('.')[-3])\.parameters.json$", '.json'
$bicepTemplatePath = $fileItem.FullName -replace "\.$($fileItem.FullName.Split('.')[-3])\.parameters.json$", '.bicep'
}
else {
$templatePath = $fileItem.FullName -replace '\.parameters.json', (Get-PSFConfigValue -FullName 'AzOps.Core.TemplateParameterFileSuffix')
Expand Down Expand Up @@ -210,7 +210,7 @@
{ $_.EndsWith('.bicepparam') } {
if ((Get-PSFConfigValue -FullName 'AzOps.Core.AllowMultipleTemplateParameterFiles') -eq $true -and $fileItem.FullName.Split('.')[-2] -match $(Get-PSFConfigValue -FullName 'AzOps.Core.MultipleTemplateParameterFileSuffix').Replace('.','')) {
Write-AzOpsMessage -LogLevel Debug -LogString 'Invoke-AzOpsPush.Resolve.MultipleTemplateParameterFile' -LogStringValues $FilePath
$bicepTemplatePath = $fileItem.FullName -replace (".$($fileItem.FullName.Split('.')[-2])"), '' -replace '\.bicepparam', '.bicep'
$bicepTemplatePath = $fileItem.FullName -replace "\.$($fileItem.FullName.Split('.')[-2])\.bicepparam$", '.bicep'
}
else {
$bicepTemplatePath = $fileItem.FullName -replace '\.bicepparam', '.bicep'
Expand Down
16 changes: 16 additions & 0 deletions src/tests/integration/Repository.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1167,6 +1167,22 @@ Describe "Repository" {
}
#endregion

#region Bicep multiple parameter files with change, suffix appears multiple times in the path of the associated template
It "Deploy Bicep base template with parameter files where suffix appears multiple times in path" {
Set-PSFConfig -FullName AzOps.Core.AllowMultipleTemplateParameterFiles -Value $true
Set-PSFConfig -FullName AzOps.Core.MultipleTemplateParameterFileSuffix -Value ".\\w+"
$script:bicepRepeatSuffixPath = Get-ChildItem -Path "$($global:testRoot)/templates/rtsuffix0102*" | Copy-Item -Destination $script:resourceGroupDirectory -PassThru -Force
$changeSet = @(
"A`t$($script:bicepRepeatSuffixPath.FullName[0])",
"A`t$($script:bicepRepeatSuffixPath.FullName[1])"
)
{Invoke-AzOpsPush -ChangeSet $changeSet} | Should -Not -Throw
Start-Sleep -Seconds 5
$script:bicepRepeatSuffixPathDeployment = Get-AzResource -ResourceGroupName $($script:resourceGroup).ResourceGroupName -ResourceType 'Microsoft.Network/routeTables' | Where-Object {$_.name -like "rtsuffix*"}
$script:bicepRepeatSuffixPathDeployment.Count | Should -Be 2
}
#endregion

#region Bicep base template with no 1-1 parameter file and AllowMultipleTemplateParameterFile set to true Test should not deploy
It "Try deployment of Bicep base template with missing defaultValue parameter with no 1-1 parameter file and AllowMultipleTemplateParameterFile set to true, Test should not deploy and exit gracefully" {
Set-PSFConfig -FullName AzOps.Core.AllowMultipleTemplateParameterFiles -Value $true
Expand Down
9 changes: 9 additions & 0 deletions src/tests/templates/rtsuffix.0102.02.parameters.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"name": {
"value": "rtsuffix02"
}
}
}
3 changes: 3 additions & 0 deletions src/tests/templates/rtsuffix0102.01.bicepparam
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
using 'rtsuffix0102.bicep'

param name = 'rtsuffix01'
12 changes: 12 additions & 0 deletions src/tests/templates/rtsuffix0102.bicep
Original file line number Diff line number Diff line change
@@ -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: [
]
}
}

0 comments on commit ded04c4

Please sign in to comment.