Skip to content

Instantly share code, notes, and snippets.

@jamengual
Created June 17, 2019 18:42
Show Gist options
  • Save jamengual/ea01fe38c71fb3353ecbfe3d5832d726 to your computer and use it in GitHub Desktop.
Save jamengual/ea01fe38c71fb3353ecbfe3d5832d726 to your computer and use it in GitHub Desktop.
terraform-datadog-ecs-ec2
[
{
"name": "datadog-agent",
"image": "datadog/agent:latest",
"cpu": ${cpu},
"memory": ${memory},
"essential": true,
"portMappings": [
{
"containerPort": 8126,
"hostPort": 8126
}
],
"mountPoints": [
{
"containerPath": "/var/run/docker.sock",
"sourceVolume": "docker_sock",
"readOnly": true
},
{
"containerPath": "/host/sys/fs/cgroup",
"sourceVolume": "cgroup",
"readOnly": true
},
{
"containerPath": "/host/proc",
"sourceVolume": "proc",
"readOnly": true
}
],
"environment": [
{
"name": "DD_API_KEY",
"value": "${dd_api_key}"
},
{
"name": "DD_SITE",
"value": "datadoghq.com"
},
{
"name": "DD_APM_NON_LOCAL_TRAFFIC",
"value": "true"
},
{
"name": "DD_APM_ENABLED",
"value": "true"
}
],
"volumes": [
{
"host": {
"sourcePath": "/var/run/docker.sock"
},
"name": "docker_sock"
},
{
"host": {
"sourcePath": "/proc/"
},
"name": "proc"
},
{
"host": {
"sourcePath": "/sys/fs/cgroup/"
},
"name": "cgroup"
}
],
"family": "datadog-agent-task"
}
]
data "template_file" "container_definitions" {
template = "${file("${path.module}/templates/containerDefinitions.json")}"
vars {
dd_agent_api_key = "${var.dd_agent_api_key}"
cpu = "${var.cpu}"
memory = "${var.memory}"
}
}
resource "aws_ecs_task_definition" "datadog_task" {
family = "datadog-agent-task"
container_definitions = "${data.template_file.container_definitions.rendered}"
volume {
name = "docker_sock"
host_path = "/var/run/docker.sock"
}
volume {
name = "proc"
host_path = "/proc/"
}
volume {
name = "cgroup"
host_path = "/sys/fs/cgroup/"
}
}
resource "aws_ecs_service" "datadog_service" {
name = "datadog-service"
cluster = "${var.ecs_cluster_name}"
task_definition = "${aws_ecs_task_definition.datadog_task.arn}"
launch_type = "EC2"
scheduling_strategy = "DAEMON"
depends_on = ["aws_ecs_task_definition.datadog_task"]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment