From a4743eac338ef7af4637a6e98cee6cb5ba6d781f Mon Sep 17 00:00:00 2001 From: Joel Vasallo Date: Fri, 7 Oct 2016 18:41:54 -0500 Subject: [PATCH 1/6] 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/6] 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/6] 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/6] 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/6] 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 From b3a0145d8c8082f1479a6fbfa5f3a9d91b4393f6 Mon Sep 17 00:00:00 2001 From: stack72 Date: Thu, 27 Oct 2016 12:12:00 +0100 Subject: [PATCH 6/6] provider/aws: Fixing the acceptance test for ALB AccessLogs Enabling toggle MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ``` % make testacc TEST=./builtin/providers/aws % TESTARGS='-run=TestAccAWSALB_' % ✹ ✭ ==> Checking that code complies with gofmt requirements... go generate $(go list ./... | grep -v /terraform/vendor/) 2016/10/27 12:04:29 Generated command/internal_plugin_list.go TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSALB_ -timeout 120m === RUN TestAccAWSALB_basic --- PASS: TestAccAWSALB_basic (61.86s) === RUN TestAccAWSALB_generatedName --- PASS: TestAccAWSALB_generatedName (63.51s) === RUN TestAccAWSALB_namePrefix --- PASS: TestAccAWSALB_namePrefix (61.93s) === RUN TestAccAWSALB_tags --- PASS: TestAccAWSALB_tags (95.84s) === RUN TestAccAWSALB_noSecurityGroup --- PASS: TestAccAWSALB_noSecurityGroup (60.01s) === RUN TestAccAWSALB_accesslogs --- PASS: TestAccAWSALB_accesslogs (156.99s) PASS ok github.com/hashicorp/terraform/builtin/providers/aws500.162s ``` --- builtin/providers/aws/resource_aws_alb.go | 2 +- .../providers/aws/resource_aws_alb_test.go | 29 +++++++++++++++---- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/builtin/providers/aws/resource_aws_alb.go b/builtin/providers/aws/resource_aws_alb.go index 757f82165..fc5510523 100644 --- a/builtin/providers/aws/resource_aws_alb.go +++ b/builtin/providers/aws/resource_aws_alb.go @@ -88,7 +88,7 @@ func resourceAwsAlb() *schema.Resource { Type: schema.TypeString, Optional: true, }, - "enabled": &schema.Schema{ + "enabled": { Type: schema.TypeBool, Optional: true, Default: true, diff --git a/builtin/providers/aws/resource_aws_alb_test.go b/builtin/providers/aws/resource_aws_alb_test.go index ad45f86da..7cfd88b40 100644 --- a/builtin/providers/aws/resource_aws_alb_test.go +++ b/builtin/providers/aws/resource_aws_alb_test.go @@ -213,9 +213,8 @@ func TestAccAWSALB_accesslogs(t *testing.T) { resource.TestCheckResourceAttrSet("aws_alb.alb_test", "arn"), ), }, - { - Config: testAccAWSALBConfig_accessLogs(albName, bucketName), + Config: testAccAWSALBConfig_accessLogs(true, albName, bucketName), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckAWSALBExists("aws_alb.alb_test", &conf), resource.TestCheckResourceAttr("aws_alb.alb_test", "name", albName), @@ -236,6 +235,26 @@ func TestAccAWSALB_accesslogs(t *testing.T) { resource.TestCheckResourceAttrSet("aws_alb.alb_test", "arn"), ), }, + { + Config: testAccAWSALBConfig_accessLogs(false, albName, bucketName), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckAWSALBExists("aws_alb.alb_test", &conf), + resource.TestCheckResourceAttr("aws_alb.alb_test", "name", albName), + resource.TestCheckResourceAttr("aws_alb.alb_test", "internal", "false"), + resource.TestCheckResourceAttr("aws_alb.alb_test", "subnets.#", "2"), + resource.TestCheckResourceAttr("aws_alb.alb_test", "security_groups.#", "1"), + resource.TestCheckResourceAttr("aws_alb.alb_test", "tags.%", "1"), + resource.TestCheckResourceAttr("aws_alb.alb_test", "tags.TestName", "TestAccAWSALB_basic1"), + resource.TestCheckResourceAttr("aws_alb.alb_test", "enable_deletion_protection", "false"), + resource.TestCheckResourceAttr("aws_alb.alb_test", "idle_timeout", "50"), + resource.TestCheckResourceAttrSet("aws_alb.alb_test", "vpc_id"), + resource.TestCheckResourceAttrSet("aws_alb.alb_test", "zone_id"), + resource.TestCheckResourceAttrSet("aws_alb.alb_test", "dns_name"), + resource.TestCheckResourceAttr("aws_alb.alb_test", "access_logs.#", "1"), + resource.TestCheckResourceAttr("aws_alb.alb_test", "access_logs.0.enabled", "false"), + resource.TestCheckResourceAttrSet("aws_alb.alb_test", "arn"), + ), + }, }, }) } @@ -570,7 +589,7 @@ resource "aws_security_group" "alb_test" { }`, albName) } -func testAccAWSALBConfig_accessLogs(albName, bucketName string) string { +func testAccAWSALBConfig_accessLogs(enabled bool, albName, bucketName string) string { return fmt.Sprintf(`resource "aws_alb" "alb_test" { name = "%s" internal = false @@ -583,7 +602,7 @@ func testAccAWSALBConfig_accessLogs(albName, bucketName string) string { access_logs { bucket = "${aws_s3_bucket.logs.bucket}" prefix = "${var.bucket_prefix}" - enabled = "${var.enabled}" + enabled = "%t" } tags { @@ -678,7 +697,7 @@ resource "aws_security_group" "alb_test" { tags { TestName = "TestAccAWSALB_basic" } -}`, albName, bucketName) +}`, albName, enabled, bucketName) } func testAccAWSALBConfig_nosg(albName string) string {