-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathservice.tf
73 lines (64 loc) · 2.22 KB
/
service.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
module "ecs_service" {
source = "terraform-aws-modules/ecs/aws//modules/service"
name = "${local.name}-svc"
cluster_arn = module.ecs_cluster.arn
cpu = 512
memory = 512
requires_compatibilities = ["EC2"]
capacity_provider_strategy = {
# On-demand instances
ex_1 = {
capacity_provider = module.ecs_cluster.autoscaling_capacity_providers["ex_1"].name
weight = 1
base = 1
}
}
# Container definition(s)
container_definitions = {
(local.container_name) = {
image = "${module.ecr.repository_url}:latest"
port_mappings = [
{
name = local.container_name
containerPort = local.container_port
protocol = "tcp"
}
]
environment = [
{ name = "DB_USER", value = "${module.db_params.db_username.secure_value}" },
{ name = "DB_PWD", value = "${module.db_params.db_password.secure_value}" },
{ name = "DB_HOST", value = "${aws_db_instance.mountains.address}" },
{ name = "DB_DATABASE", value = "${module.db_params.db_database.secure_value}" }
]
readonly_root_filesystem = true
enable_cloudwatch_logging = true
create_cloudwatch_log_group = true
cloudwatch_log_group_name = "/aws/ecs/${local.name}/${local.container_name}"
cloudwatch_log_group_retention_in_days = 7
log_configuration = {
logDriver = "awslogs"
}
}
}
load_balancer = {
service = {
target_group_arn = module.alb.target_groups["ex_ecs"].arn
container_name = local.container_name
container_port = local.container_port
}
}
subnet_ids = module.vpc.private_subnets
security_group_name = "${local.name}-lb-to-ecs-container-port"
security_group_rules = {
alb_http_ingress = {
type = "ingress"
from_port = local.container_port
to_port = local.container_port
protocol = "tcp"
description = "Service port"
source_security_group_id = module.alb.security_group_id
}
}
security_group_ids = [aws_security_group.ecs.id]
tags = local.tags
}