generated from silinternational/template-terraform-module
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
84 lines (73 loc) · 2.74 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
/*
* Get task definition data
*/
data "aws_ecs_task_definition" "td" {
task_definition = aws_ecs_task_definition.td.family
depends_on = [aws_ecs_task_definition.td]
}
/*
* Create task definition
*/
resource "aws_ecs_task_definition" "td" {
family = "${var.service_name}-${var.service_env}"
container_definitions = var.container_def_json
task_role_arn = var.task_role_arn
execution_role_arn = var.execution_role_arn
network_mode = var.network_mode
dynamic "volume" {
for_each = var.volumes
content {
host_path = lookup(volume.value, "host_path", null)
name = volume.value.name
dynamic "docker_volume_configuration" {
for_each = lookup(volume.value, "docker_volume_configuration", [])
content {
autoprovision = lookup(docker_volume_configuration.value, "autoprovision", null)
driver = lookup(docker_volume_configuration.value, "driver", null)
driver_opts = lookup(docker_volume_configuration.value, "driver_opts", null)
labels = lookup(docker_volume_configuration.value, "labels", null)
scope = lookup(docker_volume_configuration.value, "scope", null)
}
}
dynamic "efs_volume_configuration" {
for_each = lookup(volume.value, "efs_volume_configuration", [])
content {
file_system_id = lookup(efs_volume_configuration.value, "file_system_id", null)
root_directory = lookup(efs_volume_configuration.value, "root_directory", null)
}
}
}
}
}
/*
* Create ECS Service
*/
resource "aws_ecs_service" "service" {
name = var.service_name
cluster = var.cluster_id
desired_count = var.desired_count
iam_role = var.ecsServiceRole_arn
deployment_maximum_percent = var.deployment_maximum_percent
deployment_minimum_healthy_percent = var.deployment_minimum_healthy_percent
availability_zone_rebalancing = var.availability_zone_rebalancing
dynamic "ordered_placement_strategy" {
for_each = var.ordered_placement_strategy
content {
field = try(ordered_placement_strategy.value.field, null)
type = ordered_placement_strategy.value.type
}
}
dynamic "load_balancer" {
for_each = var.load_balancer
content {
container_name = load_balancer.value.container_name
container_port = load_balancer.value.container_port
target_group_arn = load_balancer.value.target_group_arn
}
}
# Track the latest ACTIVE revision
task_definition = "${aws_ecs_task_definition.td.family}:${max(
aws_ecs_task_definition.td.revision,
data.aws_ecs_task_definition.td.revision,
)}"
}