Azure / bicep

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

Bicep does not accept leading numbers in identifiers, parameter and variable names. #1494

Closed StefanIvemo closed 3 years ago

StefanIvemo commented 3 years ago

Bicep version Bicep CLI version 0.2.328 (a13b032755)

Describe the bug ARM Templates support leading numbers in parameter and variable names for example:

  "parameters": {
    "1nsgname": {
      "type": "string"
    }
  },
  "variables": {
    "2vnsgname": "nsgname"
  },

If try to do the same with Bicep it's not allowed.

To Reproduce

If my template looks like this:

param location string
param 1nsgname string

resource nsg  'Microsoft.Network/networkSecurityGroups@2020-06-01' = {
  name: 1nsgname
  location: location   
}

output id string = nsg.id

VS Code extension shows the following error: image

And bicep build throws this error:

nsg.bicep(7,7) : Error BCP013: Expected a parameter identifier at this location.
nsg.bicep(7,8) : Error BCP031: The parameter type is not valid. Please specify one of the following types: "array", "bool", "int", "object", "string".
nsg.bicep(7,16) : Error BCP008: Expected the "=" token, a parameter modifier, or a newline at this location.
nsg.bicep(10,10) : Error BCP019: Expected a new line character at this location.

If I declare a variable:

var 1hello ='hello'

VS Code Extension and Bicep Build generates the same error: image

Error BCP015: Expected a variable identifier at this location.

And I get the same error if I try to do name my resource or module identifier with a leading number in the identifier name.

image

Additional context Add any other context about the problem here.

alex-frankel commented 3 years ago

This is currently intentionally unsupported and is unlikely to change. This is similar to global symbol names in that it is more restrictive than what is possible in ARM Templates. Can you provide a bit more detail on why you need identifiers with leading integers? There could certainly be a scenario we have not though through.

FWIW, this is not something that is possible in most high level programming languages like TS, C# or Go

StefanIvemo commented 3 years ago

It's not something I intend to use. Just stumbled upon it yesterday and noticed the difference and got curious since it is working in ARM Templates. And I couldn't find any info in the docs either. Maybe the error description could be updated? Anyway you can close this, I'm happy with your explanation.

StefanIvemo commented 3 years ago

@alex-frankel forgot to mention in the issue that if I run bicep decompile on an ARM Template with leading numbers in the parameter or variable name it will generate an error and the converted .bicep file will not work. Maybe if a parameter or variable in an ARM Template has leading numbers in the names it should be changed during decompilation?

alex-frankel commented 3 years ago

Sounds good - I will close this one and open a separate one for the decompiler error