Skip to content

Commit bb19e14

Browse files
authored
Merge pull request #176068 from tfitzmac/1015adminname
add admin username linter rule
2 parents 2e2765c + d52ba15 commit bb19e14

9 files changed

+78
-55
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
---
2+
title: Linter rule - admin user name should not be literal
3+
description: Linter rule - admin user name should not be a literal
4+
ms.topic: conceptual
5+
ms.date: 10/15/2021
6+
---
7+
8+
# Linter rule - admin user name should not be literal
9+
10+
This rule finds when an admin user name is set to a literal value.
11+
12+
## Returned code
13+
14+
`adminusername-should-not-be-literal`
15+
16+
## Solution
17+
18+
Don't use a literal value or an expression that evaluates to a literal value. Instead, create a parameter for the user name and assign it to the admin user name.
19+
20+
The following example fails this test because the user name is a literal value.
21+
22+
```bicep
23+
resource vm 'Microsoft.Compute/virtualMachines@2020-12-01' = {
24+
name: 'name'
25+
location: location
26+
properties: {
27+
osProfile: {
28+
adminUsername: 'adminUsername'
29+
}
30+
}
31+
}
32+
```
33+
34+
The next example fails this test because the expression evaluates to a literal value when the default value is used.
35+
36+
```bicep
37+
var defaultAdmin = 'administrator'
38+
resource vm 'Microsoft.Compute/virtualMachines@2020-12-01' = {
39+
name: 'name'
40+
location: location
41+
properties: {
42+
osProfile: {
43+
adminUsername: defaultAdmin
44+
}
45+
}
46+
}
47+
```
48+
49+
This example passes this test.
50+
51+
```bicep
52+
@secure()
53+
param adminUsername string
54+
param location string
55+
resource vm 'Microsoft.Compute/virtualMachines@2020-12-01' = {
56+
name: 'name'
57+
location: location
58+
properties: {
59+
osProfile: {
60+
adminUsername: adminUsername
61+
}
62+
}
63+
}
64+
```
65+
66+
## Next steps
67+
68+
For more information about the linter, see [Use Bicep linter](./linter.md).

articles/azure-resource-manager/bicep/linter-rule-no-hardcoded-environment-urls.md

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,4 @@ You can customize it by adding a bicepconfig.json file and applying new settings
9999

100100
## Next steps
101101

102-
* For more information about the linter, see [Use Bicep linter](./linter.md).
103-
* The current linter rules are:
104-
105-
* [no-hardcoded-env-urls](./linter-rule-no-hardcoded-environment-urls.md)
106-
* [no-unused-params](./linter-rule-no-unused-parameters.md)
107-
* [no-unused-vars](./linter-rule-no-unused-variables.md)
108-
* [prefer-interpolation](./linter-rule-prefer-interpolation.md)
109-
* [secure-parameter-default](./linter-rule-secure-parameter-default.md)
110-
* [simplify-interpolation](./linter-rule-simplify-interpolation.md)
102+
For more information about the linter, see [Use Bicep linter](./linter.md).

articles/azure-resource-manager/bicep/linter-rule-no-unused-parameters.md

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,4 @@ To reduce confusion in your template, delete any parameters that are defined but
1919

2020
## Next steps
2121

22-
* For more information about the linter, see [Use Bicep linter](./linter.md).
23-
* The current linter rules are:
24-
25-
* [no-hardcoded-env-urls](./linter-rule-no-hardcoded-environment-urls.md)
26-
* [no-unused-params](./linter-rule-no-unused-parameters.md)
27-
* [no-unused-vars](./linter-rule-no-unused-variables.md)
28-
* [prefer-interpolation](./linter-rule-prefer-interpolation.md)
29-
* [secure-parameter-default](./linter-rule-secure-parameter-default.md)
30-
* [simplify-interpolation](./linter-rule-simplify-interpolation.md)
22+
For more information about the linter, see [Use Bicep linter](./linter.md).

articles/azure-resource-manager/bicep/linter-rule-no-unused-variables.md

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,4 @@ To reduce confusion in your template, delete any variables that are defined but
1919

2020
## Next steps
2121

22-
* For more information about the linter, see [Use Bicep linter](./linter.md).
23-
* The current linter rules are:
24-
25-
* [no-hardcoded-env-urls](./linter-rule-no-hardcoded-environment-urls.md)
26-
* [no-unused-params](./linter-rule-no-unused-parameters.md)
27-
* [no-unused-vars](./linter-rule-no-unused-variables.md)
28-
* [prefer-interpolation](./linter-rule-prefer-interpolation.md)
29-
* [secure-parameter-default](./linter-rule-secure-parameter-default.md)
30-
* [simplify-interpolation](./linter-rule-simplify-interpolation.md)
22+
For more information about the linter, see [Use Bicep linter](./linter.md).

articles/azure-resource-manager/bicep/linter-rule-prefer-interpolation.md

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,4 @@ var vnetName = 'vnet-${suffix}'
3333

3434
## Next steps
3535

36-
* For more information about the linter, see [Use Bicep linter](./linter.md).
37-
* The current linter rules are:
38-
39-
* [no-hardcoded-env-urls](./linter-rule-no-hardcoded-environment-urls.md)
40-
* [no-unused-params](./linter-rule-no-unused-parameters.md)
41-
* [no-unused-vars](./linter-rule-no-unused-variables.md)
42-
* [prefer-interpolation](./linter-rule-prefer-interpolation.md)
43-
* [secure-parameter-default](./linter-rule-secure-parameter-default.md)
44-
* [simplify-interpolation](./linter-rule-simplify-interpolation.md)
36+
For more information about the linter, see [Use Bicep linter](./linter.md).

articles/azure-resource-manager/bicep/linter-rule-secure-parameter-default.md

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,4 @@ param adminPassword string = newGuid()
5151

5252
## Next steps
5353

54-
* For more information about the linter, see [Use Bicep linter](./linter.md).
55-
* The current linter rules are:
56-
57-
* [no-hardcoded-env-urls](./linter-rule-no-hardcoded-environment-urls.md)
58-
* [no-unused-params](./linter-rule-no-unused-parameters.md)
59-
* [no-unused-vars](./linter-rule-no-unused-variables.md)
60-
* [prefer-interpolation](./linter-rule-prefer-interpolation.md)
61-
* [secure-parameter-default](./linter-rule-secure-parameter-default.md)
62-
* [simplify-interpolation](./linter-rule-simplify-interpolation.md)
54+
For more information about the linter, see [Use Bicep linter](./linter.md).

articles/azure-resource-manager/bicep/linter-rule-simplify-interpolation.md

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,4 @@ resource AutomationAccount 'Microsoft.Automation/automationAccounts@2020-01-13-p
4141

4242
## Next steps
4343

44-
* For more information about the linter, see [Use Bicep linter](./linter.md).
45-
* The current linter rules are:
46-
47-
* [no-hardcoded-env-urls](./linter-rule-no-hardcoded-environment-urls.md)
48-
* [no-unused-params](./linter-rule-no-unused-parameters.md)
49-
* [no-unused-vars](./linter-rule-no-unused-variables.md)
50-
* [prefer-interpolation](./linter-rule-prefer-interpolation.md)
51-
* [secure-parameter-default](./linter-rule-secure-parameter-default.md)
52-
* [simplify-interpolation](./linter-rule-simplify-interpolation.md)
44+
For more information about the linter, see [Use Bicep linter](./linter.md).

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ The linter is integrated into the Bicep CLI and the Bicep extension for Visual S
1717

1818
The default set of linter rules is minimal and taken from [arm-ttk test cases](../templates/template-test-cases.md). The extension and Bicep CLI check the following rules, which are set to the warning level.
1919

20+
- [adminusername-should-not-be-literal](./linter-rule-admin-username-should-not-be-literal.md)
2021
- [no-hardcoded-env-urls](./linter-rule-no-hardcoded-environment-urls.md)
2122
- [no-unused-params](./linter-rule-no-unused-parameters.md)
2223
- [no-unused-vars](./linter-rule-no-unused-variables.md)

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@
9292
href: linter.md
9393
- name: Linter rules
9494
items:
95+
- name: Admin user name not literal
96+
href: linter-rule-admin-username-should-not-be-literal.md
9597
- name: No hardcoded environment URLs
9698
href: linter-rule-no-hardcoded-environment-urls.md
9799
- name: No unused parameters
@@ -157,7 +159,7 @@
157159
- name: Data types
158160
href: data-types.md
159161
displayName: supported types,arrays,booleans,integers,objects,strings,secure
160-
- name: Bicep configuration file
162+
- name: Configuration file
161163
href: bicep-config.md
162164
- name: Functions
163165
items:

0 commit comments

Comments
 (0)