forked from neillturner/terraform-aws-autospotting
-
-
Notifications
You must be signed in to change notification settings - Fork 35
/
variables.tf
414 lines (356 loc) · 13.5 KB
/
variables.tf
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
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
# Autospotting configuration
variable "autospotting_allowed_instance_types" {
description = <<EOF
Comma separated list of allowed instance types for spot requests,
in case you want to exclude specific types (also support globs).
Example: 't2.*,m4.large'
Using the 'current' magic value will only allow the same type as the
on-demand instances set in the group's launch configuration.
EOF
default = ""
}
variable "autospotting_allow_parallel_instance_replacements" {
type = string
description = <<EOF
Controls whether AutoSpotting should allow parallel instance replacements
or force them to happen in sequence. This is by default disabled because
it may require the increase of the Maximum capacity of the autoscaling
group to double the desired capacity, and/or service quota increases for
EC2 instances.
EOF
default = "true"
validation {
condition = contains(["true", "false"], var.autospotting_allow_parallel_instance_replacements)
error_message = "Valid value is one of the following: true, false."
}
}
variable "autospotting_automated_instance_data_update" {
description = <<EOF
Controls whether AutoSpotting should automatically update its embedded
instance type data. This doesn't bring benefits for recently released
builds and is slowing down the Lambda execution, but it may be useful
later if you want to add support for newer instance types without
updating AutoSpotting.
EOF
type = string
default = "false"
validation {
condition = contains(["true", "false"], var.autospotting_automated_instance_data_update)
error_message = "Valid value is one of the following: true, false."
}
}
variable "autospotting_consider_ebs_bandwidth" {
type = string
description = <<EOF
Controls whether AutoSpotting considers EBS Bandwidth when comparing
instance types in order to determine compatibility with other instance
types, default: false. Enabling this flag will reduce diversfication
to only instance types offering at least as much EBS bandwidth as the
initial instance type.
EOF
default = "false"
validation {
condition = contains(["true", "false"], var.autospotting_consider_ebs_bandwidth)
error_message = "Valid value is one of the following: true, false."
}
}
variable "autospotting_cron_schedule_state" {
description = <<EOF
Controls whether or not to run AutoSpotting within a time interval
given in the 'autospotting_cron_schedule' parameter. Setting this to 'off'
would make it run only outside the defined interval. This is a global value
that can be overridden on a per-AutoScaling-group basis using the
'autospotting_cron_schedule_state' tag set on the AutoScaling group
Example: 'off'
EOF
default = "on"
}
variable "autospotting_cron_schedule" {
description = <<EOF
Restrict AutoSpotting to run within a time interval given as a
simplified cron-like rule format restricted to hours and days of week.
Example: '9-18 1-5' would run it during the work-week and only within
the usual 9-18 office hours.
This is a global value that can be
overridden on a per-group basis using the 'autospotting_cron_schedule'
tag set on the AutoScaling group. The default value '* *' makes it run
at all times.
EOF
default = "* *"
}
variable "autospotting_cron_timezone" {
description = <<EOF
Sets the timezone in which to check the CronSchedule.
Example: If the timezone is set to 'UTC' and the CronSchedule is '9-18 1-5'
it would start the interval at 9AM UTC, with the timezone set to 'Europe/London'
it would start the interval at 9AM BST (10am UTC) or 9AM GMT (9AM UTC)
depending on daylight savings.
EOF
default = "UTC"
}
variable "autospotting_disable_instance_rebalance_recommendation" {
description = <<EOF
Disables the handling of instance rebalancing events, only handling the 2 minute
termination events.
Pros:
- handling these give earlier instance replacements than the usual 2 minute notice,
typically between 5-10 minutes.
- they allow the execution of termination lifecycle hooks.
Cons:
- These events fire for all instances in a given capacity pool and have been seen
to cause multiple parallel instance replacements on groups with multiple instances
per AZ.
- sometimes the instances aren't terminated, resulting in extra churn.
Recommendation: set to true(disabled) on large groups, which have multiple Spot
instances per AZ, to avoid multiple instance replacements in parallel.
EOF
default = "false"
validation {
condition = can(regex("^(true|false)$", var.autospotting_disable_instance_rebalance_recommendation))
error_message = "Allowed values are 'true' or 'false'."
}
}
variable "autospotting_disallowed_instance_types" {
description = <<EOF
Comma separated list of disallowed instance types for spot requests,
in case you want to exclude specific types (also support globs).
Example: 't2.*,m4.large'
EOF
default = ""
}
variable "notify_email_addresses" {
description = <<EOF
Addresses to receive notifications for AutoSpotting actions and savings reports.
EOF
type = list(string)
}
variable "autospotting_enable_instance_rebalance_recommendation" {
description = <<EOF
Enables handling of instance rebalance recommendation events.
EOF
type = string
default = "false"
validation {
condition = contains(["true", "false"], var.autospotting_enable_instance_rebalance_recommendation)
error_message = "Valid value is one of the following: true, false."
}
}
variable "autospotting_instance_types_per_az" {
type = number
default = 1
description = "Number of instance types to diversify over for each availability zone. Can be overridden on a per-group basis using the tag 'autospotting_number_of_instance_types_per_az'."
}
variable "autospotting_min_on_demand_number" {
description = "Minimum on-demand instances to keep in absolute value"
type = number
default = 0
}
variable "autospotting_min_on_demand_percentage" {
description = "Minimum on-demand instances to keep in percentage"
type = number
default = "0.0"
}
variable "autospotting_on_demand_price_multiplier" {
description = "Multiplier for the on-demand price"
type = number
default = "1.0"
}
variable "autospotting_prioritized_instance_types_bias" {
description = <<EOF
Controls the ordering of instance types when using the capacity-optimized-prioritized
Spot allocation strategy. By default, using the 'lowest_price' bias it sorts instances by
Spot price, giving a softer preference than the 'lowest_price' Spot allocation strategy.
Alternatively, you can prefer newer instance types by using the 'prefer_newer_generations'
bias, which still orders instance types by price but penalizes instances from older
generations by adding 10% to their hourly price for each older generation when considering
them for the sorted list. For example, a C5 instance type will be penalized by 10% over C6i,
while a C4 will be penalized by 20%.
EOF
type = string
default = "prefer_newer_generations"
validation {
condition = contains(["prefer_newer_generations", "lowest_price"], var.autospotting_prioritized_instance_types_bias)
error_message = "Valid value is one of the following: prefer_newer_generations, lowest_price."
}
}
variable "autospotting_savings_reports_frequency" {
type = string
description = <<EOF
Controls the frequency of the saving reports. Defaults to sending them daily.
EOF
validation {
condition = contains(["daily", "weekly", "monthly", "never"], var.autospotting_savings_reports_frequency)
error_message = "Valid value is one of the following: daily, weekly, monthly, never."
}
default = "daily"
}
variable "autospotting_spot_allocation_strategy" {
type = string
description = <<EOF
Controls the Spot allocation strategy for launching Spot instances.
Allowed options:
'capacity-optimized-prioritized' (default), 'capacity-optimized',
'lowest-price'. Further information on this is available at
https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-fleet-allocation-strategy.html"
EOF
validation {
condition = contains(["capacity-optimized-prioritized", "capacity-optimized", "lowest-price"], var.autospotting_spot_allocation_strategy)
error_message = "Valid value is one of the following: capacity-optimized-prioritized, capacity-optimized, lowest-price."
}
default = "capacity-optimized-prioritized"
}
variable "autospotting_spot_price_buffer_percentage" {
description = "Percentage above the current spot price to place the bid"
default = "10.0"
}
variable "autospotting_termination_notification_action" {
description = <<EOF
Action to do when receiving a Spot Instance Termination Notification.
Must be one of 'auto' (terminate if lifecycle hook is defined, or else
detach) [default], 'terminate' (lifecycle hook triggered), 'detach'
(lifecycle hook not triggered)
Allowed values: auto | detach | terminate
EOF
default = "auto"
}
variable "autospotting_bidding_policy" {
description = "Bidding policy for the spot bid"
default = "normal"
}
variable "autospotting_regions_enabled" {
description = "Regions in which autospotting is enabled"
default = []
}
variable "autospotting_tag_filters" {
description = <<EOF
Tags to filter which ASGs autospotting considers. If blank
by default this will search for asgs with spot-enabled=true (when in opt-in
mode) and will skip those tagged with spot-enabled=false when in opt-out
mode.
You can set this to many tags, for example:
spot-enabled=true,Environment=dev,Team=vision
EOF
default = ""
}
variable "autospotting_tag_filtering_mode" {
description = <<EOF
Controls the tag-based ASG filter. Supported values: 'opt-in' or 'opt-out'.
Defaults to opt-in mode, in which it only acts against the tagged groups. In
opt-out mode it works against all groups except for the tagged ones.
EOF
default = "opt-in"
}
# Lambda configuration
variable "lambda_source_ecr" {
description = <<EOF
ECR repository that stores the AutoSpotting Docker image used by
Lambda. The default value is using the AWS Marketplace ECR repository
and only works if you purchased AutoSpotting through the AWS
Marketplace. If you built it yourself, you need to override this value
with the URL of your own ECR repository that contains the AutoSpotting
Docker image.
EOF
default = "709825985650.dkr.ecr.us-east-1.amazonaws.com"
}
variable "lambda_source_image" {
description = "The Docker image used for the Lambda function"
default = "cloudutil/autospotting"
}
variable "lambda_source_image_tag" {
description = "The version of the Docker image used for the Lambda function"
default = "stable-1.3.0-0"
}
variable "lambda_memory_size" {
description = "Memory size allocated to the lambda run"
default = 512
}
variable "lambda_cpu_architecture" {
description = <<EOF
The CPU architecture to use for running the AutoSpotting Docker image.
EOF
type = string
default = "x86_64"
validation {
condition = contains(["arm64", "x86_64"], var.lambda_cpu_architecture)
error_message = "Valid value is one of the following: arm64, x86_64."
}
}
variable "lambda_use_public_ecr" {
type = bool
description = "Use a public ECR repo"
default = false
}
variable "lambda_timeout" {
description = "Timeout after which the lambda timeout"
default = 300
}
variable "lambda_run_frequency" {
description = "How frequent should lambda run"
default = "rate(30 minutes)"
}
variable "lambda_tags" {
description = "Tags to be applied to the Lambda function"
default = {
# You can add more values below
Name = "autospotting"
}
}
# Label configuration
variable "label_context" {
description = "Used to pass in label module context"
type = object({
namespace = string
environment = string
stage = string
name = string
enabled = bool
delimiter = string
attributes = list(string)
label_order = list(string)
tags = map(string)
additional_tag_map = map(string)
regex_replace_chars = string
label_key_case = string
label_value_case = string
})
default = {
namespace = ""
environment = ""
stage = ""
name = ""
enabled = true
delimiter = ""
attributes = []
label_order = []
tags = {}
additional_tag_map = {}
regex_replace_chars = ""
label_key_case = "lower"
label_value_case = "lower"
}
}
variable "use_existing_iam_role" {
description = "Boolean flag to indicate whether to use an existing IAM role or create a new one for the Lambda function"
type = bool
default = false
}
variable "existing_iam_role_arn" {
description = "ARN of an existing IAM role to use for the Lambda function"
type = string
default = ""
}
variable "permissions_boundary_arn" {
description = "ARN of a permissions boundary resource"
type = string
default = ""
}
variable "use_existing_subnets" {
description = "Boolean flag to indicate whether to use existing subnets or create new ones for the Lambda function"
type = bool
default = false
}
variable "existing_subnets" {
description = "List of existing subnets to use for the Lambda function"
type = list(string)
default = []
}