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

Allow zero value for cookie_expiration_period #17204

Merged
merged 5 commits into from
Feb 16, 2021
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
3 changes: 3 additions & 0 deletions .changelog/17204.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_lb_cookie_stickiness_policy: Allow zero value for `cookie_expiration_period`
```
2 changes: 1 addition & 1 deletion aws/resource_aws_lb_cookie_stickiness_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func resourceAwsLBCookieStickinessPolicy() *schema.Resource {
Type: schema.TypeInt,
Optional: true,
ForceNew: true,
ValidateFunc: validation.IntAtLeast(1),
ValidateFunc: validation.IntAtLeast(0),
},
},
}
Expand Down
14 changes: 9 additions & 5 deletions aws/resource_aws_lb_cookie_stickiness_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

func TestAccAWSLBCookieStickinessPolicy_basic(t *testing.T) {
lbName := fmt.Sprintf("tf-test-lb-%s", acctest.RandString(5))
resourceName := "aws_lb_cookie_stickiness_policy.foo"
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Expand All @@ -22,6 +23,7 @@ func TestAccAWSLBCookieStickinessPolicy_basic(t *testing.T) {
{
Config: testAccLBCookieStickinessPolicyConfig(lbName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "cookie_expiration_period", "300"),
testAccCheckLBCookieStickinessPolicy(
"aws_elb.lb",
"aws_lb_cookie_stickiness_policy.foo",
Expand All @@ -31,6 +33,7 @@ func TestAccAWSLBCookieStickinessPolicy_basic(t *testing.T) {
{
Config: testAccLBCookieStickinessPolicyConfigUpdate(lbName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "cookie_expiration_period", "0"),
testAccCheckLBCookieStickinessPolicy(
"aws_elb.lb",
"aws_lb_cookie_stickiness_policy.foo",
Expand Down Expand Up @@ -156,14 +159,15 @@ resource "aws_elb" "lb" {
}

resource "aws_lb_cookie_stickiness_policy" "foo" {
name = "foo-policy"
load_balancer = aws_elb.lb.id
lb_port = 80
name = "foo-policy"
load_balancer = aws_elb.lb.id
lb_port = 80
cookie_expiration_period = 300
}
`, rName))
}

// Sets the cookie_expiration_period to 300s.
// Sets the cookie_expiration_period to 0s.
func testAccLBCookieStickinessPolicyConfigUpdate(rName string) string {
return composeConfig(testAccAvailableAZsNoOptInConfig(), fmt.Sprintf(`
resource "aws_elb" "lb" {
Expand All @@ -182,7 +186,7 @@ resource "aws_lb_cookie_stickiness_policy" "foo" {
name = "foo-policy"
load_balancer = aws_elb.lb.id
lb_port = 80
cookie_expiration_period = 300
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typically it is preferable to create new test cases rather than adjust existing tests to ensure we don't miss any regressions, but in this case it is probably okay. Just note that the comment on line 167 is now incorrect and we should probably be verifying these state values with resource.TestCheckResourceAttr() in the test functions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I figured it was probably ok in this case since it was still testing the update functionality. I got the comment fixed and also added checks for the cookie_expiration_period.

cookie_expiration_period = 0
}
`, rName))
}