Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Select, configure, and scale Azure compute resources—VMs, App Service, AKS, and Container Apps
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
workflows/vm-creator/examples/bicep/main.bicep
1@description('Name of the VM')2param vmName string34@description('Azure region')5param location string = resourceGroup().location67@description('VM size, e.g. Standard_D2s_v5')8param vmSize string = 'Standard_D2s_v5'910@description('Admin username')11param adminUsername string1213@description('SSH public key contents')14@secure()15param adminPublicKey string1617@description('Address space for the new VNet')18param vnetAddressPrefix string = '10.0.0.0/16'1920@description('Subnet prefix')21param subnetAddressPrefix string = '10.0.0.0/24'2223@description('OS disk size in GB')24param osDiskSizeGb int = 302526@description('OS disk storage type')27param osDiskType string = 'Premium_LRS'2829@description('Availability zone (1, 2, or 3); empty for regional')30param zone string = ''3132@description('Tags applied to all resources')33param tags object = {}3435@description('Source address prefix allowed for SSH inbound (CIDR or IP). Required — supply your public IP (e.g. "203.0.113.42/32") or a trusted CIDR range. "*" exposes port 22 to the entire internet; only pass it explicitly when you have accepted that risk.')36param sshSourceAddressPrefix string3738var vnetName = '${vmName}-vnet'39var subnetName = 'default'40var nsgName = '${vmName}-nsg'41var publicIpName = '${vmName}-ip'42var nicName = '${vmName}-nic'4344resource nsg 'Microsoft.Network/networkSecurityGroups@2024-05-01' = {45name: nsgName46location: location47tags: tags48properties: {49securityRules: [50{51name: 'AllowSSH'52properties: {53priority: 100054access: 'Allow'55direction: 'Inbound'56protocol: 'Tcp'57sourceAddressPrefix: sshSourceAddressPrefix58sourcePortRange: '*'59destinationAddressPrefix: '*'60destinationPortRange: '22'61}62}63]64}65}6667resource vnet 'Microsoft.Network/virtualNetworks@2024-05-01' = {68name: vnetName69location: location70tags: tags71properties: {72addressSpace: { addressPrefixes: [vnetAddressPrefix] }73subnets: [74{75name: subnetName76properties: {77addressPrefix: subnetAddressPrefix78networkSecurityGroup: { id: nsg.id }79}80}81]82}83}8485resource publicIp 'Microsoft.Network/publicIPAddresses@2024-05-01' = {86name: publicIpName87location: location88tags: tags89sku: { name: 'Standard' }90properties: { publicIPAllocationMethod: 'Static' }91}9293resource nic 'Microsoft.Network/networkInterfaces@2024-05-01' = {94name: nicName95location: location96tags: tags97properties: {98ipConfigurations: [99{100name: 'ipconfig1'101properties: {102subnet: { id: '${vnet.id}/subnets/${subnetName}' }103publicIPAddress: { id: publicIp.id }104privateIPAllocationMethod: 'Dynamic'105}106}107]108}109}110111resource vm 'Microsoft.Compute/virtualMachines@2024-07-01' = {112name: vmName113location: location114tags: tags115zones: empty(zone) ? null : [zone]116properties: {117hardwareProfile: { vmSize: vmSize }118storageProfile: {119imageReference: {120publisher: 'Canonical'121offer: 'ubuntu-24_04-lts'122sku: 'server'123version: 'latest'124}125osDisk: {126createOption: 'FromImage'127diskSizeGB: osDiskSizeGb128managedDisk: { storageAccountType: osDiskType }129}130}131osProfile: {132computerName: vmName133adminUsername: adminUsername134linuxConfiguration: {135disablePasswordAuthentication: true136ssh: {137publicKeys: [138{139path: '/home/${adminUsername}/.ssh/authorized_keys'140keyData: adminPublicKey141}142]143}144}145}146networkProfile: {147networkInterfaces: [148{ id: nic.id }149]150}151}152}153154output vmId string = vm.id155output publicIpAddress string = publicIp.properties.ipAddress156