param vmName string param location string param adminUsername string @secure() param adminPassword string param dnsName string param existingVnetName string param existingVnetResourceGroup string param existingSubnetName string param sourceRdpIP string = '*' param vmSize string = 'Standard_D4s_v3' // Reference VNet from different resource group resource existingVnet 'Microsoft.Network/virtualNetworks@2023-05-01' existing = { name: existingVnetName scope: resourceGroup(existingVnetResourceGroup) } resource existingSubnet 'Microsoft.Network/virtualNetworks/subnets@2023-05-01' existing = { parent: existingVnet name: existingSubnetName } resource publicIP 'Microsoft.Network/publicIPAddresses@2023-05-01' = { name: '${vmName}-pip' location: location sku: { name: 'Standard' } properties: { publicIPAllocationMethod: 'Static' publicIPAddressVersion: 'IPv4' dnsSettings: { domainNameLabel: dnsName } } } resource networkSecurityGroup 'Microsoft.Network/networkSecurityGroups@2023-05-01' = { name: '${vmName}-nsg' location: location properties: { securityRules: [ { name: 'AllowRDP' properties: { priority: 1000 protocol: 'Tcp' access: 'Allow' direction: 'Inbound' sourceAddressPrefix: sourceRdpIP sourcePortRange: '*' destinationAddressPrefix: '*' destinationPortRange: '3389' description: 'Allow RDP access' } } ] } } resource networkInterface 'Microsoft.Network/networkInterfaces@2023-05-01' = { name: '${vmName}-nic' location: location properties: { ipConfigurations: [ { name: 'ipconfig1' properties: { privateIPAllocationMethod: 'Dynamic' subnet: { id: existingSubnet.id } publicIPAddress: { id: publicIP.id } } } ] networkSecurityGroup: { id: networkSecurityGroup.id } } } resource virtualMachine 'Microsoft.Compute/virtualMachines@2023-03-01' = { name: vmName location: location properties: { hardwareProfile: { vmSize: vmSize } storageProfile: { imageReference: { publisher: 'MicrosoftWindowsDesktop' offer: 'Windows-11' sku: 'win11-23h2-pro' version: 'latest' } osDisk: { createOption: 'FromImage' name: '${vmName}-osdisk' diskSizeGB: 128 managedDisk: { storageAccountType: 'Premium_LRS' } caching: 'ReadWrite' } dataDisks: [ { createOption: 'Empty' lun: 0 diskSizeGB: 256 managedDisk: { storageAccountType: 'Premium_LRS' } name: '${vmName}-datadisk1' } ] } osProfile: { computerName: vmName adminUsername: adminUsername adminPassword: adminPassword windowsConfiguration: { provisionVMAgent: true enableAutomaticUpdates: true timeZone: 'Central Standard Time (Mexico)' } } networkProfile: { networkInterfaces: [ { id: networkInterface.id } ] } licenseType: 'Windows_Client' } } output vmName string = virtualMachine.name output publicIPAddress string = publicIP.properties.ipAddress output fqdn string = publicIP.properties.dnsSettings.fqdn output rdpCommand string = 'mstsc /v:${publicIP.properties.ipAddress}'