forked from NixOS/nixops
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathazure-load-balancer.nix
366 lines (317 loc) · 10.7 KB
/
azure-load-balancer.nix
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
{ config, lib, pkgs, uuid, name, resources, ... }:
with lib;
with (import ./lib.nix lib);
let
lbRuleOptions = { config, ... }: {
options = {
frontendInterface = mkOption {
default = "default";
example = "webservers";
type = types.str;
description = "The name of a frontend interface over which this Load Balancing Rule operates.";
};
backendAddressPool = mkOption {
default = "default";
example = "webservers";
type = types.str;
description = "The name of a backend address pool over which this Load Balancing Rule operates.";
};
probe = mkOption {
default = null;
example = "webservers";
type = types.nullOr types.str;
description = "The name of a probe used by this Load Balancing Rule.";
};
protocol = mkOption {
default = "Tcp";
example = "Udp";
type = types.enum [ "Tcp" "Udp" ];
description = "The transport protocol for the external endpoint. Possible values are Udp or Tcp.";
};
frontendPort = mkOption {
example = 80;
type = types.int;
description = ''
The port for the external endpoint.
Port numbers for each Rule must be unique within the Load Balancer.
Possible values range between 1 and 65535, inclusive.
'';
};
backendPort = mkOption {
example = 80;
type = types.int;
description = ''
The port used for internal connections on the endpoint.
Possible values range between 1 and 65535, inclusive.
'';
};
enableFloatingIp = mkOption {
default = false;
example = true;
type = types.bool;
description = ''
Floating IP is pertinent to failover scenarios:
a "floating" IP is reassigned to a secondary server
in case the primary server fails.
Floating IP is required for SQL AlwaysOn.
'';
};
idleTimeout = mkOption {
default = 4;
example = 30;
type = types.int;
description = ''
Specifies the timeout in minutes for the Tcp idle connection.
The value can be set between 4 and 30 minutes.
This property is only used when the protocol is set to <literal>Tcp</literal>.
'';
};
loadDistribution = mkOption {
default = "Default";
example = "SourceIP";
type = types.enum [ "Default" "SourceIP" "SourceIPProtocol" ];
description = ''
Specifies the load balancing distribution type to be used by the Load Balancer Rule.
Possible values are: Default - The load balancer is configured to use a 5 tuple hash
to map traffic to available servers; SourceIP - The load balancer is configured to
use a 2 tuple hash to map traffic to available servers; SourceIPProtocol - The load
balancer is configured to use a 3 tuple hash to map traffic to available servers.
'';
};
};
config = {};
};
probeOptions = { config, ... }: {
options = {
protocol = mkOption {
default = "Tcp";
example = "Http";
type = types.enum [ "Tcp" "Http" ];
description = ''
Specifies the protocol of the probe request.
Possible values are Http or Tcp. If Tcp is specified, a received ACK is required for
the probe to be successful. If Http is specified, a 200 OK response from the specified
URI is required for the probe to be successful.
'';
};
port = mkOption {
example = 80;
type = types.int;
description = ''
Port on which the Probe queries the backend endpoint.
Possible values range from 1 to 65535, inclusive.
'';
};
path = mkOption {
default = null;
example = "/is-up";
type = types.nullOr types.str;
description = ''
The URI used for requesting health status from the backend endpoint.
Used if protocol is set to http.
'';
};
interval = mkOption {
default = 15;
example = 5;
type = types.int;
description = ''
The interval, in seconds, between probes to the backend endpoint for health status.
The minimum allowed value is 5.
'';
};
numberOfProbes = mkOption {
default = 2;
example = 5;
type = types.int;
description = ''
The number of failed probe attempts after which the backend endpoint
is removed from rotation. The default value is 2. NumberOfProbes
multiplied by interval value must be greater or equal to 10.
Endpoints are returned to rotation when at least one probe is successful.
'';
};
};
config = {};
};
frontendInterfaceOptions = { config, ... }: {
options = {
subnet.network = mkOption {
default = null;
example = "my-network";
type = types.nullOr (types.either types.str (resource "azure-virtual-network"));
description = ''
The Azure Resource Id or NixOps resource of
an Azure virtual network that contains the subnet.
'';
};
subnet.name = mkOption {
default = "default";
example = "my-subnet";
type = types.str;
description = ''
The name of the subnet of <literal>network</literal>
in which to obtain the private IP address.
'';
};
privateIpAddress = mkOption {
default = null;
example = "10.10.10.10";
type = types.nullOr types.str;
description = ''
The static private IP address to reserve for the load balancer frontend interface.
The address must be in the address space of <literal>subnet</literal>.
Leave empty to auto-assign.
'';
};
publicIpAddress = mkOption {
default = null;
example = "my-reserved-ip";
type = types.nullOr (types.either types.str (resource "azure-reserved-ip-address"));
description = ''
The Azure Resource Id or NixOps resource of
an Azure reserved IP address resource to use for the frontend interface.
Leave empty to create an internal load balancer interface.
'';
};
};
config = {};
};
natRuleOptions = { config, ... }: {
options = {
frontendInterface = mkOption {
default = "default";
example = "webservers";
type = types.str;
description = "The name of a frontend interface over which this Inbound NAT Rule operates.";
};
protocol = mkOption {
default = "Tcp";
example = "Udp";
type = types.enum [ "Tcp" "Udp" ];
description = "The transport protocol for the external endpoint. Possible values are Udp or Tcp.";
};
frontendPort = mkOption {
example = 80;
type = types.int;
description = ''
The port for the external endpoint.
Port numbers for each Rule must be unique within the Load Balancer.
Possible values range between 1 and 65535, inclusive.
'';
};
backendPort = mkOption {
example = 80;
type = types.int;
description = ''
The port used for internal connections on the endpoint.
Possible values range between 1 and 65535, inclusive.
'';
};
enableFloatingIp = mkOption {
default = false;
example = true;
type = types.bool;
description = ''
Floating IP is pertinent to failover scenarios:
a "floating" IP is reassigned to a secondary server
in case the primary server fails.
Floating IP is required for SQL AlwaysOn.
'';
};
idleTimeout = mkOption {
default = 4;
example = 30;
type = types.int;
description = ''
Specifies the timeout in minutes for the Tcp idle connection.
The value can be set between 4 and 30 minutes.
This property is only used when the protocol is set to <literal>Tcp</literal>.
'';
};
};
config = {};
};
in
{
options = (import ./azure-mgmt-credentials.nix lib "load balancer") // {
name = mkOption {
default = "nixops-${uuid}-${name}";
example = "my-network";
type = types.str;
description = "Name of the Azure load balancer.";
};
resourceGroup = mkOption {
example = "xxx-my-group";
type = types.either types.str (resource "azure-resource-group");
description = "The name or resource of an Azure resource group to create the load balancer in.";
};
location = mkOption {
example = "westus";
type = types.str;
description = "The Azure data center location where the load balancer should be created.";
};
tags = mkOption {
default = {};
example = { environment = "production"; };
type = types.attrsOf types.str;
description = "Tag name/value pairs to associate with the load balancer.";
};
backendAddressPools = mkOption {
default = [ "default" ];
example = [ "website" "db" ];
type = types.listOf types.str;
description = "The list of names of backend address pools to create";
};
frontendInterfaces = mkOption {
default = {};
example = {
default = {
subnet.network = "my-virtual-network";
publicIpAddress = "my-reserved-address";
};
};
type = with types; attrsOf (submodule frontendInterfaceOptions);
description = "An attribute set of frontend network interfaces.";
};
loadBalancingRules = mkOption {
default = {};
example = {
website = {
frontendPort = 80;
backendPort = 8080;
probe = "web";
};
};
type = with types; attrsOf (submodule lbRuleOptions);
description = "An attribute set of load balancer rules.";
};
inboundNatRules = mkOption {
default = {};
example = {
admin-ssh = {
frontendPort = 2201;
backendPort = 22;
};
};
type = with types; attrsOf (submodule natRuleOptions);
description = "An attribute set of inbound NAT rules.";
};
probes = mkOption {
default = {};
example = {
web = {
protocol = "http";
port = 8080;
path = "/is-alive";
};
};
type = with types; attrsOf (submodule probeOptions);
description = "An attribute set of load balancer probes";
};
};
config = {
_type = "azure-load-balancer";
resourceGroup = mkDefault resources.azureResourceGroups.def-group;
};
}