Setting the file. One moment.
Main · Azure Compute · microsoft/azure-skills · Skills Docs
ContentsBack to the top of the page 12.9
Emm Enable Flow Portal Guidance
(opens in a new tab)
workflows/vm-creator/examples/bicep/ main.bicep
Bicep · 155 lines · 4 KB
)
11 param adminUsername string
12
13 @ description ( 'SSH public key contents' )
14 @ secure ()
15 param adminPublicKey string
16
17 @ description ( 'Address space for the new VNet' )
18 param vnetAddressPrefix string = '10.0.0.0/16'
19
20 @ description ( 'Subnet prefix' )
21 param subnetAddressPrefix string = '10.0.0.0/24'
22
23 @ description ( 'OS disk size in GB' )
24 param osDiskSizeGb int = 30
25
26 @ description ( 'OS disk storage type' )
27 param osDiskType string = 'Premium_LRS'
28
29 @ description ( 'Availability zone (1, 2, or 3); empty for regional' )
30 param zone string = ''
31
32 @ description ( 'Tags applied to all resources' )
33 param tags object = {}
34
35 @ 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.' )
36 param sshSourceAddressPrefix string
37
38 var vnetName = '${ vmName }-vnet'
39 var subnetName = 'default'
40 var nsgName = '${ vmName }-nsg'
41 var publicIpName = '${ vmName }-ip'
42 var nicName = '${ vmName }-nic'
43
44 resource nsg 'Microsoft.Network/networkSecurityGroups@2024-05-01' = {
45 name: nsgName
46 location: location
47 tags: tags
48 properties: {
49 securityRules: [
50 {
51 name: 'AllowSSH'
52 properties: {
53 priority: 1000
54 access: 'Allow'
55 direction: 'Inbound'
56 protocol: 'Tcp'
57 sourceAddressPrefix: sshSourceAddressPrefix
58 sourcePortRange: '*'
59 destinationAddressPrefix: '*'
60 destinationPortRange: '22'
61 }
62 }
63 ]
64 }
65 }
66
67 resource vnet 'Microsoft.Network/virtualNetworks@2024-05-01' = {
68 name: vnetName
69 location: location
70 tags: tags
71 properties: {
72 addressSpace: { addressPrefixes: [vnetAddressPrefix] }
73 subnets: [
74 {
75 name: subnetName
76 properties: {
77 addressPrefix: subnetAddressPrefix
78 networkSecurityGroup: { id: nsg.id }
79 }
80 }
81 ]
82 }
83 }
84
85 resource publicIp 'Microsoft.Network/publicIPAddresses@2024-05-01' = {
86 name: publicIpName
87 location: location
88 tags: tags
89 sku: { name: 'Standard' }
90 properties: { publicIPAllocationMethod: 'Static' }
91 }
92
93 resource nic 'Microsoft.Network/networkInterfaces@2024-05-01' = {
94 name: nicName
95 location: location
96 tags: tags
97 properties: {
98 ipConfigurations: [
99 {
100 name: 'ipconfig1'
101 properties: {
102 subnet: { id: '${ vnet . id }/subnets/${ subnetName }' }
103 publicIPAddress: { id: publicIp.id }
104 privateIPAllocationMethod: 'Dynamic'
105 }
106 }
107 ]
108 }
109 }
110
111 resource vm 'Microsoft.Compute/virtualMachines@2024-07-01' = {
112 name: vmName
113 location: location
114 tags: tags
115 zones: empty (zone) ? null : [zone]
116 properties: {
117 hardwareProfile: { vmSize: vmSize }
118 storageProfile: {
119 imageReference: {
120 publisher: 'Canonical'
121 offer: 'ubuntu-24_04-lts'
122 sku: 'server'
123 version: 'latest'
124 }
125 osDisk: {
126 createOption: 'FromImage'
127 diskSizeGB: osDiskSizeGb
128 managedDisk: { storageAccountType: osDiskType }
129 }
130 }
131 osProfile: {
132 computerName: vmName
133 adminUsername: adminUsername
134 linuxConfiguration: {
135 disablePasswordAuthentication: true
136 ssh: {
137 publicKeys: [
138 {
139 path: '/home/${ adminUsername }/.ssh/authorized_keys'
140 keyData: adminPublicKey
141 }
142 ]
143 }
144 }
145 }
146 networkProfile: {
147 networkInterfaces: [
148 { id: nic.id }
149 ]
150 }
151 }
152 }
153
154 output vmId string = vm.id
155 output publicIpAddress string = publicIp.properties.ipAddress