@@ -15,21 +15,48 @@ resource "aws_ecs_task_definition" "this" {
15
15
count = " ${ var . network_mode != " awsvpc" ? 1 : 0 } "
16
16
family = " ${ local . id } "
17
17
container_definitions = " ${ data . template_file . this . rendered } "
18
- volume = " ${ var . volumes } "
18
+ dynamic "volume" {
19
+ for_each = var. volumes . name == " " ? [] : list (var. volumes )
20
+ content {
21
+ name = volume. name
22
+ host_path = volume. host_path
23
+ }
24
+ }
19
25
task_role_arn = " ${ aws_iam_role . this . arn } "
20
26
execution_role_arn = " ${ var . enable_ssm ? aws_iam_role . this . arn : " " } "
21
- requires_compatibilities = [" ${ var . compatibilities } " ]
22
- placement_constraints = " ${ var . placement_constraints } "
27
+ requires_compatibilities = " ${ var . compatibilities } "
28
+ dynamic "placement_constraints" {
29
+ for_each = var. placement_constraints . type == " " ? [] : list (var. placement_constraints )
30
+ content {
31
+ type = placement_constraints. type
32
+ expression = placement_constraints. expression
33
+ }
34
+ }
35
+ # placement_constraints {
36
+ # type = "${var.placement_constraints.type}"
37
+ # expression = "${var.placement_constraints.expression}"
38
+ # }
23
39
}
24
40
25
41
resource "aws_ecs_task_definition" "private" {
26
42
count = " ${ var . network_mode == " awsvpc" ? 1 : 0 } "
27
43
family = " ${ local . id } "
28
44
container_definitions = " ${ data . template_file . this . rendered } "
29
- volume = " ${ var . volumes } "
45
+ dynamic "volume" {
46
+ for_each = var. volumes . name == " " ? [] : list (var. volumes )
47
+
48
+ content {
49
+ name = volume. name
50
+ host_path = volume. host_path
51
+ }
52
+ }
53
+ # volume {
54
+ # name = "${var.volumes.name}"
55
+ # host_path = "${var.volumes.host_path}"
56
+ # }
30
57
task_role_arn = " ${ aws_iam_role . this . arn } "
31
58
execution_role_arn = " ${ aws_iam_role . this . arn } "
32
- requires_compatibilities = [ " ${ var . compatibilities } " ]
59
+ requires_compatibilities = " ${ var . compatibilities } "
33
60
network_mode = " ${ var . network_mode } "
34
61
}
35
62
@@ -93,7 +120,7 @@ resource "aws_ecs_service" "this" {
93
120
count = " ${ var . balancer [" vpc_id" ] != " " && var . cluster != " " && var . network_mode != " awsvpc" ? 1 : 0 } "
94
121
name = " ${ local . id } "
95
122
cluster = " ${ var . cluster } "
96
- task_definition = " ${ aws_ecs_task_definition . this . arn } "
123
+ task_definition = " ${ aws_ecs_task_definition . this . 0 . arn } "
97
124
desired_count = " ${ var . desired } "
98
125
iam_role = " arn:aws:iam::${ var . aws_account } :role/aws-service-role/ecs.amazonaws.com/AWSServiceRoleForECS"
99
126
health_check_grace_period_seconds = 0
@@ -114,7 +141,7 @@ resource "aws_ecs_service" "private" {
114
141
count = " ${ var . balancer [" vpc_id" ] != " " && var . cluster != " " && var . network_mode == " awsvpc" ? 1 : 0 } "
115
142
name = " ${ local . id } "
116
143
cluster = " ${ var . cluster } "
117
- task_definition = " ${ aws_ecs_task_definition . private . arn } "
144
+ task_definition = " ${ aws_ecs_task_definition . private . 0 . arn } "
118
145
desired_count = " ${ var . desired } "
119
146
# iam_role = "aws-service-role"
120
147
health_check_grace_period_seconds = 0
@@ -131,7 +158,7 @@ resource "aws_ecs_service" "private" {
131
158
}
132
159
133
160
network_configuration {
134
- subnets = [ " ${ var . subnets } " ]
161
+ subnets = " ${ var . subnets } "
135
162
security_groups = [" ${ var . security_group } " ]
136
163
}
137
164
@@ -145,7 +172,7 @@ resource "aws_ecs_service" "no_balancer" {
145
172
count = " ${ var . balancer [" vpc_id" ] != " " || var . cluster == " " ? 0 : 1 } "
146
173
name = " ${ local . id } "
147
174
cluster = " ${ var . cluster } "
148
- task_definition = " ${ aws_ecs_task_definition . this . arn } "
175
+ task_definition = " ${ aws_ecs_task_definition . this . 0 . arn } "
149
176
desired_count = " ${ var . desired } "
150
177
health_check_grace_period_seconds = 0
151
178
176
203
177
204
module "logs" {
178
205
source = " Aplyca/cloudwatchlogs/aws"
179
- version = " 0.1 .0"
206
+ version = " 0.2 .0"
180
207
181
208
name = " ${ local . id } "
182
209
role = " ${ aws_iam_role . this . name } "
0 commit comments