Improve error message when the child resource (subnet) is unqualified
- Dominant language
- Bicep
- Stars
- 3.6k
- Forks
- 830
- Avg merge
- 1d 21m
- Merged PRs (30d)
- 79
Description
Example:
```
param subnetName string
resource existingSubnet 'Microsoft.Network/virtualNetworks/subnets@2021-02-01' existing = {
name: subnetName
}
var subnetID = existingSubnet.id
```
If the subnetName is not qualified (does not contain "/"), the following error is shown:
`{"code": "InvalidTemplate", "message": "Deployment template validation failed: 'The template variable 'subnetID' is not valid: The language expression property array index '1' is out of bounds.. Please see https://aka.ms/arm-functions for usage details.'.", "additionalInfo": [{"type": "TemplateViolation", "info": {"lineNumber": 17, "linePosition": 157, "path": "properties.template.variables.subnetID"}}]}`
This is an error because we have no way of knowing what the parent resource is (in this case the vnet). But the error should be improved so this can be self-serviceable.
The user should be guided to represent the parent resource in the bicep file when declaring the existingSubnet. As seen below:
```
param vnetName string
param subnetName string
resource existingVnet 'Microsoft.Network/virtualNetworks@2021-02-01' existing = {
name: vnetName
}
resource existingSubnet 'Microsoft.Network/virtualNetworks/subnets@2021-02-01' existing = {
parent: existingVnet
name: subnetName
}
var subnetID = existingSubnet.id
```
Contributor guide
Research direction
Start by reproducing the unqualified existing subnet example and compare it with the version that declares an existing virtual network parent. Trace the entry point that produces the invalid array-index error for the subnet ID. Done means the diagnostic explains that the parent resource must be represented when the subnet name is unqualified.
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
- 45/100