diff --git a/src/functions/Invoke-AzOpsPush.ps1 b/src/functions/Invoke-AzOpsPush.ps1 index f8d445a6..45b6df8d 100644 --- a/src/functions/Invoke-AzOpsPush.ps1 +++ b/src/functions/Invoke-AzOpsPush.ps1 @@ -167,12 +167,12 @@ { $_.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') - $bicepTemplatePath = $fileItem.FullName -replace '.parameters.json', '.bicep' + $templatePath = $fileItem.FullName -replace '\.parameters.json$', (Get-PSFConfigValue -FullName 'AzOps.Core.TemplateParameterFileSuffix') + $bicepTemplatePath = $fileItem.FullName -replace '\.parameters.json$', '.bicep' } if (Test-Path $templatePath) { if ($CompareDeploymentToDeletion) { @@ -210,10 +210,10 @@ { $_.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' + $bicepTemplatePath = $fileItem.FullName -replace '\.bicepparam$', '.bicep' } if (Test-Path $bicepTemplatePath) { if ($CompareDeploymentToDeletion) { diff --git a/src/internal/functions/ConvertFrom-AzOpsBicepTemplate.ps1 b/src/internal/functions/ConvertFrom-AzOpsBicepTemplate.ps1 index 0b3f72f4..333e08a8 100644 --- a/src/internal/functions/ConvertFrom-AzOpsBicepTemplate.ps1 +++ b/src/internal/functions/ConvertFrom-AzOpsBicepTemplate.ps1 @@ -53,7 +53,7 @@ continue } } - $transpiledTemplatePath = [IO.Path]::GetFullPath("$($BicepTemplatePath -replace '\.bicep', '.json')") + $transpiledTemplatePath = [IO.Path]::GetFullPath("$($BicepTemplatePath -replace '\.bicep$', '.json')") if ($transpiledTemplatePath -notin $ConvertedTemplate) { # Convert bicep template Write-AzOpsMessage -LogLevel Debug -LogString 'ConvertFrom-AzOpsBicepTemplate.Resolve.ConvertBicepTemplate' -LogStringValues $BicepTemplatePath, $transpiledTemplatePath @@ -69,7 +69,7 @@ if (-not $SkipParam) { if (-not $BicepParamTemplatePath) { # Check if bicep template has associated bicepparam file - $bicepParametersPath = $BicepTemplatePath -replace '\.bicep', '.bicepparam' + $bicepParametersPath = $BicepTemplatePath -replace '\.bicep$', '.bicepparam' Write-AzOpsMessage -LogLevel Debug -LogString 'ConvertFrom-AzOpsBicepTemplate.Resolve.BicepParam' -LogStringValues $BicepTemplatePath, $bicepParametersPath } elseif ($BicepParamTemplatePath) { @@ -85,7 +85,7 @@ } } if (-not $skipParameters -and $bicepParametersPath -and (Test-Path $bicepParametersPath)) { - $transpiledParametersPath = [IO.Path]::GetFullPath("$($bicepParametersPath -replace '\.bicepparam', '.parameters.json')") + $transpiledParametersPath = [IO.Path]::GetFullPath("$($bicepParametersPath -replace '\.bicepparam$', '.parameters.json')") if ($transpiledParametersPath -notin $ConvertedParameter) { # Convert bicepparam to ARM parameter file Write-AzOpsMessage -LogLevel Debug -LogString 'ConvertFrom-AzOpsBicepTemplate.Resolve.ConvertBicepParam' -LogStringValues $bicepParametersPath, $transpiledParametersPath diff --git a/src/tests/integration/Repository.Tests.ps1 b/src/tests/integration/Repository.Tests.ps1 index e8d3858f..d0cb8dc4 100644 --- a/src/tests/integration/Repository.Tests.ps1 +++ b/src/tests/integration/Repository.Tests.ps1 @@ -1167,6 +1167,23 @@ 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 + Set-PSFConfig -FullName AzOps.Core.MultipleTemplateParameterFileSuffix -Value ".x" + } + #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 diff --git a/src/tests/templates/rtsuffix0102.01.bicepparam b/src/tests/templates/rtsuffix0102.01.bicepparam new file mode 100644 index 00000000..2dde8090 --- /dev/null +++ b/src/tests/templates/rtsuffix0102.01.bicepparam @@ -0,0 +1,3 @@ +using 'rtsuffix0102.bicep' + +param name = 'rtsuffix01' diff --git a/src/tests/templates/rtsuffix0102.02.parameters.json b/src/tests/templates/rtsuffix0102.02.parameters.json new file mode 100644 index 00000000..113f7f69 --- /dev/null +++ b/src/tests/templates/rtsuffix0102.02.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": "rtsuffix02" + } + } +} \ No newline at end of file diff --git a/src/tests/templates/rtsuffix0102.bicep b/src/tests/templates/rtsuffix0102.bicep new file mode 100644 index 00000000..f790cbf7 --- /dev/null +++ b/src/tests/templates/rtsuffix0102.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: [ + ] + } +}