Azure / bicep

Bicep is a declarative language for describing and deploying Azure resources
MIT License
3.26k stars 753 forks source link

New-AzDeployment: Cannot retrieve the dynamic parameters for the cmdlet #12112

Closed kevball2 closed 1 year ago

kevball2 commented 1 year ago

Bicep version Bicep CLI version 0.22.6 (d62b94db31)

Describe the bug When attempting to use a dynamic variable with New-AzDeployment I received the following error 'New-AzDeployment: Cannot retrieve the dynamic parameters for the cmdlet. Error parsing boolean value. Path '', line 1, position 1.'

Az modules - 10.3.0

To Reproduce Steps to reproduce the behavior: Templates repro.zip

command - New-AzDeployment -location usgovvirginia -whatif -TemplateFile .\repro.bicep -TemplateParameterFile .\repro.bicep -region 'ugv' -name what-if_tagtest_dev_ugv

Additional context I was testing user defined types and ran into the same issue in out pipeline where dynamic variables were not working properly when you added a user defined type. Reproduced on my machine and confirmed. Updated to the latest version of Bicep and tested again but now I get the error in both scenarios.

kevball2 commented 1 year ago

Updates:

Removed all versions of Az modules, found the module causing issues was the Az.Resources module. Working module versions

Get-Module -Name Az, Az.Resources -ListAvailable | select Name, Version
Name         Version
----         -------
Az           10.3.0
Az.Resources 6.10.0

Bicep Version 0.22.6

I am able to deploy templates with User Defined Types if no dynamic variables are used. If I remove the Types, the dynamic functionality works again successfully.

I successfully tested using the ReadEnvironmentVariables() function as an alternative to passing the dynamic variables at the command line.

cedricbraekevelt commented 1 year ago

I have the same issue, I have the same versions of Powershell modules and I've tried both the latest and previous Bicep release. I have a main file which references a types file. My main file has a bicepparam file attached and requires some user defined type parameters, this gives me

marsontret commented 1 year ago

I'm getting a "A parameter cannot be found that matches parameter name" exception for optional parameters.

anthony-c-martin commented 1 year ago

Some observations

Repro 1

main.bicep:

type requiredTags = {
  foo: bool
}

//@description('Required. Tags that are should be deployed for all subscriptions')
param tags requiredTags

main.bicepparam

using 'main.bicep'

param tags = {
  foo: true
}

Result:

New-AzResourceGroupDeployment -ResourceGroupName ant-test -TemplateParameterFile /Users/ant/Desktop/issue12112/main.bicepparam 
WARNING: /Users/ant/Desktop/issue12112/main.bicep(6,7) : Warning no-unused-params: Parameter "tags" is declared but never used. [https://aka.ms/bicep/linter/no-unused-params]

New-AzResourceGroupDeployment: Cannot retrieve the dynamic parameters for the cmdlet. Object reference not set to an instance of an object.

Repro 2

main.bicep:

type requiredTags = {
  foo: bool
}

@description('Required. Tags that are should be deployed for all subscriptions')
param tags requiredTags

main.bicepparam

using 'main.bicep'

param tags = {
  foo: true
}

Result:

New-AzResourceGroupDeployment -ResourceGroupName ant-test -TemplateParameterFile /Users/ant/Desktop/issue12112/main.bicepparam
WARNING: /Users/ant/Desktop/issue12112/main.bicep(6,7) : Warning no-unused-params: Parameter "tags" is declared but never used. [https://aka.ms/bicep/linter/no-unused-params]

WARNING: /Users/ant/Desktop/issue12112/main.bicep(6,7) : Warning no-unused-params: Parameter "tags" is declared but never used. [https://aka.ms/bicep/linter/no-unused-params]

WARNING: /Users/ant/Desktop/issue12112/main.bicep(6,7) : Warning no-unused-params: Parameter "tags" is declared but never used. [https://aka.ms/bicep/linter/no-unused-params]

WARNING: /Users/ant/Desktop/issue12112/main.bicep(6,7) : Warning no-unused-params: Parameter "tags" is declared but never used. [https://aka.ms/bicep/linter/no-unused-params]

New-AzResourceGroupDeployment: Additional content found in JSON reference object. A JSON reference object should only have a $ref property. Path 'tags.metadata'.

Hypothesis

The JSON parser that AzPwsh is using is attempting to follow $ref statements and present a normalized view of the JSON, rather than treating them as properties named $ref.

stephaniezyen commented 1 year ago

Closed as it is fixed in the Powershell release. Please reopen if the same issue persists after the newest powershell release.

rbnmk commented 1 year ago

I seem to still run into this issue introducing User Defined Types to my Bicep template using New-AzResourceGroupDeployment.

Command: New-AzResourceGroupDeployment -ResourceGroupName validation-rg -TemplateFile deploy.bicep -TemplateParameterFile parameters.json -Tags @{ RemoveModule = "ModuleName" }

Error: New-AzResourceGroupDeployment: A parameter cannot be found that matches parameter name 'Tags'.

Versions: Bicep CLI version 0.22.6 (d62b94db31) Az: 10.4.1 Az.Resources: 6.11.2

When I use Azure CLI, basically the same command it runs succesfully: az deployment group create -g validation-rg --template-file deploy.json --parameters @parameters.json tags='{\"RemoveModule\":\"ModuleName\"}'

Unfortunately my whole template ci/cd process is based on Azure PowerShell, so would be helpful if this can be resolved. I usually run this via AzurePowerShell@5 (latestVersion) but I tried to pin the versions mentioned in this issue as well, without luck.

If any other logs are needed, please let me know.

stephaniezyen commented 1 year ago

@rbnmk Sorry, should have clarified: It should be available during the NEXT powershell release, which is stated to be around 11/17. I would wait until then to try again, and to keep an eye on when the next version is released from their github page: https://github.com/PowerShell/PowerShell/releases

Thank you!