1
1
locals {
2
- name = var . app_type == " tcp-app " ? " ${ var . env } - ${ var . name } -tcp " : " ${ var . env } -${ var . name } "
2
+ name = " ${ var . env } -${ var . name } "
3
3
ecs_service_name = var. ecs_service_name != " " ? var. ecs_service_name : " ${ var . env } -${ var . name } "
4
4
ecs_cluster_name = var. ecs_cluster_name != " " ? var. ecs_cluster_name : " ${ var . env } -${ var . namespace } "
5
5
ecs_cluster_arn = length (var. ecs_cluster_arn ) != " " ? var. ecs_cluster_arn : " arn:aws:ecs:${ data . aws_region . current . name } :${ data . aws_caller_identity . current . account_id } :cluster/${ local . ecs_cluster_name } "
6
6
ecr_repo_name = var. ecr_repo_name != " " ? var. ecr_repo_name : " ${ var . namespace } -${ var . name } "
7
7
name_prefix = " ${ substr (var. name , 0 , 5 )} -"
8
- domain_names = var. root_domain_name != " example.com" ? concat ([" ${ var . name } .${ var . env } .${ var . root_domain_name } " ], var. domain_names ) : []
8
+ domain_names = var. root_domain_name != " example.com" ? concat ([
9
+ " ${ var . name } .${ var . env } .${ var . root_domain_name } "
10
+ ], var. domain_names ) : []
9
11
10
12
# Datadog Environment Variables: https://docs.datadoghq.com/agent/guide/environment-variables/
11
13
# https://docs.datadoghq.com/agent/docker/apm/?tab=linux#docker-apm-agent-environment-variables
@@ -31,12 +33,12 @@ locals {
31
33
32
34
fluentbit_container_definition = [
33
35
{
34
- essential = true
35
- image = " public.ecr.aws/aws-observability/aws-for-fluent-bit:latest"
36
- name = " log_router"
37
- memoryReservation = 75
36
+ essential = true
37
+ image = " public.ecr.aws/aws-observability/aws-for-fluent-bit:latest"
38
+ name = " log_router"
39
+ memoryReservation = 75
38
40
firelensConfiguration = {
39
- " type" = " fluentbit"
41
+ " type" = " fluentbit"
40
42
" options" = {
41
43
" enable-ecs-log-metadata" = " true"
42
44
}
@@ -46,43 +48,45 @@ locals {
46
48
47
49
volumes = concat (var. web_proxy_enabled ? [
48
50
{
49
- name = " nginx-templates" ,
51
+ name = " nginx-templates" ,
50
52
mount_point = {
51
53
" sourceVolume" = " nginx-templates"
52
54
" containerPath" = " /etc/nginx/templates/"
53
55
" readOnly" = null
54
56
}
55
57
56
- docker_volume_configuration = [{
57
- " scope" : " task" ,
58
- " driver" : " local" ,
59
- " labels" : {
60
- " scratch" : " space"
58
+ docker_volume_configuration = [
59
+ {
60
+ " scope" : " task" ,
61
+ " driver" : " local" ,
62
+ " labels" : {
63
+ " scratch" : " space"
64
+ }
61
65
}
62
- } ]
66
+ ]
63
67
},
64
68
{
65
- name = " nginx-app" ,
69
+ name = " nginx-app" ,
66
70
mount_point = {
67
71
" sourceVolume" = " nginx-app"
68
72
" containerPath" = " /etc/nginx/app/"
69
73
" readOnly" = null
70
74
}
71
75
72
- docker_volume_configuration = [{
73
- " scope" : " task" ,
74
- " driver" : " local" ,
75
- " labels" : {
76
- " scratch" : " space"
76
+ docker_volume_configuration = [
77
+ {
78
+ " scope" : " task" ,
79
+ " driver" : " local" ,
80
+ " labels" : {
81
+ " scratch" : " space"
82
+ }
77
83
}
78
- } ]
84
+ ]
79
85
},
80
- ]
81
- : [],
82
-
86
+ ] : [],
83
87
var. efs_enabled ? [
84
88
{
85
- name = " efs" ,
89
+ name = " efs" ,
86
90
mount_point = {
87
91
" sourceVolume" = " efs"
88
92
" containerPath" = var.efs_mount_point,
@@ -103,45 +107,48 @@ locals {
103
107
(var. datadog_enabled && var. ecs_launch_type == " EC2" ) ? module. datadog . volumes : []
104
108
)
105
109
106
- http_tcp_listeners = var. app_type == " tcp-app" ? [
110
+ alb_http_tcp_listeners = var. app_type == " tcp-app" ? [
107
111
for index , port_mapping in var . port_mappings :
108
- {
109
- port = port_mapping. host_port
110
- protocol = " TCP"
111
- target_group_index = index
112
- } if port_mapping . https_listener == false
112
+ {
113
+ port = port_mapping[ " host_port" ]
114
+ protocol = " TCP"
115
+ target_group_index = index
116
+ } if ! lookup ( port_mapping, " tls " , false )
113
117
] : [
114
118
{
115
119
port = var.http_port
116
120
protocol = " HTTP"
117
121
target_group_index = 0
118
- },]
122
+ }
123
+ ]
119
124
120
- https_tls_listeners = var. app_type == " tcp-app" ? [
125
+ # In case app type is "tcp-app" and port_mapping has "tls" config and is true we use tcp over tls.
126
+ alb_https_listeners = var. app_type == " tcp-app" ? [
121
127
for index , port_mapping in var . port_mappings :
122
- {
123
- port = port_mapping.host_port
124
- protocol = " TLS"
125
- certificate_arn = var.tls_cert_arn
126
- target_group_index = index
127
- } if port_mapping . https_listener == true
128
- ] : [
129
- {
130
- port = 443
131
- protocol = " HTTPS"
132
- certificate_arn = var.tls_cert_arn
133
- target_group_index = 0
134
- },]
128
+ {
129
+ port = port_mapping[" host_port" ]
130
+ protocol = " TLS"
131
+ certificate_arn = var.tls_cert_arn
132
+ target_group_index = index
133
+ } if lookup (port_mapping, " tls" , false )
134
+ ] : [
135
+ {
136
+ port = 443
137
+ protocol = " HTTPS"
138
+ certificate_arn = var.tls_cert_arn
139
+ target_group_index = 0
140
+ }
141
+ ]
135
142
136
143
ecs_service_tcp_port_mappings = [
137
144
for index , port_mapping in var . port_mappings :
138
- {
139
- container_name = var.name
140
- container_port = port_mapping. container_port
141
- host_port = port_mapping. host_port
142
- target_group_arn = length (module. alb [* ]. target_group_arns ) >= 1 ? module.alb[0 ].target_group_arns[index] : " "
143
- }
144
- ]
145
+ {
146
+ container_name = var.name
147
+ container_port = port_mapping[ " container_port" ]
148
+ host_port = port_mapping[ " host_port" ]
149
+ target_group_arn = length (module. alb [* ]. target_group_arns ) >= 1 ? module.alb[0 ].target_group_arns[index] : " "
150
+ }
151
+ ]
145
152
146
153
target_groups_web = [
147
154
{
@@ -150,6 +157,8 @@ locals {
150
157
backend_port = var.web_proxy_enabled ? var.web_proxy_docker_container_port : var.docker_container_port
151
158
target_type = var.ecs_launch_type == " EC2" ? " instance" : " ip"
152
159
deregistration_delay = var.alb_deregistration_delay
160
+ preserve_client_ip = true
161
+ # This is specified for compatibility with the tcp target groups. It's not actually used in a lookup.
153
162
154
163
health_check = {
155
164
enabled = true
@@ -170,9 +179,10 @@ locals {
170
179
{
171
180
name_prefix = local.name_prefix
172
181
backend_protocol = " TCP"
173
- backend_port = port_mapping. container_port
182
+ backend_port = port_mapping[ " container_port" ]
174
183
target_type = var.ecs_launch_type == " EC2" ? " instance" : " ip"
175
184
deregistration_delay = var.alb_deregistration_delay
185
+ preserve_client_ip = true
176
186
177
187
health_check = {
178
188
enabled = true
@@ -182,11 +192,9 @@ locals {
182
192
unhealthy_threshold = var.alb_health_check_unhealthy_threshold
183
193
timeout = null
184
194
matcher = null
185
- port = port_mapping. host_port
195
+ port = port_mapping[ " host_port" ]
186
196
protocol = " TCP"
187
197
}
188
-
189
198
}
190
199
]
191
-
192
200
}
0 commit comments