Skip to content

Commit f0ab9e1

Browse files
author
Steven Nemetz
committed
Separate LB resource into application and network resources
1 parent dd06fec commit f0ab9e1

File tree

2 files changed

+21
-14
lines changed

2 files changed

+21
-14
lines changed

main.tf

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,6 @@ data "aws_acm_certificate" "this" {
6161
domain = "${var.certificate_name != "" ? var.certificate_name : local.cert_name }"
6262
}
6363

64-
# TODO: need to separate into 2 resources to support logging, since network doesn't
65-
/*
6664
resource "aws_lb" "application" {
6765
count = "${module.enabled.value && var.type == "application" ? 1 : 0}"
6866
name = "${module.label.id_32}"
@@ -91,10 +89,10 @@ resource "aws_lb" "application" {
9189
delete =
9290
update =
9391
}
94-
*//*
92+
*/
9593
depends_on = ["aws_s3_bucket.log_bucket"]
9694
}
97-
/*
95+
9896
resource "aws_lb" "network" {
9997
count = "${module.enabled.value && var.type == "network" ? 1 : 0}"
10098
name = "${module.label.id_32}"
@@ -117,9 +115,10 @@ resource "aws_lb" "network" {
117115
delete =
118116
update =
119117
}
120-
*//*
118+
*/
121119
}
122-
*/
120+
121+
/*
123122
resource "aws_lb" "this" {
124123
count = "${module.enabled.value}"
125124
name = "${module.label.id_32}"
@@ -151,9 +150,10 @@ resource "aws_lb" "this" {
151150
delete =
152151
update =
153152
}
154-
*/
153+
*//*
155154
depends_on = ["aws_s3_bucket.log_bucket"]
156155
}
156+
*/
157157

158158
data "aws_iam_policy_document" "bucket_policy" {
159159
count = "${
@@ -326,7 +326,8 @@ resource "aws_lb_listener" "http" {
326326
var.type == "application" &&
327327
contains(var.lb_protocols, "HTTP")
328328
? length(compact(split(",", local.lb_http_ports))) : 0}"
329-
load_balancer_arn = "${aws_lb.this.arn}"
329+
#load_balancer_arn = "${aws_lb.this.arn}" # "${coalesce(aws_lb.application.arn, aws_lb.network.arn)}"
330+
load_balancer_arn = "${coalesce(aws_lb.application.arn, aws_lb.network.arn)}"
330331
port = "${element(compact(split(",",local.lb_http_ports)), count.index)}"
331332
protocol = "HTTP"
332333
default_action {
@@ -342,7 +343,8 @@ resource "aws_lb_listener" "https" {
342343
var.type == "application" &&
343344
contains(var.lb_protocols, "HTTPS")
344345
? length(compact(split(",", local.lb_https_ports))) : 0}"
345-
load_balancer_arn = "${aws_lb.this.arn}"
346+
#load_balancer_arn = "${aws_lb.this.arn}" # "${coalesce(aws_lb.application.arn, aws_lb.network.arn)}"
347+
load_balancer_arn = "${coalesce(aws_lb.application.arn, aws_lb.network.arn)}"
346348
port = "${element(compact(split(",",local.lb_https_ports)), count.index)}"
347349
protocol = "HTTPS"
348350
certificate_arn = "${element(concat(data.aws_acm_certificate.this.*.arn, list("")), 0)}"
@@ -359,7 +361,8 @@ resource "aws_lb_listener" "network" {
359361
module.enabled.value &&
360362
var.type == "network"
361363
? length(compact(split(",", local.lb_tcp_ports))) : 0}"
362-
load_balancer_arn = "${aws_lb.this.arn}"
364+
#load_balancer_arn = "${aws_lb.this.arn}" # "${coalesce(aws_lb.application.arn, aws_lb.network.arn)}"
365+
load_balancer_arn = "${coalesce(aws_lb.application.arn, aws_lb.network.arn)}"
363366
port = "${element(compact(split(",",local.lb_tcp_ports)), count.index)}"
364367
protocol = "TCP"
365368
default_action {

outputs.tf

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,23 @@
33
//
44
output "arn" {
55
description = "ARN of the LB itself. Useful for debug output, for example when attaching a WAF."
6-
value = "${element(concat(aws_lb.this.*.arn, list("")), 0)}"
6+
#value = "${element(concat(aws_lb.this.*.arn, list("")), 0)}"
7+
value = "${element(concat(aws_lb.application.*.arn, aws_lb.network.*.arn, list("")), 0)}"
78
}
89
output "dns_name" {
910
description = "The DNS name of the LB presumably to be used with a friendlier CNAME."
10-
value = "${element(concat(aws_lb.this.*.dns_name, list("")), 0)}"
11+
#value = "${element(concat(aws_lb.this.*.dns_name, list("")), 0)}"
12+
value = "${element(concat(aws_lb.application.*.dns_name, aws_lb.network.*.dns_name, list("")), 0)}"
1113
}
1214
output "id" {
1315
description = "The ID of the LB we created."
14-
value = "${element(concat(aws_lb.this.*.id, list("")), 0)}"
16+
#value = "${element(concat(aws_lb.this.*.id, list("")), 0)}"
17+
value = "${element(concat(aws_lb.application.*.id, aws_lb.network.*.id, list("")), 0)}"
1518
}
1619
output "zone_id" {
1720
description = "The zone_id of the LB to assist with creating DNS records."
18-
value = "${element(concat(aws_lb.this.*.zone_id, list("")), 0)}"
21+
#value = "${element(concat(aws_lb.this.*.zone_id, list("")), 0)}"
22+
value = "${element(concat(aws_lb.application.*.zone_id, aws_lb.network.*.zone_id, list("")), 0)}"
1923
}
2024
# arn_suffix
2125
# canonical_hosted_zone_id

0 commit comments

Comments
 (0)