False positive for 'use-resource-id-functions' linter rule when param used in for loop
- Dominant language
- Bicep
- Stars
- 3.6k
- Forks
- 830
- Avg merge
- 1d 21m
- Merged PRs (30d)
- 79
Description
**Bicep version**
bicep --version
Bicep CLI version 0.27.1 (4b41cb6d4b)
**Describe the bug**
Similar false positive to https://github.com/Azure/bicep/issues/12419
```Bicep
param vmName string
@description('Array of DCR IDs')
param dcrIDs string[]
//Direct association to avoid scoping changes
resource dcr 'Microsoft.Insights/dataCollectionRuleAssociations@2023-03-11' = [for (id, index) in dcrIDs: {
name: 'DCRassociation-${vmName}-${index}'
scope: VM
properties: {
dataCollectionRuleId: id
description: 'DCRassociation-${vmName}-${index}'
}
}]
```
```Powershell
bicep build .\test.bicep
C:\VSProjects\DevOps\AzureReadyFoundation\BicepModules\VirtualMachine\windowsvm.bicep(249,8) : Warning use-resource-id-functions: If property "dataCollectionRuleId" represents a resource ID, it must use a symbolic resource reference, be a parameter or start with one of these functions: extensionResourceId, guid, if, managementGroupResourceId, reference, resourceId, subscription, subscriptionResourceId, tenantResourceId. [https://aka.ms/bicep/linter/use-resource-id-functions]
```
**To Reproduce**
Steps to reproduce the behavior:
code as above, bicep build
**additional Notes**
Removing the for loop and using a single dcrID string parameter eliminates the linting warning.
Contributor guide
Research direction
Start with the use-resource-id-functions linter rule and reproduce the warning using the Bicep snippet from the issue and `bicep build`. Compare the loop-based parameter case with the single-string parameter case; done means the valid `id` value no longer produces a false-positive warning.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- azure
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100