Azure / Azure/bicep

Linter rule to detect referencing of child resources using `resourceId()` function

Open
#12,033 0 comments 1 reaction 0 assignees View on GitHub
enhancement good first issue story: linter rules
Dominant language
Bicep
Stars
3.6k
Forks
830
Avg merge
1d 21m
Merged PRs (30d)
79

Description

This seems to be a common pattern in decompiled quickstart templates:
```bicep
param vnetName string
param subnetName string
param nicName string

resource vnet 'Microsoft.Network/virtualNetworks@2023-05-01' = {
name: vnetName
properties: {
subnets: [
{
name: subnetName
}
]
}
}

resource nic 'Microsoft.Network/networkInterfaces@2023-05-01' = {
name: nicName
properties: {
ipConfigurations: [
{
name: 'ipconfig1'
properties: {
subnet: {
id: resourceId('Microsoft.Network/virtualNetworks/subnets', vnetName, subnetName)
}
}
}
]
}
dependsOn: [
vnet
]
}
```

We should instead be encouraging the following by providing a linter warning + code fix:
```bicep
param vnetName string
param subnetName string
param nicName string

resource vnet 'Microsoft.Network/virtualNetworks@2023-05-01' = {
name: vnetName
properties: {
subnets: [
{
name: subnetName
}
]
}
}

resource subnet 'Microsoft.Network/virtualNetworks/subnets@2023-05-01' existing = {
parent: vnet
name: subnetName
}

resource nic 'Microsoft.Network/networkInterfaces@2023-05-01' = {
name: nicName
properties: {
ipConfigurations: [
{
name: 'ipconfig1'
properties: {
subnet: {
id: subnet.id
}
}
}
]
}
}
```

Contributor guide

Open the contributing guide

Research direction

Start by reviewing the resourceId() and existing-resource examples in the issue, then compare them with existing linter rules and code-fix patterns in the Bicep repository. Done means a warning detects child-resource references made with resourceId() and the code fix produces an equivalent existing child resource reference without requiring additional dependencies.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.