2022-12-15 21:05:12 +03:00
|
|
|
targetScope = 'resourceGroup'
|
|
|
|
|
2023-01-06 20:59:37 +03:00
|
|
|
param name string
|
|
|
|
param vm object
|
|
|
|
param image object
|
2023-05-10 18:41:46 +03:00
|
|
|
param location string
|
2022-12-15 21:05:12 +03:00
|
|
|
param resourcePostfix string = '${uniqueString(subscription().subscriptionId, resourceGroup().id)}x'
|
2023-01-06 20:59:37 +03:00
|
|
|
param subnetId string
|
|
|
|
param adminUser string
|
|
|
|
@secure()
|
2023-05-31 17:25:32 +03:00
|
|
|
param adminPassword string
|
|
|
|
@secure()
|
|
|
|
param adminSshPublicKey string
|
2023-01-13 14:21:57 +03:00
|
|
|
param asgIds object
|
2022-12-15 21:05:12 +03:00
|
|
|
|
2023-05-10 18:41:46 +03:00
|
|
|
resource publicIp 'Microsoft.Network/publicIPAddresses@2022-07-01' = if (contains(vm, 'pip') && vm.pip) {
|
2023-01-06 20:59:37 +03:00
|
|
|
name: '${name}-pip'
|
2022-12-15 21:05:12 +03:00
|
|
|
location: location
|
|
|
|
sku: {
|
2024-02-13 20:01:50 +03:00
|
|
|
name: 'Standard'
|
2022-12-15 21:05:12 +03:00
|
|
|
}
|
|
|
|
properties: {
|
2023-05-04 13:24:50 +03:00
|
|
|
publicIPAllocationMethod: 'Static'
|
2022-12-15 21:05:12 +03:00
|
|
|
publicIPAddressVersion: 'IPv4'
|
|
|
|
idleTimeoutInMinutes: 4
|
|
|
|
dnsSettings: {
|
2023-01-06 20:59:37 +03:00
|
|
|
domainNameLabel : '${name}${resourcePostfix}'
|
2022-12-15 21:05:12 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-13 20:07:46 +03:00
|
|
|
// var count = contains(vm, 'count') && vm.count > 1 ? vm.count : 1
|
|
|
|
// var vmPrefixes = [ for i in range(0, count): count > 1 ? '-${(i + 1)}' : '' ]
|
2023-01-06 20:59:37 +03:00
|
|
|
|
2023-05-10 18:41:46 +03:00
|
|
|
resource nic 'Microsoft.Network/networkInterfaces@2022-07-01' = {
|
2023-02-13 20:07:46 +03:00
|
|
|
name: '${name}-nic'
|
2022-12-15 21:05:12 +03:00
|
|
|
location: location
|
|
|
|
properties: {
|
|
|
|
ipConfigurations: [
|
|
|
|
{
|
2023-02-13 20:07:46 +03:00
|
|
|
name: '${name}-ipconfig'
|
2023-01-06 20:59:37 +03:00
|
|
|
properties: union(
|
|
|
|
{
|
2023-01-13 14:21:57 +03:00
|
|
|
applicationSecurityGroups: map(vm.asgs, asg => { id: asgIds[asg] })
|
2023-01-06 20:59:37 +03:00
|
|
|
subnet: {
|
|
|
|
id: subnetId
|
|
|
|
}
|
|
|
|
privateIPAllocationMethod: 'Dynamic'
|
|
|
|
}, contains(vm, 'pip') && vm.pip ? {
|
2023-03-28 13:01:09 +03:00
|
|
|
publicIpAddress: {
|
|
|
|
id: publicIp.id
|
|
|
|
}
|
2022-12-15 21:05:12 +03:00
|
|
|
} : {}
|
2023-01-06 20:59:37 +03:00
|
|
|
)
|
2022-12-15 21:05:12 +03:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
2023-02-13 20:07:46 +03:00
|
|
|
}
|
2022-12-15 21:05:12 +03:00
|
|
|
|
2023-01-06 20:59:37 +03:00
|
|
|
var datadisks = contains(vm, 'datadisks') ? vm.datadisks : []
|
2022-12-15 21:05:12 +03:00
|
|
|
|
2023-05-10 18:41:46 +03:00
|
|
|
resource virtualMachine 'Microsoft.Compute/virtualMachines@2022-11-01' = {
|
2023-02-13 20:07:46 +03:00
|
|
|
name: name
|
2022-12-15 21:05:12 +03:00
|
|
|
location: location
|
2023-02-06 13:14:05 +03:00
|
|
|
plan: contains(image, 'plan') && empty(image.plan) == false ? {
|
|
|
|
publisher: split(image.plan,':')[0]
|
|
|
|
product: split(image.plan,':')[1]
|
|
|
|
name: split(image.plan,':')[2]
|
2022-12-15 21:05:12 +03:00
|
|
|
} : null
|
2023-02-09 20:49:11 +03:00
|
|
|
identity: {
|
|
|
|
type: 'SystemAssigned'
|
|
|
|
}
|
2022-12-15 21:05:12 +03:00
|
|
|
properties: {
|
|
|
|
hardwareProfile: {
|
2023-01-06 20:59:37 +03:00
|
|
|
vmSize: vm.sku
|
2022-12-15 21:05:12 +03:00
|
|
|
}
|
|
|
|
storageProfile: {
|
2023-01-06 20:59:37 +03:00
|
|
|
dataDisks: [ for (disk, idx) in datadisks: union({
|
2022-12-15 21:05:12 +03:00
|
|
|
name: disk.name
|
|
|
|
managedDisk: {
|
|
|
|
storageAccountType: disk.disksku
|
|
|
|
}
|
|
|
|
lun: idx
|
2023-10-18 18:35:18 +03:00
|
|
|
createOption: disk.createOption
|
|
|
|
},
|
|
|
|
disk.createOption == 'FromImage' ? {} : {diskSizeGB: disk.size},
|
|
|
|
contains(disk, 'caching') ? {
|
|
|
|
caching: disk.caching
|
|
|
|
} : {}
|
2022-12-15 21:05:12 +03:00
|
|
|
)]
|
2023-01-06 20:59:37 +03:00
|
|
|
osDisk: union(
|
|
|
|
{
|
|
|
|
createOption: 'FromImage'
|
|
|
|
managedDisk: {
|
|
|
|
storageAccountType: vm.osdisksku
|
|
|
|
}
|
|
|
|
caching: 'ReadWrite'
|
|
|
|
}, contains(vm, 'osdisksize') ? {
|
|
|
|
diskSizeGB: vm.osdisksize
|
|
|
|
} : {}
|
2022-12-15 21:05:12 +03:00
|
|
|
)
|
2023-01-06 20:59:37 +03:00
|
|
|
imageReference: image.ref
|
2022-12-15 21:05:12 +03:00
|
|
|
}
|
|
|
|
networkProfile: {
|
|
|
|
networkInterfaces: [
|
|
|
|
{
|
2023-02-13 20:07:46 +03:00
|
|
|
id: nic.id
|
2022-12-15 21:05:12 +03:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
2023-01-06 20:59:37 +03:00
|
|
|
osProfile: union(
|
|
|
|
{
|
2023-02-13 20:07:46 +03:00
|
|
|
computerName: name
|
|
|
|
adminUsername: adminUser
|
2024-02-26 16:55:46 +03:00
|
|
|
}, contains(vm, 'deploy_script') && vm.deploy_script != '' ? { // deploy script not empty
|
2023-01-06 20:59:37 +03:00
|
|
|
customData: base64(vm.deploy_script)
|
|
|
|
} : {}, contains(vm, 'windows') && vm.windows == true ? { // windows
|
2023-05-31 17:25:32 +03:00
|
|
|
adminPassword: adminPassword
|
2023-01-06 20:59:37 +03:00
|
|
|
windowsConfiguration: {
|
|
|
|
winRM: {
|
|
|
|
listeners: [
|
|
|
|
{
|
|
|
|
protocol: 'Http'
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} : {}, ! contains(vm, 'windows') || vm.windows == false ? { // linux
|
|
|
|
linuxConfiguration: {
|
|
|
|
disablePasswordAuthentication: true
|
|
|
|
ssh: {
|
|
|
|
publicKeys: [
|
|
|
|
{
|
|
|
|
path: '/home/${adminUser}/.ssh/authorized_keys'
|
2023-05-31 17:25:32 +03:00
|
|
|
keyData: adminSshPublicKey
|
2023-01-06 20:59:37 +03:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} : {}, contains(vm, 'ahub') && vm.ahub == true ? { // ahub
|
|
|
|
licenseType: 'Windows_Server'
|
|
|
|
} : {}
|
|
|
|
)
|
2022-12-15 21:05:12 +03:00
|
|
|
}
|
2023-02-13 20:07:46 +03:00
|
|
|
}
|
2022-12-15 21:05:12 +03:00
|
|
|
|
2023-01-06 20:59:37 +03:00
|
|
|
//output private_ip string = nic.properties.ipConfigurations[0].properties.privateIPAddress
|
|
|
|
output fqdn string = contains(vm, 'pip') && vm.pip ? publicIp.properties.dnsSettings.fqdn : ''
|
2023-06-26 16:41:26 +03:00
|
|
|
output publicIp string = contains(vm, 'pip') && vm.pip ? publicIp.properties.ipAddress : ''
|
2023-02-13 20:07:46 +03:00
|
|
|
output privateIp string = nic.properties.ipConfigurations[0].properties.privateIPAddress
|
|
|
|
output principalId string = virtualMachine.identity.principalId
|
|
|
|
//output privateIps array = [ for i in range(0, count): nic[i].properties.ipConfigurations[0].properties.privateIPAddress ]
|
|
|
|
//output principalIds array = [ for i in range(0, count): virtualMachine[i].identity.principalId ]
|