Skip to content

Commit 8f5ca4d

Browse files
committed
Reducing conditionals
1 parent 849819a commit 8f5ca4d

File tree

2 files changed

+21
-19
lines changed

2 files changed

+21
-19
lines changed

operations/deployment/terraform/aws/bitovi_main.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,8 @@ module "aws_lb" {
176176
aws_alb_target_sg_id = module.ec2[0].aws_security_group_ec2_sg_id
177177
aws_r53_domain_name = var.aws_r53_domain_name
178178
# Certs
179-
aws_certificates_selected_arn = var.aws_r53_enable_cert && var.aws_r53_domain_name != "" ? module.aws_certificates[0].selected_arn : ""
179+
#aws_certificates_selected_arn = var.aws_r53_enable_cert && var.aws_r53_domain_name != "" ? module.aws_certificates[0].selected_arn : ""
180+
aws_certificates_selected_arn = try(module.aws_certificates[0].selected_arn, "")
180181
# Others
181182
aws_resource_identifier = var.aws_resource_identifier
182183
aws_resource_identifier_supershort = var.aws_resource_identifier_supershort

operations/deployment/terraform/modules/aws/lb/aws_lb.tf

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
# Locals for ALB
2+
locals {
3+
alb_ssl_available = var.aws_certificates_selected_arn != "" ? true : false
4+
5+
alb_listen_port = var.aws_alb_listen_port != "" ? [for n in split(",", var.aws_alb_listen_port) : tonumber(n)] : var.aws_certificates_selected_arn != "" ? [443] : [80]
6+
alb_listen_protocol = var.aws_alb_listen_protocol != "" ? [for n in split(",", var.aws_alb_listen_protocol) : n] : var.aws_certificates_selected_arn != "" ? ["HTTPS"] : ["HTTP"]
7+
alb_app_port = var.aws_alb_app_port != "" ? [for n in split(",", var.aws_alb_app_port) : tonumber(n)] : local.alb_listen_port
8+
alb_app_protocol = var.aws_alb_app_protocol != "" ? [for n in split(",", var.aws_alb_app_protocol) : n] : [for _ in local.alb_app_port : "HTTP"]
9+
10+
# Ensure all arrays have the same length
11+
alb_ports_ammount = min(
12+
length(local.alb_listen_port),
13+
length(local.alb_app_port),
14+
length(local.alb_listen_protocol),
15+
length(local.alb_app_protocol)
16+
)
17+
}
18+
19+
120
# Security group for ALB
221
resource "aws_security_group" "alb_security_group" {
322
name = var.aws_alb_security_group_name != "" ? var.aws_alb_security_group_name : "SG for ${var.aws_resource_identifier} - ALB"
@@ -325,24 +344,6 @@ POLICY
325344
}
326345
}
327346

328-
# Locals for ALB
329-
locals {
330-
alb_ssl_available = var.aws_certificates_selected_arn != "" ? true : false
331-
332-
alb_listen_port = var.aws_alb_listen_port != "" ? [for n in split(",", var.aws_alb_listen_port) : tonumber(n)] : (var.aws_certificates_selected_arn != "" ? [443] : [80])
333-
alb_listen_protocol = var.aws_alb_listen_protocol != "" ? [for n in split(",", var.aws_alb_listen_protocol) : n] : (var.aws_certificates_selected_arn != "" ? ["HTTPS"] : ["HTTP"])
334-
alb_app_port = var.aws_alb_app_port != "" ? [for n in split(",", var.aws_alb_app_port) : tonumber(n)] : local.alb_listen_port
335-
alb_app_protocol = var.aws_alb_app_protocol != "" ? [for n in split(",", var.aws_alb_app_protocol) : n] : [for _ in local.alb_app_port : "HTTP"]
336-
337-
# Ensure all arrays have the same length
338-
alb_ports_ammount = min(
339-
length(local.alb_listen_port),
340-
length(local.alb_app_port),
341-
length(local.alb_listen_protocol),
342-
length(local.alb_app_protocol)
343-
)
344-
}
345-
346347
# Outputs
347348
output "aws_alb_dns_name" {
348349
value = aws_lb.vm_alb.dns_name

0 commit comments

Comments
 (0)