Linter rule - use parent property
When defined outside of the parent resource, you use slashes to include the parent name in the name of the child resource. Setting the full resource name with parent resource name is not recommended. The parent
property can be used to simplify the syntax. See Full resource name outside parent.
Linter rule code
Use the following value in the Bicep configuration file to customize rule settings:
use-parent-property
Solution
The following example fails this test because of the name values for service
and share
:
param location string = resourceGroup().location
resource storage 'Microsoft.Storage/storageAccounts@2021-02-01' = {
name: 'examplestorage'
location: location
kind: 'StorageV2'
sku: {
name: 'Standard_LRS'
}
}
resource service 'Microsoft.Storage/storageAccounts/fileServices@2021-02-01' = {
name: 'examplestorage/default'
dependsOn: [
storage
]
}
resource share 'Microsoft.Storage/storageAccounts/fileServices/shares@2021-02-01' = {
name: 'examplestorage/default/exampleshare'
dependsOn: [
service
]
}
You can fix the problem by using the parent
property:
param location string = resourceGroup().location
resource storage 'Microsoft.Storage/storageAccounts@2021-02-01' = {
name: 'examplestorage'
location: location
kind: 'StorageV2'
sku: {
name: 'Standard_LRS'
}
}
resource service 'Microsoft.Storage/storageAccounts/fileServices@2021-02-01' = {
parent: storage
name: 'default'
}
resource share 'Microsoft.Storage/storageAccounts/fileServices/shares@2021-02-01' = {
parent: service
name: 'exampleshare'
}
You can fix the issue automatically by selecting Quick Fix as shown on the following screenshot:
Next steps
For more information about the linter, see Use Bicep linter.