-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
112 lines (98 loc) · 2.52 KB
/
main.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
100
101
102
103
104
105
106
107
108
109
110
111
112
data "aws_ecs_cluster" "cluster" {
cluster_name = var.cluster_name
}
locals {
}
resource "aws_ecs_task_definition" "datadog_agent" {
family = "${var.task_name}"
task_role_arn = aws_iam_role.datadog_agent.arn
execution_role_arn = aws_iam_role.datadog_agent.arn
container_definitions = jsonencode([
{
"name" : "${var.task_name}",
"cpu" : 10,
"memory" : 256,
"image" : "public.ecr.aws/datadog/agent:latest",
"essential" : true,
"environment" : [
{
"name" : "DD_API_KEY",
"value" : "${var.datadog_api_key}"
},
{
"name" : "DD_SITE",
"value" : "${var.datadog_site}"
},
{
"name" : "ECS_FARGATE",
"value" : "true"
}
],
"logConfiguration" : {
"logDriver" : "awslogs",
"options" : {
"awslogs-group" : "${var.log_group}",
"awslogs-region" : "${var.aws_region}",
"awslogs-stream-prefix" : "${var.log_stream_prefix}"
}
}
}
])
requires_compatibilities = ["FARGATE"]
cpu = 256
memory = 512
network_mode = "awsvpc"
depends_on = [aws_iam_role_policy.datadog_agent]
}
resource "aws_ecs_service" "datadog_agent" {
name = "datadog_agent"
cluster = data.aws_ecs_cluster.cluster.id
task_definition = aws_ecs_task_definition.datadog_agent.arn
desired_count = 1
launch_type = "FARGATE"
network_configuration {
subnets = var.subnets
security_groups = var.security_groups
assign_public_ip = false
}
}
resource "aws_iam_role" "datadog_agent" {
name = var.role_name
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = "sts:AssumeRole"
Effect = "Allow"
Sid = "CustomDatadogRole"
Principal = {
Service = "ecs-tasks.amazonaws.com"
}
},
]
})
}
resource "aws_iam_role_policy" "datadog_agent" {
name = var.policy_name
role = aws_iam_role.datadog_agent.id
policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = [
"ecs:ListClusters",
"ecs:ListContainerInstances",
"ecs:DescribeContainerInstances",
"logs:CreateLogStream",
"logs:PutLogEvents",
]
Effect = "Allow"
Resource = "*"
},
]
})
}
resource "aws_cloudwatch_log_group" "datadog_agent" {
name = var.log_group
retention_in_days = var.retention_in_days
}