-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes user defined function not found when used as parameter default #…
- Loading branch information
1 parent
c9d6d8f
commit 479e432
Showing
8 changed files
with
144 additions
and
3 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
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
12 changes: 12 additions & 0 deletions
12
tests/PSRule.Rules.Azure.Tests/Bicep/UserDefinedFunctionTestCases/Tests.Bicep.2.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,12 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
// Test case for https://github.com/Azure/PSRule.Rules.Azure/issues/3169 | ||
// Based on work contributed by @modbase | ||
|
||
targetScope = 'resourceGroup' | ||
|
||
module storage 'Tests.Bicep.2.child.bicep' = { | ||
name: 'storage' | ||
params: {} | ||
} |
17 changes: 17 additions & 0 deletions
17
tests/PSRule.Rules.Azure.Tests/Bicep/UserDefinedFunctionTestCases/Tests.Bicep.2.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,17 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
targetScope = 'resourceGroup' | ||
|
||
param name string = customNamingFunction('sa', 1) | ||
|
||
import { customNamingFunction } from './Tests.Bicep.2.fn.bicep' | ||
|
||
resource storage 'Microsoft.Storage/storageAccounts@2023-05-01' = { | ||
name: name | ||
location: resourceGroup().location | ||
kind: 'StorageV2' | ||
sku: { | ||
name: 'Standard_LRS' | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
tests/PSRule.Rules.Azure.Tests/Bicep/UserDefinedFunctionTestCases/Tests.Bicep.2.fn.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,9 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
targetScope = 'resourceGroup' | ||
|
||
// A custom naming function. | ||
@export() | ||
func customNamingFunction(prefix string, instance int) string => | ||
'${prefix}${uniqueString(resourceGroup().id)}${instance}' |
83 changes: 83 additions & 0 deletions
83
tests/PSRule.Rules.Azure.Tests/Bicep/UserDefinedFunctionTestCases/Tests.Bicep.2.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,83 @@ | ||
{ | ||
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", | ||
"contentVersion": "1.0.0.0", | ||
"metadata": { | ||
"_generator": { | ||
"name": "bicep", | ||
"version": "0.31.34.60546", | ||
"templateHash": "6735599436485338599" | ||
} | ||
}, | ||
"resources": [ | ||
{ | ||
"type": "Microsoft.Resources/deployments", | ||
"apiVersion": "2022-09-01", | ||
"name": "storage", | ||
"properties": { | ||
"expressionEvaluationOptions": { | ||
"scope": "inner" | ||
}, | ||
"mode": "Incremental", | ||
"parameters": {}, | ||
"template": { | ||
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", | ||
"languageVersion": "2.0", | ||
"contentVersion": "1.0.0.0", | ||
"metadata": { | ||
"_generator": { | ||
"name": "bicep", | ||
"version": "0.31.34.60546", | ||
"templateHash": "12715503820119808772" | ||
} | ||
}, | ||
"functions": [ | ||
{ | ||
"namespace": "__bicep", | ||
"members": { | ||
"customNamingFunction": { | ||
"parameters": [ | ||
{ | ||
"type": "string", | ||
"name": "prefix" | ||
}, | ||
{ | ||
"type": "int", | ||
"name": "instance" | ||
} | ||
], | ||
"output": { | ||
"type": "string", | ||
"value": "[format('{0}{1}{2}', parameters('prefix'), uniqueString(resourceGroup().id), parameters('instance'))]" | ||
}, | ||
"metadata": { | ||
"__bicep_imported_from!": { | ||
"sourceTemplate": "Tests.Bicep.2.fn.bicep" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
], | ||
"parameters": { | ||
"name": { | ||
"type": "string", | ||
"defaultValue": "[__bicep.customNamingFunction('sa', 1)]" | ||
} | ||
}, | ||
"resources": { | ||
"storage": { | ||
"type": "Microsoft.Storage/storageAccounts", | ||
"apiVersion": "2023-05-01", | ||
"name": "[parameters('name')]", | ||
"location": "[resourceGroup().location]", | ||
"kind": "StorageV2", | ||
"sku": { | ||
"name": "Standard_LRS" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
] | ||
} |
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