-
Notifications
You must be signed in to change notification settings - Fork 19
/
variables.tf
136 lines (115 loc) · 4.29 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
variable "cluster_name" {
description = "Cluster name."
}
variable "nodes_with_public_ip" {
description = "Assign public IP addresses to ECS cluster nodes. Useful when an ECS cluster hosted in internet facing networks."
default = false
}
variable "trusted_cidr_blocks" {
description = "List of trusted subnets CIDRs with hosts that should connect to the cluster. E.g., subnets with ALB and bastion hosts."
type = list(string)
default = [""]
}
variable "instance_types" {
description = "ECS node instance types. Maps of pairs like `type = weight`. Where weight gives the instance type a proportional weight to other instance types."
type = map(any)
default = {
"t3a.small" = 2
}
}
variable "protect_from_scale_in" {
description = "The autoscaling group will not select instances with this setting for termination during scale in events."
default = true
}
variable "asg_min_size" {
description = "The minimum size the auto scaling group (measured in EC2 instances)."
default = 0
}
variable "asg_max_size" {
description = "The maximum size the auto scaling group (measured in EC2 instances)."
default = 100
}
variable "spot" {
description = "Choose should we use spot instances or on-demand to populate ECS cluster."
type = bool
default = false
}
variable "security_group_ids" {
description = "Additional security group IDs. Default security group would be merged with the provided list."
default = []
}
variable "subnets_ids" {
description = "IDs of subnets. Use subnets from various availability zones to make the cluster more reliable."
type = list(string)
}
variable "target_capacity" {
description = "The target utilization for the cluster. A number between 1 and 100."
default = "100"
}
variable "user_data" {
description = "A shell script will be executed at once at EC2 instance start."
default = ""
}
variable "ebs_disks" {
description = "A list of additional EBS disks."
type = map(string)
default = {}
}
variable "on_demand_base_capacity" {
description = "The minimum number of on-demand EC2 instances."
default = 0
}
variable "lifecycle_hooks" {
description = "A list of lifecycle hook actions. See details at https://docs.aws.amazon.com/autoscaling/ec2/userguide/lifecycle-hooks.html."
type = list(object({
name = string
lifecycle_transition = string
default_result = string
heartbeat_timeout = number
role_arn = string
notification_target_arn = string
notification_metadata = string
}))
default = []
}
variable "arm64" {
description = "ECS node architecture. Default is `amd64`. You can change it to `arm64` by activating this flag. If you do, then you should use corresponding instance types."
type = bool
default = false
}
variable "enabled_default_capacity_provider" {
type = bool
default = true
}
data "aws_subnet" "default" {
id = local.subnets_ids[0]
}
data "aws_ssm_parameter" "ecs_ami" {
name = "/aws/service/ecs/optimized-ami/amazon-linux-2/recommended/image_id"
}
data "aws_ssm_parameter" "ecs_ami_arm64" {
name = "/aws/service/ecs/optimized-ami/amazon-linux-2/arm64/recommended/image_id"
}
locals {
ami_id = var.arm64 ? data.aws_ssm_parameter.ecs_ami_arm64.value : data.aws_ssm_parameter.ecs_ami.value
asg_max_size = var.asg_max_size
asg_min_size = var.asg_min_size
ebs_disks = var.ebs_disks
instance_types = var.instance_types
lifecycle_hooks = var.lifecycle_hooks
name = replace(var.cluster_name, " ", "_")
on_demand_base_capacity = var.on_demand_base_capacity
protect_from_scale_in = var.protect_from_scale_in
sg_ids = distinct(concat(var.security_group_ids, [aws_security_group.ecs_nodes.id]))
public = var.nodes_with_public_ip
spot = var.spot == true ? 0 : 100
subnets_ids = var.subnets_ids
target_capacity = var.target_capacity
trusted_cidr_blocks = var.trusted_cidr_blocks
user_data = var.user_data == "" ? [] : [var.user_data]
vpc_id = data.aws_subnet.default.vpc_id
tags = {
Name = var.cluster_name,
Module = "ECS Cluster"
}
}