This repository has been archived by the owner on Apr 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ecs.tf
72 lines (61 loc) · 2.17 KB
/
ecs.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
data "aws_ecs_cluster" "target_cluster" {
cluster_name = var.cluster_name
}
resource "aws_ecs_task_definition" "main_task" {
family = "${var.app_name}-tsk"
network_mode = "bridge"
cpu = var.cpu
memory = var.memory
container_definitions = var.container_definition
task_role_arn = var.task_role_arn
dynamic "volume" {
for_each = [for v in var.volumes : {
name = v.name
host_path = v.host_path
}]
content {
name = volume.value.name
host_path = volume.value.host_path
}
}
}
resource "aws_ecs_service" "main_service" {
name = "${var.app_name}-svc"
task_definition = aws_ecs_task_definition.main_task.arn
cluster = data.aws_ecs_cluster.target_cluster.id
desired_count = var.desired_task_count
iam_role = var.service_role_arn
launch_type = var.launch_type
deployment_maximum_percent = var.service_deployment_maximum_percent
deployment_minimum_healthy_percent = var.service_deployment_minimum_healthy_percent
health_check_grace_period_seconds = var.health_check_grace_period
deployment_circuit_breaker {
enable = var.circuit_breaker_enabled
rollback = var.circuit_breaker_rollback_enabled
}
load_balancer {
container_name = var.app_name
container_port = var.app_port
target_group_arn = aws_lb_target_group.lb_targets.arn
}
depends_on = [aws_lb.app_lb]
dynamic "ordered_placement_strategy" {
for_each = var.ordered_placement_strategies
content {
type = ordered_placement_strategy.value.type
field = ordered_placement_strategy.value.field
}
}
lifecycle {
ignore_changes = [
tags,
# this is critical to include, to prevent the service from being rebuilt on every deploy
# thus causing the service to become unavailable during a deploy
capacity_provider_strategy
]
}
}
data "aws_ecs_service" "main_service" {
cluster_arn = data.aws_ecs_cluster.target_cluster.arn
service_name = aws_ecs_service.main_service.name
}