-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.bicep
183 lines (157 loc) · 6.51 KB
/
main.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
targetScope = 'subscription'
////////////////////////////////////////////////////////////////////////////////
// Required parameters
////////////////////////////////////////////////////////////////////////////////
param location string
@description('Name of the Azure virtual network where the load balancer and virtual machines needs to be deployed.')
param virtualNetworkName string
@description('Name of the virtual network subnet where the load balancers should be created. If not specified, will use the same subnet as the virtual machines.')
param lbSubnetName string = ''
@description('Name of the virtual network subnet where the virtual machines should be created.')
param vmSubnetName string
@description('The name of the Resource Group containing the Virtual Network.')
param virtualNetworkResourceGroup string
@description('Name of the Resource Group where the existing Log Analyics/Sentinel workspace resides.')
param workspaceResourceGroup string
@description('Name of the existing Log Analytics/Sentinel workspace.')
param workspaceName string
@secure()
param adminPassword string
////////////////////////////////////////////////////////////////////////////////
// Parameters with acceptable defaults
////////////////////////////////////////////////////////////////////////////////
param environment string = 'prod'
@description('Tags that will be added to the resource group.')
param tags object = {}
@description('A value to indicate the deployment number.')
@minValue(0)
@maxValue(99)
param sequence int = 1
@minValue(1)
@maxValue(4)
param vmCount int = 2
@description('The Linux distribution to use for the virtual machines.')
@allowed([
'Ubuntu'
'RHEL'
])
param os string = 'Ubuntu'
param vmSize string = 'Standard_D4s_v4'
param osDiskSize int = 256
param scriptsLocation string = 'https://raw.githubusercontent.com/SvenAelterman/AzSentinel-syslogfwd-HA/main/scripts/'
param deploymentTime string = utcNow()
param deploymentNamePrefix string = 'syslogfwd-HA-'
// Default naming convention from the Microsoft Cloud Adoption Framework
// See https://docs.microsoft.com/en-us/azure/cloud-adoption-framework/ready/azure-best-practices/resource-naming
// {0} is a placeholder for the resource type abbreviation (e.g., "lbi")
// {1} is a placeholder for the sequence (e.gl, "01" or "02")
// See https://docs.microsoft.com/en-us/azure/cloud-adoption-framework/ready/azure-best-practices/resource-abbreviations
@description('Format string of the resource names.')
param resourceNameFormat string = '{0}-syslogfwd-${environment}-${location}-{1}'
param authenticationType string = 'password'
////////////////////////////////////////////////////////////////////////////////
// VARIABLES
////////////////////////////////////////////////////////////////////////////////
var sequenceFormatted = format('{0:00}', sequence)
var osDetails = {
Ubuntu: {
imageReference: {
publisher: 'canonical'
offer: '0001-com-ubuntu-server-focal'
sku: '20_04-lts'
version: 'latest'
}
configScriptName: 'ubuntu.sh'
}
RHEL: {
imageReference: {
publisher: 'RedHat'
offer: 'RHEL'
sku: '8_4'
version: 'latest'
}
configScriptName: 'redhat.sh'
}
}
var workspaceId = reference(logAnalytics.id, '2015-11-01-preview').customerId
var workspaceKey = listKeys(logAnalytics.id, '2015-11-01-preview').primarySharedKey
////////////////////////////////////////////////////////////////////////////////
// RESOURCES
////////////////////////////////////////////////////////////////////////////////
// For verification that it exists only
resource vnet 'Microsoft.Network/virtualNetworks@2021-02-01' existing = {
name: virtualNetworkName
scope: resourceGroup(virtualNetworkResourceGroup)
}
resource logAnalytics 'Microsoft.OperationalInsights/workspaces@2021-06-01' existing = {
name: workspaceName
scope: resourceGroup(workspaceResourceGroup)
}
// Create resource group
resource targetResourceGroup 'Microsoft.Resources/resourceGroups@2021-04-01' = {
name: format(resourceNameFormat, 'rg', sequenceFormatted)
location: location
tags: tags
}
// Create an internal load balancer if more than 1 VM is to be created
module loadBalancerInternal 'lbi.bicep' = if (vmCount > 1) {
name: '${deploymentNamePrefix}lbi-${deploymentTime}'
scope: targetResourceGroup
params: {
location: location
subnetName: empty(lbSubnetName) ? vmSubnetName : lbSubnetName
resourceNameFormat: resourceNameFormat
sequence: sequence
virtualNetworkName: virtualNetworkName
virtualNetworkResourceGroup: virtualNetworkResourceGroup
}
}
// Create an external load balancer if more than 1 VM is to be created
module loadBalancerExternal 'lbe.bicep' = if (vmCount > 1) {
name: '${deploymentNamePrefix}lbe-${deploymentTime}'
scope: targetResourceGroup
params: {
location: location
resourceNameFormat: resourceNameFormat
sequence: sequence
}
}
// Deploy an availability set and proximity placement group
module availabilitySet 'avail.bicep' = {
name: '${deploymentNamePrefix}avail-${deploymentTime}'
scope: targetResourceGroup
params: {
location: location
resourceNameFormat: resourceNameFormat
sequence: sequence
}
}
// Call VM module
module vm 'vm-syslogfwd.bicep' = [for i in range(sequence, vmCount): {
name: '${deploymentNamePrefix}vm-${i}-${deploymentTime}'
scope: targetResourceGroup
params: {
osDetail: osDetails[os]
virtualNetworkName: virtualNetworkName
virtualNetworkResourceGroup: virtualNetworkResourceGroup
subnetName: vmSubnetName
osDiskSize: osDiskSize
sequence: i
adminPasswordOrKey: adminPassword
resourceNameFormat: resourceNameFormat
location: location
vmSize: vmSize
workspaceId: workspaceId
workspaceKey: workspaceKey
scriptsLocation: scriptsLocation
lbiBackendAddressPoolId: vmCount > 1 ? loadBalancerInternal.outputs.backendAddressPoolId : ''
lbeBackendAddressPoolId: vmCount > 1 ? loadBalancerExternal.outputs.backendAddressPoolId : ''
avsetId: availabilitySet.outputs.avsetId
authenticationType: authenticationType
}
}]
// LATER: VM Backup!
output configScriptUrlUsed string = vm[0].outputs.scriptUrlUsed
output virtualMachineIPs array = [for i in range(0, vmCount): vm[i].outputs.vmIP]
output lbiIP string = vmCount > 1 ? loadBalancerInternal.outputs.frontendIP : 'N/A'
output publicIP string = vmCount > 1 ? loadBalancerExternal.outputs.publicIP : 'N/A'