To pass multiple values to the --service-endpoints
property in the Azure CLI command using the hash table, you can modify the $subnetParams
array to include the values individually. Here's an updated version of your code snippet:
Azure CLI
$resourceGroup = "TEST"
$vnetName = "testvnet"
$addressPrefix = "10.0.0.0/16"
# Define an array of subnets
$subnets = @(
@{
Name = "Default"
AddressPrefix = "10.0.2.0/24"
},
@{
Name = "Subnet1"
AddressPrefix = "10.0.1.0/24"
Delegations = "Microsoft.Web/serverFarms"
ServiceEndpoints = @("Microsoft.KeyVault", "Microsoft.Storage")
}
)
# Check if VNet exists
if (!(az network vnet show -g $resourceGroup -n $vnetName)) {
Write-Output "Creating VNet..."
az network vnet create --name $vnetName --resource-group $resourceGroup --address-prefixes $addressPrefix
} else {
Write-Output "Updating VNet..."
az network vnet update --name $vnetName --resource-group $resourceGroup --address-prefixes $addressPrefix
}
# Create or update subnets
foreach ($subnet in $subnets) {
$subnetName = $subnet.Name
$subnetAddressPrefix = $subnet.AddressPrefix
$subnetDelegations = $subnet.Delegations
$subnetServiceEndpoints = $subnet.ServiceEndpoints
$subnetParams = @(
"--vnet-name=$vnetName"
"--resource-group=$resourceGroup"
"--name=$subnetName"
"--address-prefixes=$subnetAddressPrefix"
)
if (![string]::IsNullOrEmpty($subnetDelegations)) {
$subnetParams += "--delegations=$subnetDelegations"
}
if ($subnetServiceEndpoints) {
foreach ($endpoint in $subnetServiceEndpoints) {
$subnetParams += "--service-endpoints=$endpoint"
}
}
if (!(az network vnet subnet show -g $resourceGroup --vnet-name $vnetName -n $subnetName)) {
Write-Output "Creating Subnet $subnetName..."
az network vnet subnet create @subnetParams
} else {
Write-Output "Updating Subnet $subnetName..."
az network vnet subnet update @subnetParams
}
}
In this updated code, the $subnetParams
array is modified to include each endpoint individually using a loop. The --service-endpoints
parameter is added for each endpoint in the $subnetServiceEndpoints
array.
This modification will allow you to pass multiple values to the --service-endpoints
property in the Azure CLI command.