-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathecs.tf
More file actions
85 lines (80 loc) · 2.39 KB
/
Copy pathecs.tf
File metadata and controls
85 lines (80 loc) · 2.39 KB
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
resource "aws_ecs_cluster" "main" {
name = "${var.prefix}-cluster"
setting {
name = "containerInsights"
value = "disabled"
}
}
resource "aws_ecs_cluster_capacity_providers" "main" {
cluster_name = aws_ecs_cluster.main.name
capacity_providers = [var.fargate_type]
default_capacity_provider_strategy {
base = 1
weight = 100
capacity_provider = var.fargate_type
}
}
resource "aws_ecs_task_definition" "main" {
family = "${var.prefix}-taskdef"
requires_compatibilities = ["FARGATE"]
execution_role_arn = aws_iam_role.executionrole.arn
network_mode = "awsvpc"
cpu = var.cpu
memory = var.memory
container_definitions = jsonencode([
{
name = "cloudflared"
essential = true
image = "cloudflare/cloudflared:${var.cloudflare_version}",
command = ["tunnel", "run", cloudflare_tunnel.tunnel.id]
secrets = [
{
name = "TUNNEL_TOKEN",
valueFrom = aws_ssm_parameter.tunneltoken.arn
}
]
logConfiguration = {
logDriver = "awslogs"
options = {
awslogs-group = aws_cloudwatch_log_group.logs.name
awslogs-region = data.aws_region.current.name
awslogs-stream-prefix = "cloudflared"
}
}
}
])
}
resource "aws_cloudwatch_log_group" "logs" {
name = "${var.prefix}-logs"
retention_in_days = 1
}
resource "aws_security_group" "tunnel" {
name = "${var.prefix}-tunnel"
description = "This is the security group for the Cloudflare tunnel instances"
vpc_id = var.vpc_id
// does not require any ingress ports, just egress
egress {
from_port = 0
to_port = 0
protocol = "-1"
// required to either be the VPC CIDR block, or have VPC endpoints for SSM, ECR, and Cloudwatch Logs
cidr_blocks = ["0.0.0.0/0"]
}
}
resource "aws_ecs_service" "main" {
name = "${var.prefix}-tunnel"
cluster = aws_ecs_cluster.main.id
task_definition = aws_ecs_task_definition.main.arn
desired_count = var.desired_count
capacity_provider_strategy {
capacity_provider = var.fargate_type
weight = 100
base = 1
}
network_configuration {
subnets = var.private_subnets
security_groups = [
aws_security_group.tunnel.id
]
}
}