Skip to content

Commit 2540feb

Browse files
author
Steven Nemetz
committed
Do not create any S3 related resources when logging is disabled
1 parent a026f6d commit 2540feb

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

main.tf

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
# and S3 for logging, retrieve SSL cert from ACM
44
# ?? security groups, dns
55
#
6+
# AWS provider 1.6 had some breaking changes. This supports 1.6
7+
#
68
# https://www.terraform.io/docs/providers/aws/r/lb.html
79
# https://www.terraform.io/docs/providers/aws/r/lb_listener.html
810
# https://www.terraform.io/docs/providers/aws/r/lb_listener_rule.html
@@ -14,6 +16,12 @@
1416
# TODO Future:
1517
# Multiple LBs ?
1618

19+
module "enable_logging" {
20+
source = "devops-workflow/boolean/local"
21+
version = "0.1.0"
22+
value = "${var.enable_logging}"
23+
}
24+
1725
module "enabled" {
1826
source = "devops-workflow/boolean/local"
1927
version = "0.1.0"
@@ -76,7 +84,7 @@ resource "aws_lb" "this" {
7684
access_logs {
7785
bucket = "${var.log_bucket_name}"
7886
prefix = "${var.log_location_prefix}"
79-
enabled = "${var.enable_logging}"
87+
enabled = "${module.enable_logging.value}"
8088
}
8189
*/
8290
/*
@@ -96,7 +104,10 @@ resource "aws_lb" "this" {
96104
}
97105

98106
data "aws_iam_policy_document" "bucket_policy" {
99-
count = "${module.enabled.value && var.create_log_bucket ? 1 : 0}"
107+
count = "${
108+
module.enabled.value &&
109+
module.enable_logging.value &&
110+
var.create_log_bucket ? 1 : 0}"
100111
statement {
101112
sid = "AllowToPutLoadBalancerLogsToS3Bucket"
102113
actions = [
@@ -113,7 +124,10 @@ data "aws_iam_policy_document" "bucket_policy" {
113124
}
114125

115126
resource "aws_s3_bucket" "log_bucket" {
116-
count = "${module.enabled.value && var.create_log_bucket ? 1 : 0}"
127+
count = "${
128+
module.enabled.value &&
129+
module.enable_logging.value &&
130+
var.create_log_bucket ? 1 : 0}"
117131
bucket = "${var.log_bucket_name}"
118132
#acl
119133
policy = "${var.bucket_policy == "" ? data.aws_iam_policy_document.bucket_policy.json : var.bucket_policy}"
@@ -241,7 +255,6 @@ resource "aws_lb_target_group" "network" {
241255
health_check {
242256
interval = "${var.health_check_interval}"
243257
port = "${var.health_check_port}"
244-
#path = "/"
245258
healthy_threshold = "${var.health_check_healthy_threshold}"
246259
unhealthy_threshold = "${var.health_check_unhealthy_threshold}"
247260
protocol = "${var.health_check_protocol}"

0 commit comments

Comments
 (0)