-
Notifications
You must be signed in to change notification settings - Fork 0
/
resources.bicep
executable file
·196 lines (187 loc) · 5.53 KB
/
resources.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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
// Valheim
param valheim_world string = 'HelloWorld'
@secure()
param valheim_server_password string
// VM
param virtualMachine_name string = 'valheim-server'
param virtualMachine_adminUserName string = 'azureuser'
@secure()
param virtualMachine_sshPublicKey string = ''
// Networking
param publicIPAddress_name string = 'valheim-server-ip'
param virtualNetwork_name string = 'valheim-vnet'
param networkSecurityGroup_name string = 'valheim-server-nsg'
param networkSecurityGroup_sshAcceptedSources array = [] // default: will not add security rule for port 22
param networkSecurityGroup_valheimAcceptedSources array = [] // default: will add security rule to allow any sources
param networkInterface_name string = 'valheim-server-nic'
resource virtualMachines_valheim_server_name_resource 'Microsoft.Compute/virtualMachines@2021-07-01' = {
name: virtualMachine_name
location: resourceGroup().location
properties: {
hardwareProfile: {
vmSize: 'Standard_B4ms'
}
storageProfile: {
imageReference: {
publisher: 'canonical'
offer: '0001-com-ubuntu-server-focal'
sku: '20_04-lts-gen2'
version: 'latest'
}
osDisk: {
osType: 'Linux'
name: '${virtualMachine_name}_osDisk'
createOption: 'FromImage'
caching: 'ReadWrite'
managedDisk: {
storageAccountType: 'Standard_LRS'
}
deleteOption: 'Delete'
}
}
osProfile: {
computerName: virtualMachine_name
adminUsername: virtualMachine_adminUserName
linuxConfiguration: {
disablePasswordAuthentication: true
ssh: empty(virtualMachine_sshPublicKey) ? null : {
publicKeys: [
{
path: '/home/${virtualMachine_adminUserName}/.ssh/authorized_keys'
keyData: virtualMachine_sshPublicKey
}
]
}
provisionVMAgent: true
patchSettings: {
patchMode: 'ImageDefault'
assessmentMode: 'ImageDefault'
}
}
customData: base64(replace(replace(loadTextContent('cloud-init.cfg'), '{{VALHEIM_SERVER_PASSWORD}}', '${valheim_server_password}'), '{{VALHEIM_WORLD}}', '${valheim_world}'))
}
networkProfile: {
networkInterfaces: [
{
id: networkInterface.id
}
]
}
diagnosticsProfile: {
bootDiagnostics: {
enabled: true
}
}
}
}
resource publicIPAddress 'Microsoft.Network/publicIPAddresses@2021-05-01' = {
name: publicIPAddress_name
location: resourceGroup().location
sku: {
name: 'Basic'
tier: 'Regional'
}
properties: {
publicIPAddressVersion: 'IPv4'
publicIPAllocationMethod: 'Dynamic'
idleTimeoutInMinutes: 4
}
}
var subnet_name = 'default'
var subnet_properties = {
addressPrefix: '10.0.0.0/24'
delegations: []
privateEndpointNetworkPolicies: 'Enabled'
privateLinkServiceNetworkPolicies: 'Enabled'
}
resource virtualNetwork_subnet_default 'Microsoft.Network/virtualNetworks/subnets@2021-05-01' = {
parent: virtualNetwork
name: subnet_name
properties: subnet_properties
}
resource virtualNetwork 'Microsoft.Network/virtualNetworks@2021-05-01' = {
name: virtualNetwork_name
location: resourceGroup().location
properties: {
addressSpace: {
addressPrefixes: [
'10.0.0.0/16'
]
}
subnets: [
{
name: subnet_name
properties: subnet_properties
}
]
virtualNetworkPeerings: []
enableDdosProtection: false
}
}
resource networkSecurityGroup 'Microsoft.Network/networkSecurityGroups@2021-05-01' = {
name: networkSecurityGroup_name
location: resourceGroup().location
properties: {
securityRules: concat(empty(networkSecurityGroup_sshAcceptedSources) ? [] : [
{
name: 'SSH'
properties: {
protocol: 'Tcp'
sourcePortRange: '*'
destinationPortRange: '22'
sourceAddressPrefixes: networkSecurityGroup_sshAcceptedSources
destinationAddressPrefix: '*'
access: 'Allow'
priority: 100
direction: 'Inbound'
}
}
], [
{
name: 'ValheimServer'
properties: {
protocol: 'Udp'
sourcePortRange: '*'
destinationPortRange: '2456'
sourceAddressPrefix: empty(networkSecurityGroup_valheimAcceptedSources) ? '*' : null
sourceAddressPrefixes: empty(networkSecurityGroup_valheimAcceptedSources) ? null : networkSecurityGroup_valheimAcceptedSources
destinationAddressPrefix: '*'
access: 'Allow'
priority: 110
direction: 'Inbound'
}
}
])
}
}
resource networkInterface 'Microsoft.Network/networkInterfaces@2021-05-01' = {
name: networkInterface_name
location: resourceGroup().location
properties: {
ipConfigurations: [
{
name: 'primary'
properties: {
privateIPAddress: '10.0.0.4'
privateIPAllocationMethod: 'Dynamic'
publicIPAddress: {
id: publicIPAddress.id
}
subnet: {
id: virtualNetwork_subnet_default.id
}
primary: true
privateIPAddressVersion: 'IPv4'
}
}
]
dnsSettings: {
dnsServers: []
}
enableAcceleratedNetworking: false
enableIPForwarding: false
networkSecurityGroup: {
id: networkSecurityGroup.id
}
}
}