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

aws_lb_cookie_stickiness_policy doesn't support cookie_expiration_period = 0 #12678

Closed
haidangwa opened this issue Apr 4, 2020 · 4 comments · Fixed by #17204
Closed

aws_lb_cookie_stickiness_policy doesn't support cookie_expiration_period = 0 #12678

haidangwa opened this issue Apr 4, 2020 · 4 comments · Fixed by #17204
Labels
bug Addresses a defect in current functionality. service/elb Issues and PRs that pertain to the elb service.
Milestone

Comments

@haidangwa
Copy link

haidangwa commented Apr 4, 2020

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Terraform Version

$ terraform --version
Terraform v0.12.24
+ provider.aws v2.49.0
+ provider.local v1.4.0
+ provider.null v2.1.2
+ provider.template v2.1.2
+ provider.tls v2.1.1

Affected Resource(s)

  • aws_lb_cookie_stickiness_policy

Terraform Configuration Files

resource "aws_lb_cookie_stickiness_policy" "elb" {
  name                     = "ELBCookiePolicy-${var.hostname}-${var.environment}"
  load_balancer            = aws_elb.elb.id
  lb_port                  = var.elb_listener_port
  cookie_expiration_period = 0
}

Debug Output

Panic Output

Expected Behavior

According to AWS documentation, setting cookie_expiration_period = 0 or not including this property in the config should be supported.

--cookie-expiration-period (long)

The time period, in seconds, after which the cookie should be considered stale. If you do not specify this parameter, the default value is 0, which indicates that the sticky session should last for the duration of the browser session.

Actual Behavior

Error: expected cookie_expiration_period to be at least (1), got 0

  on modules/classic_lb/main.tf line 34, in resource "aws_lb_cookie_stickiness_policy" "elb":
  34: resource "aws_lb_cookie_stickiness_policy" "elb" {



Error: expected cookie_expiration_period to be at least (1), got 0

  on modules/classic_lb/main.tf line 34, in resource "aws_lb_cookie_stickiness_policy" "elb":
  34: resource "aws_lb_cookie_stickiness_policy" "elb" {

Leaving this property out of the resource configuration creates the policy with expirationPeriod=0

This configuration works:

resource "aws_lb_cookie_stickiness_policy" "elb" {
  name          = "ELBCookiePolicy-${var.hostname}-${var.environment}"
  load_balancer = aws_elb.elb.id
  lb_port       = var.elb_listener_port
}

Steps to Reproduce

Create a classic load balancer and attach the aws_lb_cookie_stickiness_policy resource to it. Then run terraform plan

@ghost ghost added service/elb Issues and PRs that pertain to the elb service. service/elbv2 Issues and PRs that pertain to the elbv2 service. labels Apr 4, 2020
@github-actions github-actions bot added the needs-triage Waiting for first response or review from a maintainer. label Apr 4, 2020
@DrFaust92
Copy link
Collaborator

the aws sdk fails on validation when the value is zero. so i guess this was done in the provider to guard against this as well

@jimbrowne
Copy link

jimbrowne commented Sep 15, 2020

This is also a problem with aws_load_balancer_policy and policy_type_name = "LBCookieStickinessPolicyType".

If one includes a stanza of:

policy_attribute {
          name  = "CookieExpirationPeriod"
          value = "0"
        }

a validation error will be thrown by Terraform that the value must be a non-zero long.

But if one uses:

resource "aws_load_balancer_policy" "cookie-sticky" {
  load_balancer_name = aws_elb.elb[count.index].name
  count              = var.enable ? 1 : 0
  policy_name        = "${var.name}-cookie-sticky"   
  policy_type_name   = "LBCookieStickinessPolicyType"
}

this will apply the first time and create a policy with a value of zero, however on every subsequent apply a change is applied:

# module.lms-infrastructure.module.elbs.module.elk-vip.aws_load_balancer_policy.cookie-sticky[0] will be updated in-place
  ~ resource "aws_load_balancer_policy" "cookie-sticky" {
        id                 = "foo-elk:foo-elk-cookie-sticky"  
        load_balancer_name = "foo-elk"
        policy_name        = "foo-elk-cookie-sticky"
        policy_type_name   = "LBCookieStickinessPolicyType"

      - policy_attribute {
          - name  = "CookieExpirationPeriod" -> null
          - value = "0" -> null
        }
    }

But if the policy_attribute stanza is added after the ELB policy already exists no change will be flagged.

So there's some round trip problem happening here with the AWS API.

@bflad bflad added bug Addresses a defect in current functionality. and removed needs-triage Waiting for first response or review from a maintainer. service/elbv2 Issues and PRs that pertain to the elbv2 service. labels Feb 4, 2021
@github-actions github-actions bot added this to the v3.29.0 milestone Feb 16, 2021
@ghost
Copy link

ghost commented Feb 19, 2021

This has been released in version 3.29.0 of the Terraform AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template for triage. Thanks!

@ghost
Copy link

ghost commented Mar 19, 2021

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

@ghost ghost locked as resolved and limited conversation to collaborators Mar 19, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Addresses a defect in current functionality. service/elb Issues and PRs that pertain to the elb service.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants