-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update S1192 String literals should not be duplicated, add ARM
- Loading branch information
1 parent
cad20a8
commit 943ce5b
Showing
3 changed files
with
108 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
The following are ignored: | ||
|
||
* literals with fewer than 5 characters | ||
* The `apiVersion` of a resource (see rule S6893) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Instead, use variables to replace the duplicated string literals. | ||
Variables can be referenced from many places, but only need to be updated in a single place. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,124 @@ | ||
FIXME: add a description | ||
== Why is this an issue? | ||
|
||
// If you want to factorize the description uncomment the following line and create the file. | ||
//include::../description.adoc[] | ||
include::../description.adoc[] | ||
|
||
== Why is this an issue? | ||
=== Exceptions | ||
|
||
include::exceptions-arm.adoc[] | ||
|
||
== How to fix it in ARM templates | ||
|
||
include::howtofix-arm.adoc[] | ||
|
||
=== Code examples | ||
|
||
==== Noncompliant code example | ||
|
||
With the default threshold of 3: | ||
|
||
[source,json,diff-id=1,diff-type=noncompliant] | ||
---- | ||
{ | ||
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", | ||
"contentVersion": "1.0.0.0", | ||
"variables": {}, | ||
"resources": [ | ||
{ | ||
"type": "Microsoft.Storage/storageAccounts", | ||
"apiVersion": "2021-01-01", | ||
"name": "appSuperStorage", | ||
"tags": { | ||
"displayName": "appSuperStorage", | ||
"shortName" : "appSuperStorage" | ||
} | ||
} | ||
] | ||
} | ||
---- | ||
|
||
FIXME: remove the unused optional headers (that are commented out) | ||
==== Compliant solution | ||
|
||
[source,json,diff-id=1,diff-type=compliant] | ||
---- | ||
{ | ||
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", | ||
"contentVersion": "1.0.0.0", | ||
"variables": { | ||
"storageAccountName": "appSuperStorage" | ||
}, | ||
"resources": [ | ||
{ | ||
"type": "Microsoft.Storage/storageAccounts", | ||
"apiVersion": "2021-01-01", | ||
"name": "[variables('storageAccountName')]", | ||
"tags": { | ||
"displayName": "[variables('storageAccountName')]", | ||
"shortName" : "[variables('storageAccountName')]" | ||
} | ||
} | ||
] | ||
} | ||
---- | ||
|
||
//=== What is the potential impact? | ||
== How to fix it in Bicep | ||
|
||
== How to fix it | ||
//== How to fix it in FRAMEWORK NAME | ||
include::howtofix-arm.adoc[] | ||
|
||
=== Code examples | ||
|
||
==== Noncompliant code example | ||
|
||
[source,text,diff-id=1,diff-type=noncompliant] | ||
With the default threshold of 3: | ||
|
||
[source,bicep,diff-id=2,diff-type=noncompliant] | ||
---- | ||
FIXME | ||
resource storageAccount 'Microsoft.Storage/storageAccounts@2021-01-01' = { | ||
name: 'appSuperStorage' | ||
tags: { | ||
displayName: 'appSuperStorage' | ||
shortName: 'appSuperStorage' | ||
} | ||
} | ||
---- | ||
|
||
==== Compliant solution | ||
|
||
[source,text,diff-id=1,diff-type=compliant] | ||
[source,bicep,diff-id=2,diff-type=compliant] | ||
---- | ||
FIXME | ||
var storageAccountName = 'appSuperStorage' | ||
resource storageAccount 'Microsoft.Storage/storageAccounts@2021-01-01' = { | ||
name: storageAccountName | ||
tags: { | ||
displayName: storageAccountName | ||
shortName: storageAccountName | ||
} | ||
} | ||
---- | ||
|
||
//=== How does this work? | ||
== Resources | ||
|
||
== Documentation | ||
|
||
* Microsoft - https://learn.microsoft.com/en-us/azure/azure-resource-manager/templates/best-practices#variables[ARM template best practices] | ||
* Microsoft - https://learn.microsoft.com/en-us/azure/azure-resource-manager/bicep/best-practices[Best practices for Bicep] | ||
|
||
=== Related rules | ||
|
||
* S6893 - Use a constant value for the apiVersion | ||
|
||
ifdef::env-github,rspecator-view[] | ||
|
||
''' | ||
== Implementation Specification | ||
(visible only on this page) | ||
|
||
include::../message.adoc[] | ||
|
||
//=== Pitfalls | ||
include::../parameters.adoc[] | ||
|
||
//=== Going the extra mile | ||
include::../highlighting.adoc[] | ||
|
||
''' | ||
|
||
//== Resources | ||
//=== Documentation | ||
//=== Articles & blog posts | ||
//=== Conference presentations | ||
//=== Standards | ||
//=== External coding guidelines | ||
//=== Benchmarks | ||
endif::env-github,rspecator-view[] |