Azure network security group Add source ip prefixes using variable

1.6k Views Asked by At

I am trying to add a list of IP addresses (using a variable) to a security rule during deployment. Azure CLI isn't accepting the values as a variable, however the same value works if added manually.

Has anyone come across a similar issue? or know of another automated way around this.

This doesn't work

$ipWhitelist = '11.11.11.11 22.22.22.22' (I have tried many combinations i.e. space or comma between the addresses etc.)

az network nsg rule update --resource-group myRG --nsg-name myNGS  -n MyRule --source-address-prefixes $ipWhitelist

Security rule XXXXXXXXX has invalid Address prefix. Value provided: 11.11.11.11 22.22.22.22
Security Rule XXXXXXXXX has invalid Address prefix. Value provided: 11.11.11.11,22.22.22.22

Variables work with single IP address

$ipWhitelist = '11.11.11.11'

So issues seems to be with variables with multiple ip addresses.

However this works fine

az network nsg rule update --resource-group myRG --nsg-name myNGS  -n MyRule --source-address-prefixes 11.11.11.11 22.22.22.22
2

There are 2 best solutions below

0
Nancy On BEST ANSWER

You could run the following Comma-separated string list on PowerShell.

$ipWhitelist = "11.11.11.11", "22.22.22.22"

az network nsg rule update --resource-group nancytest --nsg-name win-nsg  -n NRMS-Rule-103 --source-address-prefixes $ipWhitelist

enter image description here

0
Vivekananthan k On

If it is comma separated, convert it to array.

For instance "Split" function will be converted into array of string.