forked from Azure/PSRule.Rules.Azure
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes conditional secret as parameter or placeholder Azure#2054 (Azur…
- Loading branch information
1 parent
ddeb333
commit d6471e6
Showing
6 changed files
with
181 additions
and
1 deletion.
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
27 changes: 27 additions & 0 deletions
27
tests/PSRule.Rules.Azure.Tests/Bicep/SecretTestCases/Tests.Bicep.1.bicep
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,27 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
// Test case for https://github.com/Azure/PSRule.Rules.Azure/issues/2054 | ||
|
||
param prefix string = 'super' | ||
param deployed bool = true | ||
|
||
resource vault 'Microsoft.KeyVault/vaults@2022-07-01' existing = { | ||
name: 'vault1' | ||
} | ||
|
||
module withSecret 'Tests.Bicep.1.child.bicep' = { | ||
name: 'withSecret' | ||
params: { | ||
name: '1' | ||
secret: deployed ? vault.getSecret('${prefix}secret1') : 'placeholder' | ||
} | ||
} | ||
|
||
module withPlaceholder 'Tests.Bicep.1.child.bicep' = { | ||
name: 'withPlaceholder' | ||
params: { | ||
name: '2' | ||
secret: !deployed ? vault.getSecret('${prefix}secret1') : 'placeholder' | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
tests/PSRule.Rules.Azure.Tests/Bicep/SecretTestCases/Tests.Bicep.1.child.bicep
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,14 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
param name string | ||
|
||
@secure() | ||
param secret string | ||
|
||
resource secretToSet 'Microsoft.KeyVault/vaults/secrets@2022-07-01' = { | ||
name: 'vault1/toSet${name}' | ||
properties: { | ||
value: secret | ||
} | ||
} |
115 changes: 115 additions & 0 deletions
115
tests/PSRule.Rules.Azure.Tests/Bicep/SecretTestCases/Tests.Bicep.1.json
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,115 @@ | ||
{ | ||
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", | ||
"contentVersion": "1.0.0.0", | ||
"metadata": { | ||
"_generator": { | ||
"name": "bicep", | ||
"version": "0.30.23.60470", | ||
"templateHash": "6760857410189558623" | ||
} | ||
}, | ||
"parameters": { | ||
"prefix": { | ||
"type": "string", | ||
"defaultValue": "super" | ||
}, | ||
"deployed": { | ||
"type": "bool", | ||
"defaultValue": true | ||
} | ||
}, | ||
"resources": [ | ||
{ | ||
"type": "Microsoft.Resources/deployments", | ||
"apiVersion": "2022-09-01", | ||
"name": "withSecret", | ||
"properties": { | ||
"expressionEvaluationOptions": { | ||
"scope": "inner" | ||
}, | ||
"mode": "Incremental", | ||
"parameters": { | ||
"name": { | ||
"value": "1" | ||
}, | ||
"secret": "[if(parameters('deployed'), createObject('reference', createObject('keyVault', createObject('id', resourceId('Microsoft.KeyVault/vaults', 'vault1')), 'secretName', format('{0}secret1', parameters('prefix')))), createObject('value', 'placeholder'))]" | ||
}, | ||
"template": { | ||
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", | ||
"contentVersion": "1.0.0.0", | ||
"metadata": { | ||
"_generator": { | ||
"name": "bicep", | ||
"version": "0.30.23.60470", | ||
"templateHash": "15661998235342522313" | ||
} | ||
}, | ||
"parameters": { | ||
"name": { | ||
"type": "string" | ||
}, | ||
"secret": { | ||
"type": "securestring" | ||
} | ||
}, | ||
"resources": [ | ||
{ | ||
"type": "Microsoft.KeyVault/vaults/secrets", | ||
"apiVersion": "2022-07-01", | ||
"name": "[format('vault1/toSet{0}', parameters('name'))]", | ||
"properties": { | ||
"value": "[parameters('secret')]" | ||
} | ||
} | ||
] | ||
} | ||
} | ||
}, | ||
{ | ||
"type": "Microsoft.Resources/deployments", | ||
"apiVersion": "2022-09-01", | ||
"name": "withPlaceholder", | ||
"properties": { | ||
"expressionEvaluationOptions": { | ||
"scope": "inner" | ||
}, | ||
"mode": "Incremental", | ||
"parameters": { | ||
"name": { | ||
"value": "2" | ||
}, | ||
"secret": "[if(not(parameters('deployed')), createObject('reference', createObject('keyVault', createObject('id', resourceId('Microsoft.KeyVault/vaults', 'vault1')), 'secretName', format('{0}secret1', parameters('prefix')))), createObject('value', 'placeholder'))]" | ||
}, | ||
"template": { | ||
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", | ||
"contentVersion": "1.0.0.0", | ||
"metadata": { | ||
"_generator": { | ||
"name": "bicep", | ||
"version": "0.30.23.60470", | ||
"templateHash": "15661998235342522313" | ||
} | ||
}, | ||
"parameters": { | ||
"name": { | ||
"type": "string" | ||
}, | ||
"secret": { | ||
"type": "securestring" | ||
} | ||
}, | ||
"resources": [ | ||
{ | ||
"type": "Microsoft.KeyVault/vaults/secrets", | ||
"apiVersion": "2022-07-01", | ||
"name": "[format('vault1/toSet{0}', parameters('name'))]", | ||
"properties": { | ||
"value": "[parameters('secret')]" | ||
} | ||
} | ||
] | ||
} | ||
} | ||
} | ||
] | ||
} |
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
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