Skip to content

Commit 3089e47

Browse files
committed
Fixing issue on count cannot be determined
1 parent 00cb248 commit 3089e47

File tree

1 file changed

+4
-15
lines changed

1 file changed

+4
-15
lines changed

main.tf

+4-15
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ resource "aws_security_group_rule" "ingress_through_https" {
8181
# AWS LOAD BALANCER - Target Groups
8282
#------------------------------------------------------------------------------
8383
resource "aws_lb_target_group" "lb_http_tgs" {
84-
count = length(var.http_ports)
84+
count = var.enable_http ? length(var.http_ports) : 0
8585
name = "${var.name_preffix}-lb-http-tg-${count.index}"
8686
port = element(var.http_ports, count.index)
8787
protocol = "HTTP"
@@ -118,7 +118,7 @@ resource "aws_lb_target_group" "lb_http_tgs" {
118118
}
119119

120120
resource "aws_lb_target_group" "lb_https_tgs" {
121-
count = length(var.https_ports)
121+
count = var.enable_https ? length(var.https_ports) : 0
122122
name = "${var.name_preffix}-lb-https-tg-${count.index}"
123123
port = element(var.https_ports, count.index)
124124
protocol = "HTTPS"
@@ -158,7 +158,7 @@ resource "aws_lb_target_group" "lb_https_tgs" {
158158
# AWS LOAD BALANCER - Listeners
159159
#------------------------------------------------------------------------------
160160
resource "aws_lb_listener" "lb_http_listeners" {
161-
count = length(aws_lb_target_group.lb_http_tgs)
161+
count = var.enable_http ? length(aws_lb_target_group.lb_http_tgs) : 0
162162
load_balancer_arn = aws_lb.lb.arn
163163
port = element(aws_lb_target_group.lb_http_tgs.*.port, count.index)
164164
protocol = element(aws_lb_target_group.lb_http_tgs.*.protocol, count.index)
@@ -169,7 +169,7 @@ resource "aws_lb_listener" "lb_http_listeners" {
169169
}
170170

171171
resource "aws_lb_listener" "lb_https_listeners" {
172-
count = length(aws_lb_target_group.lb_https_tgs)
172+
count = var.enable_https ? length(aws_lb_target_group.lb_https_tgs) : 0
173173
load_balancer_arn = aws_lb.lb.arn
174174
port = element(aws_lb_target_group.lb_https_tgs.*.port, count.index)
175175
protocol = element(aws_lb_target_group.lb_https_tgs.*.protocol, count.index)
@@ -181,14 +181,3 @@ resource "aws_lb_listener" "lb_https_listeners" {
181181
# TODO
182182
# ssl_policy - (Optional) The name of the SSL Policy for the listener. Required if protocol is HTTPS or TLS.
183183
# certificate_arn - (Optional) The ARN of the default SSL server certificate. Exactly one certificate is required if the protocol is HTTPS. For adding additional SSL certificates, see the aws_lb_listener_certificate resource.
184-
185-
186-
187-
188-
189-
190-
191-
192-
193-
194-

0 commit comments

Comments
 (0)