-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUbuntu.bicep
More file actions
171 lines (156 loc) · 4.16 KB
/
Ubuntu.bicep
File metadata and controls
171 lines (156 loc) · 4.16 KB
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
@description('Deployment location')
param location string = resourceGroup().location
@description('VM name')
param vmName string = 'caldera-vm'
@description('Admin username for password login')
param adminUsername string = 'azureuser'
@secure()
@description('Admin password for the VM (do not hardcode; supply at deploy time)')
param adminPassword string
@description('VM size')
param vmSize string = 'Standard_B2s'
@description('Expose CALDERA UI port (8888) to the Internet. Recommended: false (use SSH tunnel or Bastion).')
param exposeCalderaToInternet bool = false
@description('CALDERA UI port')
param calderaPort int = 8888
// Networking names
var vnetName = '${vmName}-vnet'
var subnetName = 'default'
var nsgName = '${vmName}-nsg'
var pipName = '${vmName}-pip'
var nicName = '${vmName}-nic'
var osDiskName = '${vmName}-osdisk'
// Cloud-init is stored in repo and embedded at compile time
var cloudInit = base64(loadTextContent('./cloud-init.yml'))
resource nsg 'Microsoft.Network/networkSecurityGroups@2024-05-01' = {
name: nsgName
location: location
properties: {
securityRules: [
{
name: 'Allow-SSH'
properties: {
priority: 1000
access: 'Allow'
direction: 'Inbound'
protocol: 'Tcp'
sourcePortRange: '*'
destinationPortRange: '22'
sourceAddressPrefix: '*'
destinationAddressPrefix: '*'
}
}
{
name: 'Allow-CALDERA'
properties: {
priority: 1010
access: exposeCalderaToInternet ? 'Allow' : 'Deny'
direction: 'Inbound'
protocol: 'Tcp'
sourcePortRange: '*'
destinationPortRange: string(calderaPort)
sourceAddressPrefix: '*'
destinationAddressPrefix: '*'
}
}
]
}
}
resource vnet 'Microsoft.Network/virtualNetworks@2024-05-01' = {
name: vnetName
location: location
properties: {
addressSpace: {
addressPrefixes: [
'10.10.0.0/16'
]
}
subnets: [
{
name: subnetName
properties: {
addressPrefix: '10.10.1.0/24'
networkSecurityGroup: {
id: nsg.id
}
}
}
]
}
}
resource pip 'Microsoft.Network/publicIPAddresses@2024-05-01' = {
name: pipName
location: location
sku: {
name: 'Standard'
}
properties: {
publicIPAllocationMethod: 'Static'
}
}
resource nic 'Microsoft.Network/networkInterfaces@2024-05-01' = {
name: nicName
location: location
properties: {
ipConfigurations: [
{
name: 'ipconfig1'
properties: {
privateIPAllocationMethod: 'Dynamic'
subnet: {
id: vnet.properties.subnets[0].id
}
publicIPAddress: {
id: pip.id
}
}
}
]
}
}
resource vm 'Microsoft.Compute/virtualMachines@2024-07-01' = {
name: vmName
location: location
properties: {
hardwareProfile: {
vmSize: vmSize
}
osProfile: {
computerName: vmName
adminUsername: adminUsername
adminPassword: adminPassword
customData: cloudInit
linuxConfiguration: {
disablePasswordAuthentication: false
}
}
storageProfile: {
imageReference: {
publisher: 'Canonical'
offer: 'ubuntu-24_04-lts'
sku: 'server'
version: 'latest'
}
osDisk: {
name: osDiskName
createOption: 'FromImage'
caching: 'ReadWrite'
managedDisk: {
storageAccountType: 'Premium_LRS'
}
}
}
networkProfile: {
networkInterfaces: [
{
id: nic.id
}
]
}
}
}
output publicIp string = pip.properties.ipAddress
output sshCommand string = 'ssh ${adminUsername}@${pip.properties.ipAddress}'
output calderaAccess string = exposeCalderaToInternet
? 'http://${pip.properties.ipAddress}:${calderaPort}'
: 'Not exposed. Use SSH tunnel: ssh -L ${calderaPort}:localhost:${calderaPort} ${adminUsername}@${pip.properties.ipAddress}'