-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathecs.tf
98 lines (87 loc) · 2.75 KB
/
ecs.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
resource "aws_ecs_cluster" "this" {
name = local.ecs_cluster_name
tags = merge(
var.standard_tags,
{
Name = local.ecs_cluster_name
Metaflow = "true"
}
)
}
resource "aws_ecs_task_definition" "this" {
family = "${var.resource_prefix}service${var.resource_suffix}" # Unique name for task definition
container_definitions = <<EOF
[
{
"name": "${var.resource_prefix}service${var.resource_suffix}",
"image": "${var.metadata_service_container_image}",
"essential": true,
"cpu": ${var.metadata_service_cpu},
"memory": ${var.metadata_service_memory},
"portMappings": [
{
"containerPort": 8080,
"hostPort": 8080
},
{
"containerPort": 8082,
"hostPort": 8082
}
],
"environment": [
{"name": "MF_METADATA_DB_HOST", "value": "${replace(var.rds_master_instance_endpoint, ":5432", "")}"},
{"name": "MF_METADATA_DB_NAME", "value": "${var.database_name}"},
{"name": "MF_METADATA_DB_PORT", "value": "5432"},
{"name": "MF_METADATA_DB_PSWD", "value": "${var.database_password}"},
{"name": "MF_METADATA_DB_USER", "value": "${var.database_username}"}
],
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-group": "${aws_cloudwatch_log_group.this.name}",
"awslogs-region": "${data.aws_region.current.name}",
"awslogs-stream-prefix": "metadata"
}
}
}
]
EOF
network_mode = "awsvpc"
requires_compatibilities = ["FARGATE"]
task_role_arn = aws_iam_role.metadata_svc_ecs_task_role.arn
execution_role_arn = var.fargate_execution_role_arn
cpu = var.metadata_service_cpu
memory = var.metadata_service_memory
tags = merge(
var.standard_tags,
{
Metaflow = "true"
}
)
}
resource "aws_ecs_service" "this" {
name = "${var.resource_prefix}metadata-service${var.resource_suffix}"
cluster = aws_ecs_cluster.this.id
task_definition = aws_ecs_task_definition.this.arn
desired_count = 1
launch_type = "FARGATE"
network_configuration {
security_groups = [aws_security_group.metadata_service_security_group.id]
assign_public_ip = var.with_public_ip
subnets = [var.subnet1_id, var.subnet2_id]
}
load_balancer {
target_group_arn = aws_lb_target_group.this.arn
container_name = "${var.resource_prefix}service${var.resource_suffix}"
container_port = 8080
}
load_balancer {
target_group_arn = aws_lb_target_group.db_migrate.arn
container_name = "${var.resource_prefix}service${var.resource_suffix}"
container_port = 8082
}
lifecycle {
ignore_changes = [desired_count]
}
tags = var.standard_tags
}