Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

provider/aws: Fix issue with LB Cookie Stickiness and empty expiration period #3908

Merged
merged 2 commits into from
Nov 20, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions builtin/providers/aws/resource_aws_lb_cookie_stickiness_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package aws

import (
"fmt"
"log"
"strings"

"github.com/aws/aws-sdk-go/aws"
Expand Down Expand Up @@ -41,6 +42,14 @@ func resourceAwsLBCookieStickinessPolicy() *schema.Resource {
Type: schema.TypeInt,
Optional: true,
ForceNew: true,
ValidateFunc: func(v interface{}, k string) (ws []string, es []error) {
value := v.(int)
if value <= 0 {
es = append(es, fmt.Errorf(
"LB Cookie Expiration Period must be greater than zero if specified"))
}
return
},
},
},
}
Expand All @@ -51,11 +60,15 @@ func resourceAwsLBCookieStickinessPolicyCreate(d *schema.ResourceData, meta inte

// Provision the LBStickinessPolicy
lbspOpts := &elb.CreateLBCookieStickinessPolicyInput{
CookieExpirationPeriod: aws.Int64(int64(d.Get("cookie_expiration_period").(int))),
LoadBalancerName: aws.String(d.Get("load_balancer").(string)),
PolicyName: aws.String(d.Get("name").(string)),
LoadBalancerName: aws.String(d.Get("load_balancer").(string)),
PolicyName: aws.String(d.Get("name").(string)),
}

if v := d.Get("cookie_expiration_period").(int); v > 0 {
lbspOpts.CookieExpirationPeriod = aws.Int64(int64(v))
}

log.Printf("[DEBUG] LB Cookie Stickiness Policy opts: %#v", lbspOpts)
if _, err := elbconn.CreateLBCookieStickinessPolicy(lbspOpts); err != nil {
return fmt.Errorf("Error creating LBCookieStickinessPolicy: %s", err)
}
Expand All @@ -66,6 +79,7 @@ func resourceAwsLBCookieStickinessPolicyCreate(d *schema.ResourceData, meta inte
PolicyNames: []*string{aws.String(d.Get("name").(string))},
}

log.Printf("[DEBUG] LB Cookie Stickiness create configuration: %#v", setLoadBalancerOpts)
if _, err := elbconn.SetLoadBalancerPoliciesOfListener(setLoadBalancerOpts); err != nil {
return fmt.Errorf("Error setting LBCookieStickinessPolicy: %s", err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ resource "aws_lb_cookie_stickiness_policy" "foo" {
name = "foo-policy"
load_balancer = "${aws_elb.lb.id}"
lb_port = 80
cookie_expiration_period = 600
}
`

Expand Down