Describe the bug
Several child extensions report the subject error in VS Code mainly on the name property passed to the resource when using a reference to the parent. Here is an example from the resourceGroups nested_roleAssignments.bicep where the 'resourceId' specified in the name property is generating the error. This is just one example.
resource roleAssignment 'Microsoft.Authorization/roleAssignments@2022-04-01' = [for principalId in principalIds: {
name: guid(last(split(resourceId, '/')), principalId, roleDefinitionIdOrName)
properties: {
description: description
roleDefinitionId: contains(builtInRoleNames, roleDefinitionIdOrName) ? builtInRoleNames[roleDefinitionIdOrName] : roleDefinitionIdOrName
principalId: principalId
principalType: !empty(principalType) ? any(principalType) : null
condition: !empty(condition) ? condition : null
conditionVersion: !empty(conditionVersion) && !empty(condition) ? conditionVersion : null
delegatedManagedIdentityResourceId: !empty(delegatedManagedIdentityResourceId) ? delegatedManagedIdentityResourceId : null
}
}]
I am not sure if this is a new linter test in the BICEP extension, but there are two possibilities to mitigate this error.
- Use the any() function to wrap the value of the referencing value (i.e., 'guid(any(last(split(resourceId, '/'))), principalId, roleDefinitionIdOrName)').
name: guid(any(last(split(resourceId, '/'))), principalId, roleDefinitionIdOrName)
- Use a non-null assertion postfix operator (!) just introduced in BICEP (but not documented as of now) that tells the linter that we will never have a null value for this passed variable.
name: guid(last(split(resourceId, '/'))!, principalId, roleDefinitionIdOrName)
For more information see: Azure\BICEP Github Issue #9565 and
Azure\BICEP Github Pull Request #9585.
To reproduce
Open modules\Microsoft.Resources\resourceGroups.bicep\nested_roleAssignments.bicep in Visual Studio Code and navigate to line 229. The error looks like this:

Note that this is not the only occurrence.
Code snippet
resource roleAssignment 'Microsoft.Authorization/roleAssignments@2022-04-01' = [for principalId in principalIds: {
name: guid(last(split(resourceId, '/')), principalId, roleDefinitionIdOrName)
properties: {
description: description
roleDefinitionId: contains(builtInRoleNames, roleDefinitionIdOrName) ? builtInRoleNames[roleDefinitionIdOrName] : roleDefinitionIdOrName
principalId: principalId
principalType: !empty(principalType) ? any(principalType) : null
condition: !empty(condition) ? condition : null
conditionVersion: !empty(conditionVersion) && !empty(condition) ? conditionVersion : null
delegatedManagedIdentityResourceId: !empty(delegatedManagedIdentityResourceId) ? delegatedManagedIdentityResourceId : null
}
}]
Relevant log output
No response
Describe the bug
Several child extensions report the subject error in VS Code mainly on the name property passed to the resource when using a reference to the parent. Here is an example from the resourceGroups nested_roleAssignments.bicep where the 'resourceId' specified in the name property is generating the error. This is just one example.
I am not sure if this is a new linter test in the BICEP extension, but there are two possibilities to mitigate this error.
For more information see: Azure\BICEP Github Issue #9565 and
Azure\BICEP Github Pull Request #9585.
To reproduce
Open modules\Microsoft.Resources\resourceGroups.bicep\nested_roleAssignments.bicep in Visual Studio Code and navigate to line 229. The error looks like this:
Note that this is not the only occurrence.
Code snippet
Relevant log output
No response