@@ -7,15 +7,12 @@ locals {
77# ###############################################################################
88
99resource "aws_lb" "this" {
10- name = var. name
11- load_balancer_type = local. load_balancer_type
12- internal = var. internal
13-
14- subnets = var. subnets_ids
15- security_groups = var. security_groups_ids
16-
17- preserve_host_header = var. preserve_host_header
18-
10+ name = try (var. name , null )
11+ load_balancer_type = try (local. load_balancer_type , null )
12+ internal = try (var. internal , null )
13+ subnets = var. subnets_ids
14+ security_groups = var. security_groups_ids
15+ preserve_host_header = var. preserve_host_header
1916 enable_deletion_protection = var. enable_deletion_protection
2017
2118 tags = var. tags
@@ -28,11 +25,11 @@ resource "aws_lb" "this" {
2825resource "aws_lb_target_group" "this" {
2926 for_each = var. target_groups
3027
31- name = each. value . name
32- vpc_id = each. value . vpc_id
33- port = each. value . port
34- protocol = each. value . protocol
35- target_type = each. value . target_type
28+ name = try ( each. value . name , null )
29+ vpc_id = try ( each. value . vpc_id , null )
30+ port = try ( each. value . port , null )
31+ protocol = try ( each. value . protocol , null )
32+ target_type = try ( each. value . target_type , null )
3633
3734 dynamic "health_check" {
3835 for_each = try (each. value . health_check , null ) != null ? [1 ] : []
@@ -62,10 +59,10 @@ resource "aws_lb_listener" "this" {
6259
6360 load_balancer_arn = aws_lb. this . arn
6461
65- certificate_arn = each. value . certificate_arn
66- port = each. value . port
67- protocol = each. value . protocol
68- ssl_policy = each. value . ssl_policy
62+ certificate_arn = try ( each. value . certificate_arn , null )
63+ port = try ( each. value . port , null )
64+ protocol = try ( each. value . protocol , null )
65+ ssl_policy = try ( each. value . ssl_policy , null )
6966
7067 dynamic "default_action" {
7168 for_each = each. value . default_action
@@ -74,7 +71,7 @@ resource "aws_lb_listener" "this" {
7471 content {
7572 type = default_action. value . type
7673 target_group_arn = aws_lb_target_group. this [default_action . value . target_group ]. arn
77- order = default_action. value . order
74+ order = try ( default_action. value . order , null )
7875
7976 dynamic "fixed_response" {
8077 for_each = try (default_action. value . fixed_response , null ) != null ? [1 ] : []
@@ -96,7 +93,7 @@ resource "aws_lb_listener" "this" {
9693
9794 content {
9895 arn = target_group. value . arn
99- weight = target_group. value . weight
96+ weight = try ( target_group. value . weight , null )
10097 }
10198 }
10299
@@ -105,7 +102,7 @@ resource "aws_lb_listener" "this" {
105102
106103 content {
107104 duration = default_action. value . forward . stickiness . duration
108- enabled = try (default_action. value . forward . stickiness . enabled , false )
105+ enabled = try (default_action. value . forward . stickiness . enabled , null )
109106 }
110107 }
111108 }
@@ -146,7 +143,7 @@ resource "aws_lb_listener_rule" "this" {
146143 type = action. value . type
147144 target_group_arn = lookup (
148145 aws_lb_target_group. this ,
149- try (action. value . target_group , " " ),
146+ try (action. value . target_group , null ) != null ? try (action . value . target_group , " " ) : " " ,
150147 null
151148 ) != null ? aws_lb_target_group. this [try (action. value . target_group , null )]. arn : null
152149
0 commit comments