forked from terraform-community-modules/tf_aws_ecs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
consul_agent.tf
52 lines (46 loc) · 1.74 KB
/
consul_agent.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
resource "aws_ecs_task_definition" "consul" {
count = var.enable_agents ? 1 : 0
family = "consul-agent-${aws_ecs_cluster.cluster.name}"
container_definitions = templatefile(
"${path.module}/templates/consul.json",
{
env = aws_ecs_cluster.cluster.name
image = var.consul_image
registrator_image = var.registrator_image
consul_memory_reservation = var.consul_memory_reservation
registrator_memory_reservation = var.registrator_memory_reservation
awslogs_group = "consul-agent-${aws_ecs_cluster.cluster.name}"
awslogs_stream_prefix = "consul-agent-${aws_ecs_cluster.cluster.name}"
awslogs_region = var.region
}
)
network_mode = "host"
task_role_arn = aws_iam_role.consul_task[0].arn
volume {
name = "consul-config-dir"
host_path = "/etc/consul"
}
volume {
name = "docker-sock"
host_path = "/var/run/docker.sock"
}
}
resource "aws_cloudwatch_log_group" "consul" {
count = var.enable_agents ? 1 : 0
name = aws_ecs_task_definition.consul[0].family
tags = {
VPC = data.aws_vpc.vpc.tags["Name"]
Application = aws_ecs_task_definition.consul[0].family
}
}
resource "aws_ecs_service" "consul" {
count = var.enable_agents ? 1 : 0
name = "consul-agent-${aws_ecs_cluster.cluster.name}"
cluster = aws_ecs_cluster.cluster.id
task_definition = aws_ecs_task_definition.consul[0].arn
desired_count = var.servers
deployment_minimum_healthy_percent = "60"
placement_constraints {
type = "distinctInstance"
}
}