-
Notifications
You must be signed in to change notification settings - Fork 88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] User Defined Function not found #3169
Comments
Hi @modbase. Thanks for reporting the issue. There might be a little more information required, in the simple case with v1.39.3 I wasn't able to reproduce the issue. I have constructed the sample below based on your information provided which does not generate the error you are experiencing. Are you able to update/ fill in the blanks so I can reproduce it locally. Tests.Bicep.2.bicep targetScope = 'resourceGroup'
module storage 'Tests.Bicep.2.child.bicep' = {
name: 'storage'
params: {
prefix: 'sa'
}
} Tests.Bicep.2.child.bicep targetScope = 'resourceGroup'
param prefix string
import { customNamingFunction } from './Tests.Bicep.2.fn.bicep'
resource storage 'Microsoft.Storage/storageAccounts@2023-05-01' = {
name: customNamingFunction(prefix, 1)
location: resourceGroup().location
kind: 'StorageV2'
sku: {
name: 'Standard_LRS'
}
} Tests.Bicep.2.fn.bicep targetScope = 'resourceGroup'
// A custom naming function.
@export()
func customNamingFunction(prefix string, instance int) string =>
'${prefix}${uniqueString(resourceGroup().id)}${instance}' Also if you have an Bicep experimental features enabled in Thanks. |
Hi @BernieWhite Thanks for your fast response! |
Thanks @modbase I was able to reproduce that locally. |
Existing rule
No response
Description of the issue
I just started investigating PRRule for Azure, so hopefully the behaviour I get is simply a matter of incorrect use.
We have a large Bicep module library with custom made modules. Modules are separated in a folder per module. Besides the modules, we also have some shared Bicep code which contains User Defined Types and User Defined Functions used across the modules.
In summary, our folder structure is like this:
I created a ps-rule.yml file with the following content:
I tried to run the built-in WAF rules on one of our modules. This module makes use of a User Defined Function within the
/shared/functions.bicep
file. So in the/modules/storage-account/main.bicep
file we import this function, lets call it nameOfCustomFunction:The main.tests.bicep file looks like this:
Unfortunately, when running the tests using
Assert-PSRule -InputPath .\modules\
we get the following error (redacted to remove some sensitive info):Failed to expand bicep source '##redacted##\modules\storage-account\.tests\main.tests.bicep'. Exception calling "GetBicepResources" with "2" argument(s): "Unable to expand resources because the source file '##redacted##\modules\storage-account\.tests\main.tests.bicep' was not valid. An error occurred evaluating expression '[__bicep.nameOfCustomFunction(parameters('someParameter'), 6)]' line 1408. The function "__bicep.nameOfCustomFunction" was not found."
Apart from PSRule, the module builds and deploys perfectly, so we can be assured that there's in fact nothing wrong with the module itself.
I tried using PRRule v2.9.0 and PSRule.Rule.Azure v1.39.3 and v1.40.0-B0063
Am I perhaps missing something?
Error messages
No response
Reproduction
Create a module which uses an exported User Defined Function defined within another file.
Run the default rules.
Version of PSRule
2.9.0
Version of PSRule for Azure
v1.39.3 and v1.40.0-B0063
Additional context
No response
The text was updated successfully, but these errors were encountered: