-
Notifications
You must be signed in to change notification settings - Fork 31
/
ecs.tf
99 lines (85 loc) · 3.44 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
99
/**
* Copyright (C) 2018-2020 Expedia, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
*/
resource "aws_ecs_cluster" "apiary" {
count = var.hms_instance_type == "ecs" ? 1 : 0
name = local.instance_alias
tags = var.apiary_tags
}
resource "aws_cloudwatch_log_group" "apiary_ecs" {
count = var.hms_instance_type == "ecs" ? 1 : 0
name = "${local.instance_alias}-ecs"
tags = var.apiary_tags
}
resource "aws_ecs_task_definition" "apiary_hms_readwrite" {
count = var.hms_instance_type == "ecs" ? 1 : 0
family = "${local.instance_alias}-hms-readwrite"
task_role_arn = aws_iam_role.apiary_hms_readwrite.arn
execution_role_arn = aws_iam_role.apiary_task_exec[0].arn
network_mode = "awsvpc"
memory = var.hms_rw_heapsize
cpu = var.hms_rw_cpu
requires_compatibilities = var.ecs_requires_compatibilities
container_definitions = local.hms_readwrite_template
tags = var.apiary_tags
}
resource "aws_ecs_task_definition" "apiary_hms_readonly" {
count = var.hms_instance_type == "ecs" ? 1 : 0
family = "${local.instance_alias}-hms-readonly"
task_role_arn = aws_iam_role.apiary_hms_readonly.arn
execution_role_arn = aws_iam_role.apiary_task_exec[0].arn
network_mode = "awsvpc"
memory = var.hms_ro_heapsize
cpu = var.hms_ro_cpu
requires_compatibilities = var.ecs_requires_compatibilities
container_definitions = local.hms_readonly_template
tags = var.apiary_tags
}
resource "aws_ecs_service" "apiary_hms_readwrite_service" {
count = var.hms_instance_type == "ecs" ? 1 : 0
depends_on = [aws_lb_target_group.apiary_hms_rw_tg]
name = "${local.instance_alias}-hms-readwrite-service"
launch_type = "FARGATE"
platform_version = var.ecs_platform_version
cluster = aws_ecs_cluster.apiary[0].id
task_definition = aws_ecs_task_definition.apiary_hms_readwrite[0].arn
desired_count = var.hms_rw_ecs_task_count
load_balancer {
target_group_arn = aws_lb_target_group.apiary_hms_rw_tg[0].arn
container_name = "apiary-hms-readwrite"
container_port = 9083
}
network_configuration {
security_groups = ["${aws_security_group.hms_rw[0].id}"]
subnets = var.private_subnets
}
service_registries {
registry_arn = aws_service_discovery_service.hms_readwrite[0].arn
}
tags = var.apiary_tags
}
resource "aws_ecs_service" "apiary_hms_readonly_service" {
count = var.hms_instance_type == "ecs" ? 1 : 0
depends_on = [aws_lb_target_group.apiary_hms_ro_tg]
name = "${local.instance_alias}-hms-readonly-service"
launch_type = "FARGATE"
platform_version = var.ecs_platform_version
cluster = aws_ecs_cluster.apiary[0].id
task_definition = aws_ecs_task_definition.apiary_hms_readonly[0].arn
desired_count = var.hms_ro_ecs_task_count
load_balancer {
target_group_arn = aws_lb_target_group.apiary_hms_ro_tg[0].arn
container_name = "apiary-hms-readonly"
container_port = 9083
}
network_configuration {
security_groups = ["${aws_security_group.hms_ro[0].id}"]
subnets = var.private_subnets
}
service_registries {
registry_arn = aws_service_discovery_service.hms_readonly[0].arn
}
tags = var.apiary_tags
}