-
Notifications
You must be signed in to change notification settings - Fork 40
/
variables.tf
454 lines (362 loc) · 11.9 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
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
# To pretify the use of this module externally we use maps. Downside of map-usage is that default variables are lost when only a part
# of the map is being defined. This is mitigated by using an extra set of default_* variables
variable "create" {
default = true
}
variable "num_docker_volumes" {
default = 1
}
variable "docker_volumes" {
type = "list"
default = [{
name = "NONAME"
}]
# {
# # these properties are supported as a 'flattened' version of the docker volume configuration:
# # https://www.terraform.io/docs/providers/aws/r/ecs_task_definition.html#docker_volume_configuration
# name = "bla",
# scope == "shared",
# autoprovision = true,
# driver = "foo"
# # these properties are NOT supported, as they are nested maps in the resource's configuration
# # driver_opts = NA
# # labels = NA
# }
}
variable "docker_volume_options" {
type = "map"
default = {}
}
variable "docker_volume_labels" {
type = "map"
default = {}
}
# ecs_cluster_id is the cluster to which the ECS Service will be added.
variable "ecs_cluster_id" {}
variable "allow_terraform_deploy" {
description = "When true, forces task update from Terraform."
default = false
}
# Number of days for the cloudwatch logs for the containers to be retained
variable "log_retention_in_days" {
default = "14"
}
# kms_key for the cloudwatch logs
variable "cloudwatch_kms_key" {
default = ""
}
# Region of the ECS Cluster
variable "region" {}
# With fargate_enabled the launchtype of the service will be FARGATE, otherwise EC2 ( default is false)
variable "fargate_enabled" {
default = false
}
# With awsvpc_enabled the network_mode for the ECS task definition will be awsvpc, defaults to bridge
variable "awsvpc_enabled" {
default = false
}
# scheduling_strategy defaults to REPLICA
variable "scheduling_strategy" {
default = "REPLICA"
}
# Spread tasks over ECS Cluster based on AZ, Instance-id, memory
variable "with_placement_strategy" {
default = false
}
# Extra hosts the ALB needs to make listener_rules for to the ECS target group
variable "custom_listen_hosts" {
default = []
type = "list"
}
# load_balancing_enabled defines if we are using a load balancer for our ecs service
variable "load_balancing_enabled" {
default = false
}
## load_balancing_properties map defines the map for services hooked to a load balancer
variable "load_balancing_properties" {
type = "map"
default = {
/*
Note that since Terraform doesn't support partial map defaults (see
https://github.com/hashicorp/terraform/issues/16517), the default values here
are set in the independent default_load_balancing_properties_* variables
lb_listener_arn is the ALB listener arn for HTTP
lb_listener_arn = ""
lb_listener_arn_https is the ALB listener arn for HTTPS
lb_listener_arn_https = ""
lb_vpc_id is the vpc_id for the target_group to reside in
lb_vpc_id = ""
route53_zone_id is the zone to add a subdomain to
route53_zone_id = ""
health_uri is the health uri to be checked by the ALB
health_uri = "/ping"
unhealthy_threshold is the health uri to be checked by the ALB
unhealthy_threshold = "3"
Do we create listener rules for https
https_enabled = true
Do we want to create a subdomain for the service inside the Route53 zone
create_route53_record = true
*/
}
}
## load_balancing_properties map defines the map for services hooked to a load balancer
variable "default_load_balancing_properties_tg_port" {
description = "This is the port that the container listens on"
default = "80"
}
variable "default_load_balancing_properties_tg_arn" {
description = "This is the target group arn that the container uses"
default = ""
}
variable "default_load_balancing_properties_tg_protocol" {
description = "This is the target group protocol that the container uses. The protocol to use for routing traffic to the targets. Should be one of TCP, HTTP, HTTPS or TLS."
default = "HTTP"
}
variable "default_load_balancing_properties_load_balancer_type" {
description = "This can be application or network"
default = "application"
}
variable "default_load_balancing_properties_lb_listener_arn" {
default = ""
}
variable "default_load_balancing_properties_lb_listener_arn_https" {
default = ""
}
variable "default_load_balancing_properties_lb_vpc_id" {
default = ""
}
variable "default_load_balancing_properties_route53_zone_id" {
default = ""
}
variable "default_load_balancing_properties_health_uri" {
default = "/ping"
}
variable "default_load_balancing_properties_unhealthy_threshold" {
default = "3"
}
variable "default_load_balancing_properties_deregistration_delay" {
default = 300
}
variable "default_load_balancing_properties_https_enabled" {
default = true
}
variable "default_load_balancing_properties_lb_arn" {
default = ""
}
variable "default_load_balancing_properties_route53_record_identifier" {
default = "identifier"
}
# By default we create a NO record to the ALB, the moment terraform can handle CNAME to ALIAS A record changes
# Route53 Alias A will be the default.
# https://github.com/terraform-providers/terraform-provider-aws/issues/5280
variable "default_load_balancing_properties_route53_record_type" {
default = "NONE"
}
variable "default_load_balancing_properties_health_check_grace_period_seconds" {
default = "300"
}
## capacity_properties map defines the capacity properties of the service
variable "capacity_properties" {
type = "map"
default = {
/*
Note that since Terraform doesn't support partial map defaults (see
https://github.com/hashicorp/terraform/issues/16517), the default values here
are set in the independent default_capacity_properties_* variables
desired_capacity is the desired amount of tasks for a service, when autoscaling is used desired_capacity is only used initially
after that autoscaling determins the amount of tasks
desired_capacity = "2"
desired_min_capacity is used when autoscaling is used, it sets the minimum of tasks to be available for this service
desired_min_capacity = "2"
desired_max_capacity is used when autoscaling is used, it sets the maximum of tasks to be available for this service
desired_max_capacity = "5"
deployment_maximum_percent sets the maximum deployment size of the current capacity, 200% means double the amount of current tasks
will be active in case a deployment is happening
deployment_maximum_percent = "200"
deployment_minimum_healthy_percent sets the minimum deployment size of the current capacity, 0% means no tasks need to be running at the moment of
a deployment switch
deployment_minimum_healthy_percent = "0"
*/
}
}
variable "default_capacity_properties_desired_capacity" {
default = "2"
}
variable "default_capacity_properties_desired_min_capacity" {
default = "2"
}
variable "default_capacity_properties_desired_max_capacity" {
default = "2"
}
variable "default_capacity_properties_deployment_maximum_percent" {
default = "200"
}
variable "default_capacity_properties_deployment_minimum_healthy_percent" {
default = "100"
}
# image_url defines the docker image location
variable "container_image" {
default = ""
}
# Container name
variable "container_name" {
default = "app"
}
# cpu defines the needed cpu for the container
variable "container_cpu" {}
# container_memory defines the hard memory limit of the container
variable "container_memory" {}
# container_memory_reservation defines the ECS Memory reservation for this service and Soft/limit
variable "container_memory_reservation" {
default = ""
}
variable "privileged" {
description = "Bool. Run the container with elevated privilege."
default = false
}
# port defines the needed port of the container
variable "container_port" {
default = ""
}
variable "host_port" {
default = ""
}
# Scaling properties holds a map of multiple maps defining scaling policies and alarms
#
#
# [{
# # type is the metric the metric being used for the service
# type = "CPUUtilization"
#
# # direction defines the direction of the scaling, up means more tasks, down is less tasks
# direction = "up"
#
# # evaluation_periods how many observation points are needed for a scaling decision
# evaluation_periods = "2"
#
#
# # observation_period is the number of seconds one statistic is measured
# observation_period = "300"
#
# # statistic defines the type of statistic for measuring SampleCount, Average, Sum, Minimum, Maximum
# statistic = "Average"
#
# # threshold defines the value which is needed to surpass, given the direction
# threshold = "89"
#
# # Cooldown defines the amount of seconds in which another scaling is disabled after a succesful scaling action
# cooldown = "900"
#
# # Adjustment_type defines the type of adjustment, can either be absolute or relative : ChangeInCapacity, ExactCapacity, and PercentChangeInCapacity.
# adjustment_type = "ChangeInCapacity"
#
# # scaling_adjustment defines the amount to scale, can be a postive or negative number or percentage
# scaling_adjustment = "1"
# },]
variable "scaling_properties" {
default = []
}
# container_envvars defines extra container env vars, list of maps
# { key = val,key2= val2}
variable "container_envvars" {
default = {}
}
####
variable "name" {
description = "The name of the project, must be unique ."
}
# Whether to provide access to the supplied kms_keys. If no kms keys are
# passed, set this to false.
variable "kms_enabled" {
default = true
}
# List of KMS keys the task has access to
variable "kms_keys" {
default = []
}
# Whether to provide access to the supplied ssm_paths. If no ssm paths are
# passed, set this to false.
variable "ssm_enabled" {
default = true
}
# List of SSM Paths the task has access to
variable "ssm_paths" {
default = []
}
# AWSVPC ( FARGATE ) need subnets to reside in
variable "awsvpc_subnets" {
default = []
}
# AWSVPC ( FARGATE ) need awsvpc_security_group_ids attached to the task
variable "awsvpc_security_group_ids" {
default = []
}
# S3 Read-only paths the Task has access to
variable "s3_ro_paths" {
default = []
}
# S3 Read-write paths the Task has access to
variable "s3_rw_paths" {
default = []
}
# A Docker volume to add to the task
variable "docker_volume" {
type = "map"
default = {}
# {
# # these properties are supported as a 'flattened' version of the docker volume configuration:
# # https://www.terraform.io/docs/providers/aws/r/ecs_task_definition.html#docker_volume_configuration
# name = "bla",
# scope == "shared",
# autoprovision = true,
# driver = "foo"
# # these properties are NOT supported, as they are nested maps in the resource's configuration
# # driver_opts = NA
# # labels = NA
# }
}
# list of host paths to add as volumes to the task
variable "host_path_volumes" {
type = "list"
default = []
# {
# name = "service-storage",
# host_path = "/foo"
# },
}
variable "host_path_volume" {
type = "map"
default = {}
}
# list of mount points to add to every container in the task
variable "mountpoints" {
type = "list"
default = []
# {
# source_volume = "service-storage",
# container_path = "/foo",
# read_only = "false"
# },
}
variable "enable_service_discovery" {
default = "false"
}
# The service discovery namespace arn to register the services against
variable "service_discovery_namespace_arn" {
default = ""
}
# (Optional) The container name value, already specified in the task definition, to be used for your service discovery service
variable "service_discovery_container_name" {
default = ""
}
variable "tags" {
description = "A map of tags to apply to all taggable resources"
type = "map"
default = {}
}
locals {
name_map = {
"Name" = "${var.container_name}"
}
tags = "${merge(var.tags, local.name_map)}"
}