Azure / Azure/bicep

Consider shortcut syntax for nested object keys/properties

Open
#704 8 comments 1 reaction 0 assignees View on GitHub
enhancement Needs: Upvote
Dominant language
Bicep
Stars
3.6k
Forks
830
Avg merge
1d 2h
Merged PRs (30d)
79

Description

In the examples I have seen so far it appears that when the right-hand side of a property is an object with a single key assigned, it is necessary to introduce nested curly brace blocks. E.g.:

``` yaml
resource diagsAccount 'Microsoft.Storage/storageAcconunts@2019-06-01' = {
name: diagStorageAccountName
location: location
sku: {
name: 'Premium_LRS'
}
kind: 'Storage'
}
```

It seems at first glance this is a common scenario for which it would be worth optimizing for terseness. One idea that came up in a brief discussion with the Bicep team was to support dot on the left-hand side for chaining of nested properties. Using this feature, the example above becomes:

``` yaml
resource diagsAccount 'Microsoft.Storage/storageAcconunts@2019-06-01' = {
name: diagStorageAccountName
location: location
sku.name: 'Premium_LRS'
kind: 'Storage'
}
```

Another example from (a fragment taken from [docs/1vm-2nics-2subnets-1vnet/main.bicep](https://github.com/Azure/bicep/blob/main/docs/examples/101/1vm-2nics-2subnets-1vnet/main.bicep)) where this can have more impact:

``` yaml
resource nic1 'Microsoft.Network/networkInterfaces@2020-06-01' = {
name: nic1Name
location: location
properties: {
ipConfigurations: [
{
name: 'ipconfig1'
properties: {
subnet: {
id: '${vnet.id}/subnets/${subnet1Name}'
}
privateIPAllocationMethod: 'Dynamic'
publicIPAddress: {
id: pip.id
}
}
}
]
networkSecurityGroup: {
id: nsg.id
}
}
}
```

Becomes:

``` yaml
resource nic1 'Microsoft.Network/networkInterfaces@2020-06-01' = {
name: nic1Name
location: location
properties: {
ipConfigurations: [
{
name: 'ipconfig1'
properties: {
subnet.id: '${vnet.id}/subnets/${subnet1Name}'
privateIPAllocationMethod: 'Dynamic'
publicIPAddress.id: pip.id
}
}
]
networkSecurityGroup.id: nsg.id
}
}
```

cc @anthony-c-martin, @satyavel

Contributor guide

Open the contributing guide

Research direction

Start with the nested-property examples in docs/1vm-2nics-2subnets-1vnet/main.bicep and compare them with the proposed dotted-key syntax in this issue. Define the syntax and its behavior for nested objects and confirm that the examples can be expressed consistently before considering implementation and coverage.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure
Domain
compilers, infrastructure
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.