Closed kevball2 closed 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.
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
with version 0.21.1:
New-AzDeployment: Cannot retrieve the dynamic parameters for the cmdlet. Object reference not set to an instance of an object.
with version 0.22.6:
Unhandled exception. System.ArgumentException: Invalid type expression encountered. at Bicep.Core.Emit.TemplateWriter.TypePropertiesForTypeExpression(TypeExpression typeExpression) at Bicep.Core.Emit.TemplateWriter.<>c__DisplayClass27_0.<EmitParameter>b__0() at Bicep.Core.Emit.PositionTrackingJsonTextWriter.WriteObjectWithPosition(IPositionable sourcePosition, Action propertiesFunc) at Bicep.Core.Emit.ExpressionEmitter.EmitObject(Action writePropertiesFunc, IPositionable position) at Bicep.Core.Emit.ExpressionEmitter.<>c__DisplayClass32_0.<EmitObjectProperty>b__0() at Bicep.Core.Emit.PositionTrackingJsonTextWriter.WritePropertyWithPosition(IPositionable keyPosition, String name, Action valueFunc) at Bicep.Core.Emit.ExpressionEmitter.EmitProperty(String propertyName, Action writeValueFunc, IPositionable position) at Bicep.Core.Emit.ExpressionEmitter.EmitObjectProperty(String propertyName, Action writePropertiesFunc, IPositionable position) at Bicep.Core.Emit.TemplateWriter.EmitParameter(ExpressionEmitter emitter, DeclaredParameterExpression parameter) at Bicep.Core.Emit.TemplateWriter.<>c__DisplayClass23_0.<EmitParametersIfPresent>b__0() at Bicep.Core.Emit.PositionTrackingJsonTextWriter.WriteObjectWithPosition(IPositionable sourcePosition, Action propertiesFunc) at Bicep.Core.Emit.ExpressionEmitter.EmitObject(Action writePropertiesFunc, IPositionable position) at Bicep.Core.Emit.ExpressionEmitter.<>c__DisplayClass32_0.<EmitObjectProperty>b__0() at Bicep.Core.Emit.PositionTrackingJsonTextWriter.WritePropertyWithPosition(IPositionable keyPosition, String name, Action valueFunc) at Bicep.Core.Emit.ExpressionEmitter.EmitProperty(String propertyName, Action writeValueFunc, IPositionable position) at Bicep.Core.Emit.ExpressionEmitter.EmitObjectProperty(String propertyName, Action writePropertiesFunc, IPositionable position) at Bicep.Core.Emit.TemplateWriter.EmitParametersIfPresent(ExpressionEmitter emitter, ImmutableArray
1 parameters)
at Bicep.Core.Emit.TemplateWriter.GenerateTemplateWithoutHash(PositionTrackingJsonTextWriter jsonWriter)
at Bicep.Core.Emit.TemplateWriter.Write(SourceAwareJsonTextWriter writer)
at Bicep.Core.Emit.TemplateEmitter.<>c__DisplayClass10_0.1 write) at Bicep.Core.Emit.TemplateEmitter.Emit(TextWriter textWriter) at Bicep.Core.Emit.TemplateEmitter.Emit(Stream stream) at Bicep.Cli.Services.CompilationWriter.ToStream(SemanticModel model, Stream stream) at Bicep.Cli.Services.CompilationWriter.ToFile(SemanticModel model, String outputPath) at Bicep.Cli.Services.CompilationWriter.ToFile(Compilation compilation, String outputPath) at Bicep.Cli.Commands.BuildCommand.RunAsync(BuildArguments args) at Bicep.Cli.Program.RunAsync(String[] args) at Bicep.Cli.Program.Main(String[] args) at Bicep.Cli.Program.<Main>(String[] args)
I'm getting a "A parameter cannot be found that matches parameter name" exception for optional parameters.
Some observations
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.
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'.
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
.
Closed as it is fixed in the Powershell release. Please reopen if the same issue persists after the newest powershell release.
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.
@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!
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.