-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathecs.tf
More file actions
66 lines (56 loc) · 1.89 KB
/
ecs.tf
File metadata and controls
66 lines (56 loc) · 1.89 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
resource "aws_ecs_cluster" "app_cluster" {
name = "${var.project_names}-cluster"
}
# Create a CloudWatch Log Group for ECS logs
resource "aws_cloudwatch_log_group" "ecs_log_group" {
name = "/ecs/${var.project_names}"
retention_in_days = 7 # Retain logs for 7 days (adjust as needed)
}
resource "aws_ecs_task_definition" "app_task" {
family = "${var.project_names}-task"
network_mode = "awsvpc"
requires_compatibilities = ["FARGATE"]
cpu = "256"
memory = "512"
execution_role_arn = aws_iam_role.ecs_task_execution_role.arn
container_definitions = jsonencode([
{
name = "${var.project_names}"
image = "${aws_ecr_repository.app.repository_url}:latest"
cpu = 256
memory = 512
essential = true
portMappings = [{
containerPort = 80
hostPort = 80
}]
logConfiguration = {
logDriver = "awslogs"
options = {
awslogs-group = aws_cloudwatch_log_group.ecs_log_group.name
awslogs-region = "ap-south-1"
awslogs-stream-prefix = "ecs"
}
}
}
])
}
resource "aws_ecs_service" "app_service" {
name = "${var.project_names}-service"
cluster = aws_ecs_cluster.app_cluster.id
task_definition = aws_ecs_task_definition.app_task.arn
launch_type = "FARGATE"
network_configuration {
# subnets = var.public_subnets # Replace with actual subnets
subnets = aws_subnet.public_subnets[*].id
# security_groups = ["sg-07ed7eb6862f90068"]
assign_public_ip = true
security_groups = [aws_security_group.ecs_sg.id] # Replace with actual security group
}
load_balancer {
target_group_arn = aws_lb_target_group.ecs_tg.arn
container_name = "${var.project_names}"
container_port = 80
}
desired_count = 1
}