Skip to content

Commit

Permalink
Always set load balancer access log bucket prefix.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcarp committed May 2, 2018
1 parent 1d5d36a commit e0553b3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 20 deletions.
15 changes: 5 additions & 10 deletions aws/resource_aws_elb.go
Original file line number Diff line number Diff line change
Expand Up @@ -584,17 +584,12 @@ func resourceAwsElbUpdate(d *schema.ResourceData, meta interface{}) error {
logs := d.Get("access_logs").([]interface{})
if len(logs) == 1 {
l := logs[0].(map[string]interface{})
accessLog := &elb.AccessLog{
Enabled: aws.Bool(l["enabled"].(bool)),
EmitInterval: aws.Int64(int64(l["interval"].(int))),
S3BucketName: aws.String(l["bucket"].(string)),
}

if l["bucket_prefix"] != "" {
accessLog.S3BucketPrefix = aws.String(l["bucket_prefix"].(string))
attrs.LoadBalancerAttributes.AccessLog = &elb.AccessLog{
Enabled: aws.Bool(l["enabled"].(bool)),
EmitInterval: aws.Int64(int64(l["interval"].(int))),
S3BucketName: aws.String(l["bucket"].(string)),
S3BucketPrefix: aws.String(l["bucket_prefix"].(string)),
}

attrs.LoadBalancerAttributes.AccessLog = accessLog
} else if len(logs) == 0 {
// disable access logs
attrs.LoadBalancerAttributes.AccessLog = &elb.AccessLog{
Expand Down
14 changes: 4 additions & 10 deletions aws/resource_aws_lb.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package aws

import (
"bytes"
"fmt"
"log"
"regexp"
"strconv"
"time"

"bytes"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/aws/aws-sdk-go/service/elbv2"
Expand Down Expand Up @@ -139,13 +138,11 @@ func resourceAwsLb() *schema.Resource {
"prefix": {
Type: schema.TypeString,
Optional: true,
Computed: true,
DiffSuppressFunc: suppressIfLBType("network"),
},
"enabled": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
DiffSuppressFunc: suppressIfLBType("network"),
},
},
Expand Down Expand Up @@ -361,14 +358,11 @@ func resourceAwsLbUpdate(d *schema.ResourceData, meta interface{}) error {
&elbv2.LoadBalancerAttribute{
Key: aws.String("access_logs.s3.bucket"),
Value: aws.String(log["bucket"].(string)),
})

if prefix, ok := log["prefix"]; ok {
attributes = append(attributes, &elbv2.LoadBalancerAttribute{
},
&elbv2.LoadBalancerAttribute{
Key: aws.String("access_logs.s3.prefix"),
Value: aws.String(prefix.(string)),
Value: aws.String(log["prefix"].(string)),
})
}
} else if len(logs) == 0 {
attributes = append(attributes, &elbv2.LoadBalancerAttribute{
Key: aws.String("access_logs.s3.enabled"),
Expand Down

0 comments on commit e0553b3

Please sign in to comment.