Azure / Azure/bicep

Linter Rule to convert resourceId to `existing` syntax

Open
#3,019 1 comment 2 reactions 0 assignees View on GitHub
devdiv enhancement P1 story: linter rules
Dominant language
Bicep
Stars
3.6k
Forks
830
Avg merge
1d 21m
Merged PRs (30d)
79

Description

**Is your feature request related to a problem? Please describe.**

Existing resources are an awesome part of bicep that are easy to look over. Could a linter rule detect hard coded resource ids, and offer to convert them to use the existing syntax?

**Describe the solution you'd like**

Suggest changing the following:

```bicep
var resourceId = '/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rgName/providers/Microsoft.Storage/storageAccounts/accountName'
```

to

```bicep
resource resource 'Microsoft.Storage/storageAccounts@2021-04-01' existing = {
name: 'accountName'
scope: resourceGroup('00000000-0000-0000-0000-000000000000', 'rgName')
}
```
and change all other references to `resourceId` to `resource.id`

Contributor guide

Open the contributing guide

Research direction

Start by locating the linter-rule entry point and the handling of hard-coded resource IDs in the Bicep compiler or analyzer. Define how the rule should recognize IDs, infer the existing resource declaration and scope, and update references to resource.id. Done means the example is transformed correctly and equivalent cases are covered by tests.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.