diff --git a/README.md b/README.md index b140208..45a7955 100644 --- a/README.md +++ b/README.md @@ -35,8 +35,8 @@ For an example of using ALB with ECS look no further than the [hashicorp example * `certificate_arn` - . (Required if using HTTPS in `alb_protocols`) * `cookie_duration` - If sticky sessions via cookies are desired, set this variable to a value from 2 - 604800 seconds. (Optional) * `health_check_path` - Path for the load balancer to health check instances. (Optional; default: /) -* `log_bucket` - S3 bucket where access logs should land. (Required) -* `log_prefix` - S3 prefix within the `log_bucket` where logs should land. (Optional) +* `log_bucket` - S3 bucket where access logs should land. If not set it will be not leave logs. (Optional; default: "") +* `log_prefix` - S3 prefix within the `log_bucket` where logs should land. (Optional; default: "") * `principle_account_id` - A mapping of regions to principle account IDs used to send LB logs. (Should only change as regions are added) * `subnets` - ALB will be created in the subnets in this list. (Required) * `vpc_id` - Resources will be created in the VPC with this `id`. (Required) diff --git a/alb/main.tf b/alb/main.tf index ae49129..d0bb81b 100644 --- a/alb/main.tf +++ b/alb/main.tf @@ -21,14 +21,16 @@ resource "aws_alb" "main" { internal = "${var.alb_is_internal}" access_logs { - bucket = "${var.log_bucket}" - prefix = "${var.log_prefix}" + bucket = "${var.log_bucket}" + prefix = "${var.log_prefix}" + enabled = "${var.log_bucket != ""}" } tags = "${merge(var.tags, map("Name", format("%s", var.alb_name)))}" } resource "aws_s3_bucket" "log_bucket" { + count = "${var.log_bucket != "" ? 1 : 0}" bucket = "${var.log_bucket}" policy = "${data.template_file.bucket_policy.rendered}" force_destroy = true diff --git a/alb/variables.tf b/alb/variables.tf index e00a350..797178b 100644 --- a/alb/variables.tf +++ b/alb/variables.tf @@ -56,10 +56,12 @@ variable "health_check_path" { variable "log_bucket" { description = "S3 bucket for storing ALB access logs." + default = "" } variable "log_prefix" { description = "S3 prefix within the log_bucket under which logs are stored." + default = "" } variable "principle_account_id" {