Azure / Azure/bicep

Bicep visualizer points to parent resource instead of to child resource

Open
#6,650 2 comments 0 reactions 0 assignees View on GitHub
bug story: visualizer
Dominant language
Bicep
Stars
3.6k
Forks
830
Avg merge
1d 21m
Merged PRs (30d)
79

Description

**Bicep version**
Bicep CLI version 0.5.6 (5f2f88f0f0)

**Describe the bug**
In network interface using subnet reference as child resource (`id: virtualNetwork::defaultSubnet.id`) visualizer points to vnet:
![image](https://user-images.githubusercontent.com/24376947/165157551-e703d3c3-6b32-4087-aa32-d82b12e73520.png)
instead of points to the subnet as it is when using reference as a separate resource (`id: defaultSubnet`):
![image](https://user-images.githubusercontent.com/24376947/165157591-0ae4d9a0-9893-4bcf-a7aa-b573df77c556.png)

**To Reproduce**
Use below bicep template (it's piece of code from this [Learn module](https://docs.microsoft.com/en-us/learn/modules/migrate-azure-resources-bicep/5-exercise-refactor-bicep-file)):

main.bicep

```bicep
@description('The location into which the resources should be deployed.')
param location string = resourceGroup().location

@description('The virtual network address range.')
param virtualNetworkAddressPrefix string

@description('The default subnet address range within the virtual network')
param virtualNetworkDefaultSubnetAddressPrefix string

var virtualNetworkName = 'ToyTruck-vnet'
var virtualNetworkDefaultSubnetName = 'default'
var networkInterfaceName = 'toytruckserver237'

resource virtualNetwork 'Microsoft.Network/virtualNetworks@2020-11-01' = {
name: virtualNetworkName
location: location
properties: {
addressSpace: {
addressPrefixes: [
virtualNetworkAddressPrefix
]
}
subnets: [
{
name: virtualNetworkDefaultSubnetName
properties: {
addressPrefix: virtualNetworkDefaultSubnetAddressPrefix
privateEndpointNetworkPolicies: 'Enabled'
privateLinkServiceNetworkPolicies: 'Enabled'
}
}
]
enableDdosProtection: false
}

resource defaultSubnet 'subnets' existing = {
name: virtualNetworkDefaultSubnetName
}
}

resource networkInterface 'Microsoft.Network/networkInterfaces@2020-07-01' = {
name: networkInterfaceName
location: location
properties: {
ipConfigurations: [
{
name: 'ipconfig1'
properties: {
privateIPAllocationMethod: 'Dynamic'
subnet: {
id: virtualNetwork::defaultSubnet.id
// id: defaultSubnet
}
primary: true
privateIPAddressVersion: 'IPv4'
}
}
]
enableIPForwarding: false
}
}

resource defaultSubnet 'Microsoft.Network/virtualNetworks/subnets@2020-11-01' = {
parent: virtualNetwork
name: 'default'
properties: {
addressPrefix: '10.0.0.0/24'
delegations: []
privateEndpointNetworkPolicies: 'Enabled'
privateLinkServiceNetworkPolicies: 'Enabled'
}
}

```

Contributor guide

Open the contributing guide

Research direction

Start with the main.bicep reproduction and compare the visualizer output for the virtualNetwork::defaultSubnet.id reference with the separate defaultSubnet reference. Trace how the visualizer resolves the child-resource reference; done when the first form points to the subnet rather than its parent virtual network.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure
Domain
cloud, devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.