bicep icon indicating copy to clipboard operation
bicep copied to clipboard

Azure CLI/Bicep Deployment Ignores Inline Parameters when Supplied with bicepparam File

Open AlexGlassman opened this issue 11 months ago • 3 comments

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

AlexGlassman avatar Feb 28 '24 12:02 AlexGlassman

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 avatar Feb 28 '24 14:02 anthony-c-martin

@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?

AlexGlassman avatar Feb 28 '24 16:02 AlexGlassman

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 avatar Feb 29 '24 14:02 anthony-c-martin

@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 avatar Apr 02 '24 14:04 Ossiam

@ossiam - can you share the full command and parameters that you tried to pass that led to this failure?

alex-frankel avatar Apr 02 '24 23:04 alex-frankel

@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?

anthony-c-martin avatar Apr 16 '24 17:04 anthony-c-martin

The article has been updated - https://github.com/MicrosoftDocs/azure-docs-pr/pull/270808.

mumian avatar Apr 18 '24 20:04 mumian