Skip to content

Commit b762c17

Browse files
committed
New linter rule - use parent-property
1 parent f635b66 commit b762c17

File tree

4 files changed

+86
-5
lines changed

4 files changed

+86
-5
lines changed

articles/azure-resource-manager/bicep/bicep-config-linter.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: Linter settings for Bicep config
33
description: Describes how to customize configuration values for the Bicep linter
44
ms.topic: conceptual
5-
ms.date: 11/01/2022
5+
ms.date: 01/30/2023
66
---
77

88
# Add linter settings in the Bicep config file
@@ -89,6 +89,9 @@ The following example shows the rules that are available for configuration.
8989
"simplify-interpolation": {
9090
"level": "warning"
9191
},
92+
"use-parent-property": {
93+
"level": "warning"
94+
},
9295
"use-protectedsettings-for-commandtoexecute-secrets": {
9396
"level": "warning"
9497
},

articles/azure-resource-manager/bicep/child-resource-name-type.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ If you would rather learn about about child resources through step-by-step guida
2121

2222
## Name and type pattern
2323

24-
In Bicep, you can specify the child resource either within the parent resource or outside of the parent resource. The values you provide for the resource name and resource type vary based on how you declare the child resource. However, the full name and type always resolve to the same pattern.
24+
In Bicep, you can specify the child resource either within the parent resource or outside of the parent resource. The values you provide for the resource name and resource type vary based on how you declare the child resource. However, the full name and type always resolve to the same pattern.
2525

2626
The **full name** of the child resource uses the pattern:
2727

@@ -47,7 +47,7 @@ If you have more than two levels in the hierarchy, keep repeating parent resourc
4747
{resource-provider-namespace}/{parent-resource-type}/{child-level1-resource-type}/{child-level2-resource-type}
4848
```
4949

50-
If you count the segments between `/` characters, the number of segments in the type is always one more than the number of segments in the name.
50+
If you count the segments between `/` characters, the number of segments in the type is always one more than the number of segments in the name.
5151

5252
## Within parent resource
5353

@@ -113,7 +113,7 @@ You can also use the full resource name and type when declaring the child resour
113113
:::code language="bicep" source="~/azure-docs-bicep-samples/syntax-samples/child-resource-name-type/fullnamedeclaration.bicep" highlight="10,11,17,18":::
114114

115115
> [!IMPORTANT]
116-
> Setting the full resource name and type isn't the recommended approach. It's not as type safe as using one of the other approaches.
116+
> Setting the full resource name and type isn't the recommended approach. It's not as type safe as using one of the other approaches. For more information, see [Linter rule: use parent property](./linter-rule-use-parent-property.md).
117117
118118
## Next steps
119119

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
---
2+
title: Linter rule - use parent property
3+
description: Linter rule - use parent property
4+
ms.topic: conceptual
5+
ms.date: 01/30/2023
6+
---
7+
8+
# Linter rule - use parent property
9+
10+
When defined outside of the parent resource, you format name of the child resource with slashes to include the parent name. Setting the full resource name isn't the recommended approach. The syntax can be simplified by using the parent property. For more information, see [Full resource name outside parent](./child-resource-name-type.md#full-resource-name-outside-parent).
11+
12+
## Linter rule code
13+
14+
Use the following value in the [Bicep configuration file](bicep-config-linter.md) to customize rule settings:
15+
16+
`use-parent-property`
17+
18+
## Solution
19+
20+
The following example fails this test because of the name values for `service` and `share`:
21+
22+
```bicep
23+
param location string = resourceGroup().location
24+
25+
resource storage 'Microsoft.Storage/storageAccounts@2021-02-01' = {
26+
name: 'examplestorage'
27+
location: location
28+
kind: 'StorageV2'
29+
sku: {
30+
name: 'Standard_LRS'
31+
}
32+
}
33+
34+
resource service 'Microsoft.Storage/storageAccounts/fileServices@2021-02-01' = {
35+
name: 'examplestorage/default'
36+
dependsOn: [
37+
storage
38+
]
39+
}
40+
41+
resource share 'Microsoft.Storage/storageAccounts/fileServices/shares@2021-02-01' = {
42+
name: 'examplestorage/default/exampleshare'
43+
dependsOn: [
44+
service
45+
]
46+
}
47+
```
48+
49+
You can fix the problem by using the parent property:
50+
51+
```bicep
52+
param location string = resourceGroup().location
53+
54+
resource storage 'Microsoft.Storage/storageAccounts@2021-02-01' = {
55+
name: 'examplestorage'
56+
location: location
57+
kind: 'StorageV2'
58+
sku: {
59+
name: 'Standard_LRS'
60+
}
61+
}
62+
63+
resource service 'Microsoft.Storage/storageAccounts/fileServices@2021-02-01' = {
64+
parent: storage
65+
name: 'default'
66+
}
67+
68+
resource share 'Microsoft.Storage/storageAccounts/fileServices/shares@2021-02-01' = {
69+
parent: service
70+
name: 'exampleshare'
71+
}
72+
73+
```
74+
75+
## Next steps
76+
77+
For more information about the linter, see [Use Bicep linter](./linter.md).

articles/azure-resource-manager/bicep/linter.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: Use Bicep linter
33
description: Learn how to use Bicep linter.
44
ms.topic: conceptual
5-
ms.date: 11/01/2022
5+
ms.date: 01/30/2023
66
---
77

88
# Use Bicep linter
@@ -39,6 +39,7 @@ The default set of linter rules is minimal and taken from [arm-ttk test cases](.
3939
- [secure-params-in-nested-deploy](./linter-rule-secure-params-in-nested-deploy.md)
4040
- [secure-secrets-in-params](./linter-rule-secure-secrets-in-parameters.md)
4141
- [simplify-interpolation](./linter-rule-simplify-interpolation.md)
42+
- [use-parent-property](./linter-rule-use-parent-property.md)
4243
- [use-protectedsettings-for-commandtoexecute-secrets](./linter-rule-use-protectedsettings-for-commandtoexecute-secrets.md)
4344
- [use-recent-api-versions](./linter-rule-use-recent-api-versions.md)
4445
- [use-resource-id-functions](./linter-rule-use-resource-id-functions.md)

0 commit comments

Comments
 (0)