Azure / PSRule.Rules.Azure

Rules to validate Azure resources and infrastructure as code (IaC) using PSRule.
https://azure.github.io/PSRule.Rules.Azure/
MIT License
383 stars 84 forks source link

[BUG] Bicep Expand Source - arguments for 'Filter' are not in the expected format or type #2966

Closed mbrat2005 closed 1 month ago

mbrat2005 commented 1 month ago

Existing rule

No response

Description of the issue

When PSRule attempts to expand my bicep source, it fails due to a filter statement. The filter seems to work as expected in deployments, so this appears to be an issue with PSRule bicep expansion.

Error messages

Using PSRule v2.9.0 Using PSRule.Rules.Azure v1.38.0-B0034


Explore documentation: https://aka.ms/ps-rule Contribute and find source: https://github.com/microsoft/PSRule Report issues: https://github.com/microsoft/PSRule/issues PSRule.Rules.Azure: https://aka.ms/ps-rule-azure

From repository: https://github.com/mbrat2005/bicep-registry-modules on : mtb-azure-stack-hci-cluster at : a5b87fcf970b932895a78a86a2b24d22ae812b87

Error: Failed to expand bicep source '/home/runner/work/bicep-registry-modules/bicep-registry-modules/avm/res/azure-stack-hci/cluster/tests/e2e/2nodeswitched.defaults/main.test.bicep'. Exception calling "GetBicepResources" with "2" argument(s): "Unable to expand resources because the source file '/home/runner/work/bicep-registry-modules/bicep-registry-modules/avm/res/azure-stack-hci/cluster/tests/e2e/2nodeswitched.defaults/main.test.bicep' was not valid. An error occurred evaluating expression '[filter(reference(format('{0}/providers/microsoft.azurestackhci/edgeDevices/default', variables('arcNodeResourceIds')[copyIndex('physicalNodes')]), '2024-01-01', 'Full').properties.deviceConfiguration.nicDetails, lambda('nic', not(equals(tryGet(lambdaVariables('nic'), 'defaultGateway'), null()))))[0].ip4Address]' line 2800. The arguments for 'Filter' are not in the expected format or type."

Reproduction

// Getting the IP from the first NIC of the node with a default gateway. Only the first management NIC should have a gateway defined. // This reference call requires that the 'DeviceManagementExtension' extension be fully initialized on each node, which creates the // referenced edgeDevices sub-resource, containing the IP configuration. ipv4Address: (filter( reference('${hciNode}/providers/microsoft.azurestackhci/edgeDevices/default', '2024-01-01', 'Full').properties.deviceConfiguration.nicDetails, nic => nic.?defaultGateway != null ))[0].ip4Address

Version of PSRule

2.9.0

Version of PSRule for Azure

v1.38.0-B0034

Additional context

No response