bicep
bicep copied to clipboard
Azure CLI/Bicep Deployment Ignores Inline Parameters when Supplied with bicepparam File
Bicep version 2.57.0
Describe the bug
When deploying a Bicep template using az deployment sub create
, all inline parameters specified in the command are ignored when also passed in with a bicepparam
file. This occurs regardless of whether the parameters are hardcoded or passed from Azure Pipeline variables/parameters. The deployment proceeds with the default values specified in the Bicep file.
To Reproduce
Define a main.bicep
template which includes a parameter to be passed from a bicepparam
file, and a parameter to be passed inline, with a default value to avoid the bicepparam
file throwing an error:
param tags object
param deployFoo bool = true
resource fooResourceGroup 'Microsoft.Resources/resourceGroups@2021-04-01' = if (deployFoo ) {
name: 'foo-rg'
location: 'uksouth'
tags:tags
}
Define a params.bicepparam
file:
using '../main.bicep'
param tags = {//omitted for brevity}
Define an azure-pipelines.yaml
and use the AzureCLI@2 task with PowerShell to deploy the template whilst supplying both a parameter file and an inline parameter:
trigger:
- main
pool:
vmImage: 'windows-latest'
steps:
- task: AzureCLI@2
inputs:
azureSubscription: '<YourServiceConnectionName>'
scriptType: 'ps'
scriptLocation: 'inlineScript'
inlineScript: |
az deployment sub create `
--location "uksouth" `
--template-file "path/to/main.bicep" `
--parameters "path/to/params.bicepparam" `
deployFoo=false
When the above pipeline is run, the deployFoo
value is seen as true
, and the resource group is deployed.
Additional context I've seen a few issues and threads about the problem, but it still persists: https://github.com/Azure/bicep/issues/11445 https://github.com/Azure/bicep/issues/11042
Could you try instead using:
trigger:
- main
pool:
vmImage: 'windows-latest'
steps:
- task: AzureCLI@2
inputs:
azureSubscription: '<YourServiceConnectionName>'
scriptType: 'ps'
scriptLocation: 'inlineScript'
inlineScript: |
az deployment sub create `
--location "uksouth" `
--template-file "path/to/main.bicep" `
--parameters "path/to/params.bicepparam" `
--parameters deployFoo=false
@anthony-c-martin Ah that does work! Thanks.
Do you think it's worth updating the docs to clarify this? Or is this more of a workaround until a longer term fix is implemented?
Good question - I'm actually not sure if this is a bug or by design. Either way, I think updating our docs to give some examples of inline parameter overrides is a really good idea - tagging @mumian.
@anthony-c-martin When using multiple arguments with a .bicepparam file, I get the following error:
ERROR: Can not use --parameters argument more than once when using a .bicepparam file
@ossiam - can you share the full command and parameters that you tried to pass that led to this failure?
@Ossiam - it sounds like you are using an old version of Azure CLI; support for supplemental parameters was added in 2.54.0. Please could you try again with a more recent version, and confirm this is still an issue?
The article has been updated - https://github.com/MicrosoftDocs/azure-docs-pr/pull/270808.