-
Notifications
You must be signed in to change notification settings - Fork 0
/
vm.bicep
164 lines (153 loc) · 3.87 KB
/
vm.bicep
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
param vnet object
param vmName string = 'linux-vm'
param vmSize string = 'Standard_B1s'
param adminUsername string = 'takekazu.omi'
param adminPassword string {
secure: true
}
param subnetName string = 'subnet1'
param customData string = ''
param location string = resourceGroup().location
output results object = {
vm: vm
nic: nic
nsg: nsg
publicIP: publicIP
diagstg: stg
}
var nicName = '${vmName}-nic1'
var nsgName = '${vmName}-nsg'
var diskName = '${vmName}-osdisk-1'
var publicIPName = '${vmName}-public-ip-1'
// get vnet name from vnet id. Workaround, vnet.name is missing.
var vnetName = last(split(vnet.resourceId, '/'))
var subnetId = resourceId(vnet.resourceGroupName, 'Microsoft.Network/virtualNetworks/subnets', vnetName, subnetName)
var storageAccountName = take('${replace(vmName,'-', '')}diag${uniqueString(resourceGroup().id)}', 24)
//var subnetId = resourceId('Microsoft.Network/virtualNetworks/subnets', vnet.name, subnetName)
var imageReference = {
publisher: 'Canonical'
offer: 'UbuntuServer'
sku: '18.04-LTS'
version: 'latest'
}
// https://docs.microsoft.com/en-us/azure/templates/microsoft.compute/virtualmachines
resource vm 'Microsoft.Compute/virtualMachines@2020-06-01' = {
name: vmName
location: location
dependsOn: [
publicIP
]
properties: {
hardwareProfile: {
vmSize: vmSize
}
storageProfile: {
imageReference: imageReference
osDisk: {
osType: 'Linux'
name: diskName
createOption: 'FromImage'
caching: 'ReadWrite'
managedDisk: {
storageAccountType: 'StandardSSD_LRS'
}
diskSizeGB: 30
}
dataDisks: []
}
osProfile: {
computerName: vmName
adminUsername: adminUsername
adminPassword: adminPassword
customData: customData == '' ? null : customData
linuxConfiguration: {
provisionVMAgent: true
}
secrets: []
allowExtensionOperations: true
}
networkProfile: {
networkInterfaces: [
{
id: nic.id
}
]
}
diagnosticsProfile: {
bootDiagnostics: {
enabled: true
storageUri: stg.properties.primaryEndpoints.blob
}
}
}
}
// https://docs.microsoft.com/en-us/azure/templates/microsoft.network/2020-05-01/networkinterfaces
resource nic 'Microsoft.Network/networkInterfaces@2020-05-01' = {
name: nicName
location: location
properties: {
ipConfigurations: [
{
name: 'ipconfig1'
properties: {
subnet: {
id: subnetId
}
privateIPAllocationMethod: 'Dynamic'
publicIPAddress: {
id: publicIP.id
}
}
}
]
networkSecurityGroup: {
id: nsg.id
}
}
}
// https://docs.microsoft.com/en-us/azure/templates/microsoft.network/publicipaddresses
resource publicIP 'Microsoft.Network/publicIPAddresses@2020-05-01' = {
name: publicIPName
location: location
properties: {
publicIPAllocationMethod: 'Dynamic'
publicIPAddressVersion: 'IPv4'
idleTimeoutInMinutes: 4
}
sku: {
name: 'Basic'
}
}
// https://docs.microsoft.com/en-us/azure/templates/microsoft.network/networksecuritygroups
resource nsg 'Microsoft.Network/networkSecurityGroups@2020-05-01' = {
name: nsgName
location: location
properties: {
securityRules: [
]
}
}
// https://docs.microsoft.com/en-us/azure/templates/microsoft.storage/storageaccounts
resource stg 'Microsoft.Storage/storageAccounts@2019-06-01' = {
name: storageAccountName
location: location
kind: 'Storage'
sku: {
name: 'Standard_LRS'
tier: 'Standard'
}
properties: {
networkAcls: {
bypass: 'AzureServices'
virtualNetworkRules: [
{
id: subnetId
action: 'Allow'
}
]
defaultAction: 'Deny'
}
allowBlobPublicAccess: false
minimumTlsVersion: 'TLS1_2'
}
}