-
Notifications
You must be signed in to change notification settings - Fork 0
/
factorio.bicep
153 lines (137 loc) · 3.88 KB
/
factorio.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
@description('The number of CPU cores to allocate to the Factorio server (in vCPUs).')
param cpuCores int = 4
@description('The amount of memory to allocate to the Factorio server (in GB).')
param memoryInGb int = 4
@description('The name of the game - should be unique for different Factorio games.')
@minLength(4)
@maxLength(12)
param gameName string
@description('The RCON password for the Factorio server (optional).')
param rconPass string = ''
@description('The azure location where Factorio should be hosted.')
param location string = resourceGroup().location
@description('The version of the Factorio server to create.')
param factorioVersion string = 'stable'
var storageAccountName = 'gameservers${uniqueString(resourceGroup().id)}'
@description('Storage Account for all Game Servers')
resource storageAccount 'Microsoft.Storage/storageAccounts@2021-09-01' = {
name: storageAccountName
location: location
kind: 'StorageV2'
sku: {
name: 'Standard_LRS'
}
properties: {
allowBlobPublicAccess: false
accessTier: 'Hot'
}
}
/*
//For future use, in splitting bicep files apart
resource storageAccount 'Microsoft.Storage/storageAccounts@2021-09-01' existing = {
name: storageAccountName
}
//*/
@description('File Share for Factorio Game')
resource fileShare 'Microsoft.Storage/storageAccounts/fileServices/shares@2021-09-01' = {
name: '${storageAccount.name}/default/factorio-${gameName}-savedata'
properties: {
shareQuota: 1
}
}
@description('Generate Factorio RCON password file')
resource generateRconPassword 'Microsoft.Resources/deploymentScripts@2020-10-01' = if (!empty(rconPass)) {
name: 'script-generate-factorio-rcon-password'
location: location
kind:'AzureCLI'
properties: {
azCliVersion: '2.9.1'
retentionInterval: 'PT1H'
cleanupPreference: 'Always'
environmentVariables: [
{
name: 'AZURE_STORAGE_ACCOUNT'
value: storageAccount.name
}
{
name: 'AZURE_STORAGE_KEY'
secureValue: storageAccount.listKeys().keys[0].value
}
]
scriptContent: 'echo "${rconPass}" > rconpw && az storage file upload --source ./rconpw --share-name factorio-${gameName}-savedata --path \\config\\'
}
}
@description('Contains the port mappings for the Factorio server.')
var gamePorts = empty(rconPass) ? [
{
port: 34197
protocol: 'UDP'
}
] : [
{
port: 27015
protocol: 'TCP'
}
{
port: 34197
protocol: 'UDP'
}
]
@description('Factorio Server for Game via Container Instances')
resource containerGroup 'Microsoft.ContainerInstance/containerGroups@2021-09-01' = {
name: 'factorio-${gameName}'
location: location
properties: {
containers: [
{
name: 'factorio-server-${gameName}'
properties: {
image: 'factoriotools/factorio:${factorioVersion}'
environmentVariables:[
{
name: 'GENERATE_NEW_SAVE'
value: 'true'
}
{
name: 'SAVE_NAME'
value: 'save-${gameName}'
}
]
ports: gamePorts
resources: {
requests: {
cpu: cpuCores
memoryInGB: memoryInGb
}
}
volumeMounts: [
{
name: 'savedata'
mountPath: '/factorio'
readOnly: false
}
]
}
}
]
osType: 'Linux'
restartPolicy: 'OnFailure'
ipAddress: {
type: 'Public'
ports: gamePorts
}
volumes: [
{
name: 'savedata'
azureFile: {
readOnly: false
shareName: 'factorio-${gameName}-savedata'
storageAccountName: storageAccount.name
storageAccountKey: storageAccount.listKeys().keys[0].value
}
}
]
}
}
output containerIPv4Address string = containerGroup.properties.ipAddress.ip
output rcon string = rconPass