Skip to content

Commit 8d4ba96

Browse files
authored
Merge pull request #231025 from mumian/0316-linter-null
add new linter rule: simplify json null
2 parents 0dcdfeb + c29b51d commit 8d4ba96

File tree

6 files changed

+138
-4
lines changed

6 files changed

+138
-4
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: 01/30/2023
5+
ms.date: 03/16/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+
"simplify-json-null": {
93+
"level": "warning"
94+
}
9295
"use-parent-property": {
9396
"level": "warning"
9497
},
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
---
2+
title: Linter rule - simplify JSON null
3+
description: Linter rule - simplify JSON null
4+
ms.topic: conceptual
5+
ms.date: 03/20/2023
6+
---
7+
8+
# Linter rule - simplify JSON null
9+
10+
This rule finds `json('null')`.
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+
`simplify-json-null`
17+
18+
## Solution
19+
20+
The following example fails this test because `json('null')` is used:
21+
22+
```bicep
23+
@description('The name of the API Management service instance')
24+
param apiManagementServiceName string = 'apiservice${uniqueString(resourceGroup().id)}'
25+
26+
@description('The email address of the owner of the service')
27+
@minLength(1)
28+
param publisherEmail string
29+
30+
@description('The name of the owner of the service')
31+
@minLength(1)
32+
param publisherName string
33+
34+
@description('The pricing tier of this API Management service')
35+
@allowed([
36+
'Premium'
37+
])
38+
param sku string = 'Premium'
39+
40+
@description('The instance size of this API Management service.')
41+
param skuCount int = 3
42+
43+
@description('Location for all resources.')
44+
param location string = resourceGroup().location
45+
46+
@description('Zone numbers e.g. 1,2,3.')
47+
param availabilityZones array = [
48+
'1'
49+
'2'
50+
'3'
51+
]
52+
53+
resource apiManagementService 'Microsoft.ApiManagement/service@2022-08-01' = {
54+
name: apiManagementServiceName
55+
location: location
56+
zones: ((length(availabilityZones) == 0) ? json('null') : availabilityZones)
57+
sku: {
58+
name: sku
59+
capacity: skuCount
60+
}
61+
identity: {
62+
type: 'SystemAssigned'
63+
}
64+
properties: {
65+
publisherEmail: publisherEmail
66+
publisherName: publisherName
67+
}
68+
}
69+
```
70+
71+
You can simplify the syntax by replacing `json('null')` by `null`:
72+
73+
```bicep
74+
@description('The name of the API Management service instance')
75+
param apiManagementServiceName string = 'apiservice${uniqueString(resourceGroup().id)}'
76+
77+
@description('The email address of the owner of the service')
78+
@minLength(1)
79+
param publisherEmail string
80+
81+
@description('The name of the owner of the service')
82+
@minLength(1)
83+
param publisherName string
84+
85+
@description('The pricing tier of this API Management service')
86+
@allowed([
87+
'Premium'
88+
])
89+
param sku string = 'Premium'
90+
91+
@description('The instance size of this API Management service.')
92+
param skuCount int = 3
93+
94+
@description('Location for all resources.')
95+
param location string = resourceGroup().location
96+
97+
@description('Zone numbers e.g. 1,2,3.')
98+
param availabilityZones array = [
99+
'1'
100+
'2'
101+
'3'
102+
]
103+
104+
resource apiManagementService 'Microsoft.ApiManagement/service@2022-08-01' = {
105+
name: apiManagementServiceName
106+
location: location
107+
zones: ((length(availabilityZones) == 0) ? null : availabilityZones)
108+
sku: {
109+
name: sku
110+
capacity: skuCount
111+
}
112+
identity: {
113+
type: 'SystemAssigned'
114+
}
115+
properties: {
116+
publisherEmail: publisherEmail
117+
publisherName: publisherName
118+
}
119+
}
120+
```
121+
122+
You can simplify the syntax by selecting **Quick Fix** as shown on the following screenshot:
123+
124+
:::image type="content" source="./media/linter-rule-simplify-json-null/bicep-linter-rule-simplify-json-null-quick-fix.png" alt-text="Screenshot of simplify JSON null quick fix.":::
125+
126+
## Next steps
127+
128+
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: 01/30/2023
5+
ms.date: 03/16/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+
- [simplify-json-null](./linter-rule-simplify-json-null.md)
4243
- [use-parent-property](./linter-rule-use-parent-property.md)
4344
- [use-protectedsettings-for-commandtoexecute-secrets](./linter-rule-use-protectedsettings-for-commandtoexecute-secrets.md)
4445
- [use-recent-api-versions](./linter-rule-use-recent-api-versions.md)
Loading

articles/azure-resource-manager/bicep/toc.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,9 @@
464464
- name: Simplify interpolation
465465
displayName: linter
466466
href: linter-rule-simplify-interpolation.md
467+
- name: Simplify JSON null
468+
displayName: linter
469+
href: linter-rule-simplify-json-null.md
467470
- name: Use explicit values for module location parameters
468471
displayName: linter
469472
href: linter-rule-explicit-values-for-loc-params.md

articles/azure-resource-manager/templates/key-vault-parameter.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@ description: Shows how to pass a secret from a key vault as a parameter during d
44
ms.topic: conceptual
55
ms.date: 06/18/2021
66
ms.custom: devx-track-azurepowershell, devx-track-azurecli
7-
87
---
98

109
# Use Azure Key Vault to pass secure parameter value during deployment
1110

1211
Instead of putting a secure value (like a password) directly in your template or parameter file, you can retrieve the value from an [Azure Key Vault](../../key-vault/general/overview.md) during a deployment. You retrieve the value by referencing the key vault and secret in your parameter file. The value is never exposed because you only reference its key vault ID.
1312

1413
> [!IMPORTANT]
15-
> This article focuses on how to pass a sensitive value as a template parameter. When the secret is passed as a parameter, the key vault can exist in a different subscription than the resource group you're deploying to.
14+
> This article focuses on how to pass a sensitive value as a template parameter. When the secret is passed as a parameter, the key vault can exist in a different subscription than the resource group you're deploying to.
1615
>
1716
> This article doesn't cover how to set a virtual machine property to a certificate's URL in a key vault. For a quickstart template of that scenario, see [Install a certificate from Azure Key Vault on a Virtual Machine](https://github.com/Azure/azure-quickstart-templates/tree/master/demos/vm-winrm-keyvault-windows).
1817

0 commit comments

Comments
 (0)