Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Standardize Bicep syntax - What's the difference between "", "=", and ":" ? #1183

Closed
ChristopherGLewis opened this issue Dec 17, 2020 · 4 comments
Labels
question Further information is requested

Comments

@ChristopherGLewis
Copy link
Contributor

Is your feature request related to a problem? Please describe.
I'm loving Bicep so far, but I'm having an issue understanding the syntax decisions of Bicep.

Specifically, I'm having issues figuring out when and why to use a space, an "=" or a ":".

For example, there are two types of parameters -

Simple

param myParam string = "Fred"

Param with meta

param myParam string {
  default: 'Fred'
  allowed: [
   'Fred' 
   'Sam'
  ]
}

The first example shows assigning a default parameter, the second shows meta info that assigns a default parameter, but using a different syntax.

Variables with objects show the same issue

var myval1 = 'fred'
var myval2 = {
  'fred' : 'Sam'
  derf : null
}
var myval3 = {
  'fred' : 'Sam'
  'derf' : null
}

Why would the internal assignment use a ":" vs a "="? Is this some sort of JSONish syntax?

the ARM json produced is this:

  "variables": {
    "myval1": "fred",
    "myval2": {
      "fred": "Sam",
      "derf": null
    },
    "myval3": {
      "fred": "Sam",
      "derf": null
    }
  },

Resources use an = sign, while the internal fields use :

resource nic 'Microsoft.Network/networkInterfaces@2020-06-01' = {
  name: nicName
  location: resourceGroup().location
  properties: {
    ipConfigurations: [
      {
        name: 'IPConfig1'
        properties: {
          privateIPAllocationMethod: 'Dynamic'

          primary: true
          subnet: {
            id: subnetID
          }
        }
      }
    ]
  }
}

Describe the solution you'd like
I'd like to see a more consistent usage of the = and : signs and possibly more JSON like syntax.

I would think Resources should not be required to use an "="

resource nic 'Microsoft.Network/networkInterfaces@2020-06-01'  {

to be consistent with parameters with meta info

param myParam string {

This would make the "=" be an ASSIGNMENT character and the space character be a meta info indicator

I could see using the ":" for both instances.

resource nic 'Microsoft.Network/networkInterfaces@2020-06-01' : {
param myParam string : {
@ChristopherGLewis ChristopherGLewis added the enhancement New feature or request label Dec 17, 2020
@ghost ghost added the Needs: Triage 🔍 label Dec 17, 2020
@ChristopherGLewis ChristopherGLewis changed the title Standardize Bicep syntax - What's the difference between "", "=", and ":" Standardize Bicep syntax - What's the difference between "", "=", and ":" ? Dec 17, 2020
@alex-frankel
Copy link
Collaborator

Coincidentally, we are taking feedback on #64 right now because of this confusion. So we are planning to get rid of the confusion around param that you cite.

On = vs : this is more of a personal taste thing. It felt weird to use anything but = for param default values and variable assignment. At that point we wanted to be consistent that = is the assignment character for every top level keyword (param, var, resource, module, output).

However, for objects (object type, resource body, module body), = feels weird as in most languages they will use : as a separator. So that's the history and it matches with other programming languages like TS/JS:

var myCar = {
    make: 'Ford',
    model: 'Mustang',
    year: 1969
}

Whether we were right or wrong is an open question :) Happy to take more feedback here.

@alex-frankel
Copy link
Collaborator

Chris - does this answer help clarify? Should I keep this open or can I close it?

@alex-frankel alex-frankel added question Further information is requested and removed Needs: Triage 🔍 enhancement New feature or request labels Dec 18, 2020
@alex-frankel
Copy link
Collaborator

Going to close this - let me know if there is any more context I can add

@ChristopherGLewis
Copy link
Contributor Author

Going to close this - let me know if there is any more context I can add

Thanks! all good!

@ghost ghost locked as resolved and limited conversation to collaborators May 28, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants