title | description | ms.topic | ms.custom | ms.date |
---|---|---|---|---|
Linter rule - use parent property |
Linter rule - use parent property |
reference |
devx-track-bicep |
03/20/2024 |
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.
Use the following value in the Bicep configuration file to customize rule settings:
use-parent-property
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:
:::image type="content" source="./media/linter-rule-use-parent-property/bicep-linter-rule-use-parent-property-quick-fix.png" alt-text="Screenshot of use parent property quick fix.":::
For more information about the linter, see Use Bicep linter.