-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathecs_container_instances.tf
63 lines (55 loc) · 1.78 KB
/
ecs_container_instances.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
data "template_file" "user_data" {
count = var.ecs_launch_type == "FARGATE" ? 0 : 1
template = file("${path.module}/templates/user_data.sh")
vars = {
cluster_name = "${var.name}-cluster"
dag_s3_bucket = var.dag_s3_bucket
dag_s3_key = var.dag_s3_key
region = var.region
custom_user_data = var.custom_user_data
airflow_home = var.airflow_home
}
}
resource "aws_launch_configuration" "ecs" {
count = var.ecs_launch_type == "FARGATE" ? 0 : 1
name_prefix = "lc-${var.name}"
image_id = var.ecs_ami_id
instance_type = var.ecs_instance_type
user_data = data.template_file.user_data[0].rendered
key_name = var.key_name
iam_instance_profile = aws_iam_instance_profile.airflow-task-definition-execution-profile.name
security_groups = concat([aws_security_group.sg_airflow_internal.id], var.container_instance_sg_ids)
lifecycle {
create_before_destroy = true
}
}
resource "aws_autoscaling_group" "ecs" {
count = var.ecs_launch_type == "FARGATE" ? 0 : 1
name = "autoscaling-${var.name}"
launch_configuration = aws_launch_configuration.ecs[0].name
vpc_zone_identifier = var.private_subnet_ids
min_size = 2
max_size = 2
lifecycle {
create_before_destroy = true
}
tag {
key = "Name"
value = "${var.name}-ecs-asg"
propagate_at_launch = true
}
tag {
key = "AppService"
value = "Airflow"
propagate_at_launch = true
}
dynamic "tag" {
for_each = var.tags
iterator = tag
content {
key = tag.key
value = tag.value
propagate_at_launch = true
}
}
}