From a4743eac338ef7af4637a6e98cee6cb5ba6d781f Mon Sep 17 00:00:00 2001 From: Joel Vasallo Date: Fri, 7 Oct 2016 18:41:54 -0500 Subject: [PATCH 1/5] Enable/Disable option for ALB Access Logs --- builtin/providers/aws/resource_aws_alb.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/builtin/providers/aws/resource_aws_alb.go b/builtin/providers/aws/resource_aws_alb.go index da26ce49b..99ccd4871 100644 --- a/builtin/providers/aws/resource_aws_alb.go +++ b/builtin/providers/aws/resource_aws_alb.go @@ -88,6 +88,11 @@ func resourceAwsAlb() *schema.Resource { Type: schema.TypeString, Optional: true, }, + "enabled": &schema.Schema{ + Type: schema.TypeBool, + Optional: true, + Default: true, + }, }, }, }, @@ -276,7 +281,7 @@ func resourceAwsAlbUpdate(d *schema.ResourceData, meta interface{}) error { attributes = append(attributes, &elbv2.LoadBalancerAttribute{ Key: aws.String("access_logs.s3.enabled"), - Value: aws.String("true"), + Value: aws.String(log["enabled"].(bool)), }, &elbv2.LoadBalancerAttribute{ Key: aws.String("access_logs.s3.bucket"), From e00b2448d8013a20085c5e2abebfab2ac7682e1f Mon Sep 17 00:00:00 2001 From: Joel Vasallo Date: Fri, 7 Oct 2016 19:32:19 -0500 Subject: [PATCH 2/5] Fixed alb access_log enabled type to match that of aws-sdk-go --- builtin/providers/aws/resource_aws_alb.go | 4 ++-- builtin/providers/aws/resource_aws_alb_test.go | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/builtin/providers/aws/resource_aws_alb.go b/builtin/providers/aws/resource_aws_alb.go index 99ccd4871..d1ea9a4a9 100644 --- a/builtin/providers/aws/resource_aws_alb.go +++ b/builtin/providers/aws/resource_aws_alb.go @@ -281,7 +281,7 @@ func resourceAwsAlbUpdate(d *schema.ResourceData, meta interface{}) error { attributes = append(attributes, &elbv2.LoadBalancerAttribute{ Key: aws.String("access_logs.s3.enabled"), - Value: aws.String(log["enabled"].(bool)), + Value: aws.String(strconv.FormatBool(log["enabled"].(bool))), }, &elbv2.LoadBalancerAttribute{ Key: aws.String("access_logs.s3.bucket"), @@ -297,7 +297,7 @@ func resourceAwsAlbUpdate(d *schema.ResourceData, meta interface{}) error { } else if len(logs) == 0 { attributes = append(attributes, &elbv2.LoadBalancerAttribute{ Key: aws.String("access_logs.s3.enabled"), - Value: aws.String("false"), + Value: aws.String(strconv.FormatBool(false)), }) } } diff --git a/builtin/providers/aws/resource_aws_alb_test.go b/builtin/providers/aws/resource_aws_alb_test.go index 168eda6c1..ad45f86da 100644 --- a/builtin/providers/aws/resource_aws_alb_test.go +++ b/builtin/providers/aws/resource_aws_alb_test.go @@ -232,6 +232,7 @@ func TestAccAWSALB_accesslogs(t *testing.T) { resource.TestCheckResourceAttr("aws_alb.alb_test", "access_logs.#", "1"), resource.TestCheckResourceAttr("aws_alb.alb_test", "access_logs.0.bucket", bucketName), resource.TestCheckResourceAttr("aws_alb.alb_test", "access_logs.0.prefix", "testAccAWSALBConfig_accessLogs"), + resource.TestCheckResourceAttr("aws_alb.alb_test", "access_logs.0.enabled", "true"), resource.TestCheckResourceAttrSet("aws_alb.alb_test", "arn"), ), }, @@ -582,6 +583,7 @@ func testAccAWSALBConfig_accessLogs(albName, bucketName string) string { access_logs { bucket = "${aws_s3_bucket.logs.bucket}" prefix = "${var.bucket_prefix}" + enabled = "${var.enabled}" } tags { From 16c1366e6330258b0b86a9539e5c964f47cf505d Mon Sep 17 00:00:00 2001 From: Joel Vasallo Date: Sun, 9 Oct 2016 22:09:41 -0500 Subject: [PATCH 3/5] Reverted alb false logic to be a string instead of converted bool to string --- builtin/providers/aws/resource_aws_alb.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builtin/providers/aws/resource_aws_alb.go b/builtin/providers/aws/resource_aws_alb.go index d1ea9a4a9..4c81911f1 100644 --- a/builtin/providers/aws/resource_aws_alb.go +++ b/builtin/providers/aws/resource_aws_alb.go @@ -297,7 +297,7 @@ func resourceAwsAlbUpdate(d *schema.ResourceData, meta interface{}) error { } else if len(logs) == 0 { attributes = append(attributes, &elbv2.LoadBalancerAttribute{ Key: aws.String("access_logs.s3.enabled"), - Value: aws.String(strconv.FormatBool(false)), + Value: aws.String("false"), }) } } From f290a3a955803787daa509879900dbf40ea7587e Mon Sep 17 00:00:00 2001 From: Joel Vasallo Date: Mon, 10 Oct 2016 09:46:28 -0500 Subject: [PATCH 4/5] ALB: Enabled s3.enabled and changed default value of s3.enabled - Disabled access logs by default - Enabled case to set value of s3.enabled --- builtin/providers/aws/resource_aws_alb.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/builtin/providers/aws/resource_aws_alb.go b/builtin/providers/aws/resource_aws_alb.go index 4c81911f1..4ad27f832 100644 --- a/builtin/providers/aws/resource_aws_alb.go +++ b/builtin/providers/aws/resource_aws_alb.go @@ -91,7 +91,7 @@ func resourceAwsAlb() *schema.Resource { "enabled": &schema.Schema{ Type: schema.TypeBool, Optional: true, - Default: true, + Default: false, }, }, }, @@ -234,6 +234,8 @@ func resourceAwsAlbRead(d *schema.ResourceData, meta interface{}) error { accessLogMap := map[string]interface{}{} for _, attr := range attributesResp.Attributes { switch *attr.Key { + case "access_logs.s3.enabled": + accessLogMap["enabled"] = *attr.Value case "access_logs.s3.bucket": accessLogMap["bucket"] = *attr.Value case "access_logs.s3.prefix": From 7dd376216bb445d14325e93f9cfa7c7c2e3550e1 Mon Sep 17 00:00:00 2001 From: Joel Vasallo Date: Mon, 10 Oct 2016 10:05:13 -0500 Subject: [PATCH 5/5] Added documentation around access_logs enabled and reverted default value to true --- builtin/providers/aws/resource_aws_alb.go | 2 +- website/source/docs/providers/aws/r/alb.html.markdown | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/builtin/providers/aws/resource_aws_alb.go b/builtin/providers/aws/resource_aws_alb.go index 4ad27f832..757f82165 100644 --- a/builtin/providers/aws/resource_aws_alb.go +++ b/builtin/providers/aws/resource_aws_alb.go @@ -91,7 +91,7 @@ func resourceAwsAlb() *schema.Resource { "enabled": &schema.Schema{ Type: schema.TypeBool, Optional: true, - Default: false, + Default: true, }, }, }, diff --git a/website/source/docs/providers/aws/r/alb.html.markdown b/website/source/docs/providers/aws/r/alb.html.markdown index e69a92a87..982da0ee2 100644 --- a/website/source/docs/providers/aws/r/alb.html.markdown +++ b/website/source/docs/providers/aws/r/alb.html.markdown @@ -54,6 +54,7 @@ Access Logs (`access_logs`) support the following: * `bucket` - (Required) The S3 bucket name to store the logs in. * `prefix` - (Optional) The S3 bucket prefix. Logs are stored in the root if not configured. +* `enabled` = (Optional) Boolean to enable / disable `access_logs`. Default is `true` ## Attributes Reference