-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.tf
96 lines (81 loc) · 2.63 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
locals {
xray_service_placement_constraints = module.this.environment == "prod" ? [{
type = "memberOf"
expression = "attribute:spotinst.io/container-instance-lifecycle==od"
}] : []
}
module "log_group_label" {
source = "justtrackio/label/null"
version = "0.26.0"
context = module.this.context
label_order = var.label_orders.cloudwatch
attributes = ["xray"]
}
resource "aws_cloudwatch_log_group" "xray" {
name = module.log_group_label.id
tags = module.log_group_label.tags
retention_in_days = var.log_retention_in_days
}
resource "aws_service_discovery_service" "xray" {
name = "xray"
dns_config {
namespace_id = var.service_discovery_dns_namespace_id
dns_records {
ttl = 60
type = "SRV"
}
}
health_check_custom_config {
failure_threshold = 1
}
tags = module.this.tags
}
module "xray_definition" {
source = "cloudposse/ecs-container-definition/aws"
version = "0.58.1"
container_image = "public.ecr.aws/xray/aws-xray-daemon:3.3.5"
container_name = "xray-daemon"
container_cpu = module.this.environment == "prod" ? 100 : 25
container_memory_reservation = module.this.environment == "prod" ? 100 : 50
port_mappings = [
{
containerPort = 2000
hostPort = 0
protocol = "udp"
},
]
log_configuration = {
logDriver = "awslogs"
options = {
awslogs-group = aws_cloudwatch_log_group.xray.name
awslogs-region = module.this.aws_region
awslogs-stream-prefix = "ecs"
}
}
}
module "ecs_xray_task" {
source = "justtrackio/ecs-alb-service-task/aws"
version = "1.3.0"
task_policy_arns = ["arn:aws:iam::aws:policy/AWSXRayDaemonWriteAccess"]
network_mode = var.network_mode
container_definition_json = "[${module.xray_definition.json_map_encoded}]"
scheduling_strategy = "REPLICA"
service_registries = [{
registry_arn = aws_service_discovery_service.xray.arn
container_name = "xray-daemon"
container_port = 2000
}]
ecs_cluster_arn = var.ecs_cluster_arn
launch_type = "EC2"
deployment_minimum_healthy_percent = 0
deployment_maximum_percent = 100
desired_count = 1
vpc_id = var.vpc_id
propagate_tags = "SERVICE"
context = module.this.context
label_orders = var.label_orders
service_placement_constraints = local.xray_service_placement_constraints
tags = {
"spotinst.io/restrict-scale-down" = true
}
}