-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds Consul and Registrator agents to ECS Instances (#16)
* Adds consul + registrator to ECS Clusters! * Formating * Setting enable_consul to false * readme updates * Some updates based on code review feedback * Updated IAM Names so we don't have duplicates * terraform fmt * Updates README and adds an example consul template * Updates based on feedback in #16 * Adding Build Status Badge to README * READEME update about TF Version * READEME update about TF Version
- Loading branch information
1 parent
dc9f643
commit b8779be
Showing
10 changed files
with
261 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
0.10.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
data "template_file" "consul" { | ||
template = "${file("${path.module}/templates/consul.json")}" | ||
|
||
vars { | ||
env = "${aws_ecs_cluster.cluster.name}" | ||
image = "${var.consul_image}" | ||
registrator_image = "${var.registrator_image}" | ||
awslogs_group = "consul-agent-${aws_ecs_cluster.cluster.name}" | ||
awslogs_stream_prefix = "consul-agent-${aws_ecs_cluster.cluster.name}" | ||
awslogs_region = "${var.region}" | ||
} | ||
} | ||
|
||
# End Data block | ||
|
||
resource "aws_ecs_task_definition" "consul" { | ||
count = "${var.enable_agents ? 1 : 0}" | ||
family = "consul-agent-${aws_ecs_cluster.cluster.name}" | ||
container_definitions = "${data.template_file.consul.rendered}" | ||
network_mode = "host" | ||
task_role_arn = "${aws_iam_role.consul_task.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.family}" | ||
|
||
tags { | ||
VPC = "${data.aws_vpc.vpc.tags["Name"]}" | ||
Application = "${aws_ecs_task_definition.consul.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.arn}" | ||
desired_count = "${var.servers}" | ||
|
||
placement_constraints { | ||
type = "distinctInstance" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
[ | ||
{ | ||
"name": "consul_agent-${env}", | ||
"image": "${image}", | ||
"memoryReservation": 512, | ||
"environment": [ | ||
{ | ||
"name": "CONSUL_BIND_INTERFACE", | ||
"value": "eth0" | ||
} | ||
], | ||
"command": [ | ||
"agent", "-client=0.0.0.0" | ||
], | ||
"mountPoints": [ | ||
{ | ||
"sourceVolume": "consul-config-dir", | ||
"containerPath": "/consul/config" | ||
} | ||
], | ||
"logConfiguration": { | ||
"logDriver": "awslogs", | ||
"options": { | ||
"awslogs-group": "${awslogs_group}", | ||
"awslogs-region": "${awslogs_region}", | ||
"awslogs-stream-prefix": "${awslogs_stream_prefix}" | ||
} | ||
} | ||
}, | ||
{ | ||
"name": "registrator-${env}", | ||
"image": "${registrator_image}", | ||
"memoryReservation": 256, | ||
"command": [ | ||
"-retry-attempts=10", "-retry-interval=1000", "consul://localhost:8500" | ||
], | ||
"mountPoints": [ | ||
{ | ||
"sourceVolume": "docker-sock", | ||
"containerPath": "/tmp/docker.sock" | ||
} | ||
], | ||
"logConfiguration": { | ||
"logDriver": "awslogs", | ||
"options": { | ||
"awslogs-group": "${awslogs_group}", | ||
"awslogs-region": "${awslogs_region}", | ||
"awslogs-stream-prefix": "${awslogs_stream_prefix}" | ||
} | ||
} | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/bin/mkdir -p /etc/consul | ||
cat <<"CONSUL" > /etc/consul/config.json | ||
{ | ||
"raft_protocol": 3, | ||
"log_level": "INFO", | ||
"enable_script_checks": true, | ||
"datacenter": "${datacenter}", | ||
"retry_join_ec2": { | ||
"tag_key": "consul_server", | ||
"tag_value": "true" | ||
} | ||
} | ||
CONSUL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters