microsoft / PSRule

Validate infrastructure as code (IaC) and objects using PowerShell rules.

Home Page:https://microsoft.github.io/PSRule/v2/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

The function "parseCidr" was not found

tstooke opened this issue · comments

commented

Description of the issue

New Bicep function parseCidr is not supported.

To Reproduce

Steps to reproduce the issue:

  1. Add Bicep resource for SQL Server Firewall Rules
  2. Reference function parseCidr to process incoming values
  3. Notice error when running PSRule tests.

Bicep module

@description('The name of the SQL Server.')
param SqlServerName string

@description('''
An object containing the list of public IP Addresses that are allowed to access the Resource (Name, CIDR).
**IMPORTANT:** The `CIDR` value must be an `array` of strings rather than a single comma-separated string.
''')
param AllowedPublicIp object

resource sqlServer 'Microsoft.Sql/servers@2022-05-01-preview' existing = {
  name: SqlServerName
}

resource firewallRules 'Microsoft.Sql/servers/firewallRules@2022-05-01-preview' = [for (ip, index) in AllowedPublicIp.CIDR: {
  name: '${AllowedPublicIp.Name}_${index}'
  parent: sqlServer
  properties: {
    startIpAddress: parseCidr(ip).firstUsable
    endIpAddress: parseCidr(ip).lastUsable
  }
}]

Bicep Params

using './main.bicep'

param SqlServerName = 'some-existing-sql-server'
param AllowedPublicIp = {
  Name: 'fake_ip'
  CIDR: [ '10.1.2.0/23', '10.10.2.0/23' ]
  Priority: 100
}

Expected behaviour

The Bicep module should expand and get processed.

Error output

[ERROR] Failed to expand bicep source 'C:\source\sql-firewallrule\main.tests.bicep'.
Exception calling "GetBicepResources" with "2" argument(s):
Unable to expand resources because the source file 'C:\source\sql-firewallrule\main.tests.bicep' was not valid.
An error occurred evaluating expression '[parseCidr(parameters('AllowedPublicIp').CIDR[copyIndex()]).firstUsable]' line 72.
The function "parseCidr" was not found.

Module in use and version:

  • Module: PSRule
  • Version: 2.9.0
  • Module: PSRule.Rules.Azure
  • Version: 1.27.2
  • Module: Bicep
  • Version: 0.18.4

Captured output from $PSVersionTable:

Name                           Value
----                           -----
PSVersion                      7.3.4
PSEdition                      Core
GitCommitId                    7.3.4
OS                             Microsoft Windows 10.0.19045
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Additional context

The parseCidr function is relatively new (Bicep 0.17.1) - perhaps it's just not implemented in PSRule, or maybe there's a phantom older version of Bicep hiding on my machine?

@tstooke. Correct. Thanks for reporting the issue.

I'll more the issue over to Azure/PSRule.Rules.Azure#2279 for better tracking.

@tstooke This is implemented in PSRule for Azure v1.28.0-B0115.