Azure / Azure/azure-powershell
Az PowerShell Bicepparam deployments / WhatIf does not work if filename contains brackets.
- Dominant language
- C#
- Stars
- 4.8k
- Forks
- 4.3k
- Avg merge
- 2d 17h
- Merged PRs (30d)
- 51
Description
### Description
When deploying or getting WhatIf results using `Get-AzResourceGroupDeploymentWhatIfResult` or `New-AzResourceGroupDeployment`, if using a bicepparam file with brackets - [ ] - in filename, the deployment fails with `Invalid Bicepparam file path.`.
This is only the case in param files, templates work.
Repro steps:
Create a bicep file with simple contents:
```Bicep
param inValue string = 'in'
output outValue string = inValue
```
Save it as filename with .bicep extension.
Create a bicepparam file to match
```Bicep
using 'test[Bicep].bicep'
param inValue = 'whatever'
```
Doing a WhatIf deploy of only bicep file works, but using the bicepparam file fails.
Escaping the brackets or not, trying the solution from [the similar issue with blobs](https://github.com/Azure/azure-powershell/issues/10049) it all has the same result. Also verified on PowerShell on Windows and Linux machines.
Deploys with az cli works fine.
The obvious solution and general recommendation is always "Don't use weird characters in file names", but since brackets are valid file name characters and do work with the bicep file, I do think they should work with bicepparam files as well.
(Oh, and just to be clear - I have _not_ tested this with ARM json param files, and do not know they behaviour there.)
### Issue script & Debug output
```PowerShell
> Get-AzResourceGroupDeploymentWhatIfResult -Name 'test' -ResourceGroupName RG -TemplateFile '.\test`[Bicep`].bicep' -TemplateParameterFile '.\test`[Bicep`].bicepparam'
DEBUG: 09:27:10 - [ConfigManager] Got nothing from [DisplaySecretsWarning], Module = [], Cmdlet = []. Returning default value [True].
DEBUG: 09:27:10 - GetAzureResourceGroupDeploymentWhatIfResultCmdlet begin processing with ParameterSet 'ByTemplateFileAndParameterFile'.
DEBUG: 09:27:10 - using account id 'nope, not sharing this'...
DEBUG: 09:27:10 - [ConfigManager] Got nothing from [DisplayBreakingChangeWarning], Module = [Az.Resources], Cmdlet = [Get-AzResourceGroupDeploymentWhatIfResult]. Returning default value [True].
```
### Environment data
```PowerShell
Name Value
---- -----
PSVersion 7.5.4
PSEdition Core
GitCommitId 7.5.4
OS Microsoft Windows 10.0.26200
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
```
### Module versions
```PowerShell
ModuleType Version PreRelease Name ExportedCommands
---------- ------- ---------- ---- ----------------
Script 5.3.1 Az.Accounts {Add-AzEnvironment, Clear-AzConfig, Clear-AzContext, Clear-AzDefault…}
Script 9.0.0 Az.Resources {Export-AzResourceGroup, Export-AzTemplateSpec, Get-AzDenyAssignment, Get-AzDeployment…}
```
### Error output
```PowerShell
HistoryId: 46
Message : Invalid Bicepparam file path.
StackTrace : at Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.ResourceManagerCmdletBase.HandleException(ExceptionDispatchInfo capturedException)
at Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.ResourceManagerCmdletBase.BeginProcessing()
at System.Management.Automation.Cmdlet.DoBeginProcessing()
at System.Management.Automation.CommandProcessorBase.DoBegin()
Exception : Microsoft.Azure.Commands.Common.Exceptions.AzPSArgumentException
InvocationInfo : {Get-AzResourceGroupDeploymentWhatIfResult}
Line : Get-AzResourceGroupDeploymentWhatIfResult -Name 'test' -ResourceGroupName RG -TemplateFile '.\test`[Bicep`].bicep' -TemplateParameterFile '.\test`[Bicep`].bicepparam'
Position : At line:1 char:1
+ Get-AzResourceGroupDeploymentWhatIfResult -Name 'test' -ResourceGroup 
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId : 46
```
Contributor guide
Assessment
This issue has not been assessed yet.