I am learning bicep and trying to get my head around loops. I have a basic integer based loop which will create x number of VMs based on the int value passed through as a parameter (aka if parameter value is 3, 3 VMs should be created). I am having trouble getting Bicep to allocate the VMs to the correct AZ. The code I have is below:
param location string
param vmname string
param tags object
param OSVersion string
param compName string
param username string
@secure()
param password string
param vmCount int
resource virutalmachine 'Microsoft.Compute/virtualMachines@2022-03-01' = [for i in
range(1, vmCount): {
name: '${vmname}${i}'
location: location
tags: tags
properties: {
hardwareProfile: {
vmSize: 'Standard_D2as_v4'
}
osProfile: {
computerName: compName
adminUsername: username
adminPassword: password
}
storageProfile: {
imageReference: {
publisher: 'MicrosoftWindowsServer'
offer: 'WindowsServer'
sku: OSVersion
version: 'latest'
}
osDisk: {
createOption: 'FromImage'
diskSizeGB: 128
managedDisk: {
storageAccountType: 'StandardSSD_LRS'
}
}
}
networkProfile: {
networkInterfaces: [
{
id: nic[i].id
}
]
}
}
zones: [
'${i}'
]
}]
resource nic 'Microsoft.Network/networkInterfaces@2022-01-01' =
[for i in range(0, vmCount): {
name: '${nicname}${i}'
location: location
properties: {
ipConfigurations:[
{
name: 'ipconfig1'
properties: {
privateIPAllocationMethod: 'Dynamic'
subnet: {
id: subnetID
}
}
}
]
networkSecurityGroup: {
id: nsgID
}
}
}]