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_listener_rule: Stickiness block not removed from state #15144

Closed
ian-bartholomew opened this issue Sep 14, 2020 · 11 comments · Fixed by #35671
Closed

aws_lb_listener_rule: Stickiness block not removed from state #15144

ian-bartholomew opened this issue Sep 14, 2020 · 11 comments · Fixed by #35671
Assignees
Labels
bug Addresses a defect in current functionality. prioritized Part of the maintainer teams immediate focus. To be addressed within the current quarter. service/elbv2 Issues and PRs that pertain to the elbv2 service.
Milestone

Comments

@ian-bartholomew
Copy link

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 CLI and Terraform AWS Provider Version

$ terraform -v
Terraform v0.12.29
+ provider.aws v3.2.0
+ provider.null v2.1.2

Affected Resource(s)

  • aws_XXXXX

Terraform Configuration Files

resource "aws_lb_listener_rule" "httpsecure_prod" {
  count        = local.is_prod ? 1 : 0
  depends_on   = [null_resource.health]
  listener_arn = data.aws_alb_listener.https.arn

  priority = 48001


  action {
    order = 1
    type  = "forward"
    forward {

      dynamic "target_group" {
        for_each = local.target_groups

        content {
          arn    = target_group.value.arn
          weight = target_group.value.weight
        }
      }
    }
  }

  condition {
    host_header {
      values = [
        "foo.com",
        "bar.foo.com"
      ]
    }
  }
}

Expected Behavior

When stickiness is not declared in the resource, the listener rule should not use it

Actual Behavior

We had previously had a rule with stickiness enabled, and applied it. Later our use case changed and we removed it. Yesterday we went to update the rule and got this error when applying:

aws_lb_listener_rule.httpsecure_prod[0]: Modifying... [id=arn:aws:elasticloadbalancing:*********:xxxx:listener-rule/app/foo-production-app/xxx/xxx/xxx]

Error: Error modifying LB Listener Rule: ValidationError: Target group stickiness duration must be between 1 and 604800 seconds
	status code: 400, request id: xxx-xxx-xxx-xxx-xxxxx

Checking in the AWS console, the listener rule didn't have stickiness enabled. Looking into the plan, we can see that the plan does include the stickiness:

resource "aws_lb_listener_rule" "httpsecure_prod" {
      ...
      ~ action {
            order = 1
            type  = "forward"

          ~ forward {
                stickiness {
                    duration = 0
                    enabled  = false
                }
            ... 
            }
        }
}

Steps to Reproduce

  1. terraform apply with stickiness defied in an aws_lb_listener_rule
  2. Remove the stickiness block from the rule
  3. Run terraform apply again, and notice the above error.
@ghost ghost added the service/elbv2 Issues and PRs that pertain to the elbv2 service. label Sep 14, 2020
@github-actions github-actions bot added the needs-triage Waiting for first response or review from a maintainer. label Sep 14, 2020
@anGie44 anGie44 added bug Addresses a defect in current functionality. and removed needs-triage Waiting for first response or review from a maintainer. labels Sep 15, 2020
@anGie44
Copy link
Contributor

anGie44 commented Sep 15, 2020

Hi @ian-bartholomew, thank you for creating this issue! Looking at the plan output you've provided as well as reproducing this locally, seems there's a bug in the diff created as the entire stickiness block should be marked for removal with something like:

  ~ action {
            order = 1
            type  = "forward"

          ~ forward {
              - stickiness {
                  - duration = 3600 -> null
                  - enabled  = true -> null
                }

This could stem from some custom logic in the resource that modifies the diff behavior, so further investigation is needed. In the meantime, I would recommend disabling stickiness with enabled=false instead of removing the entire block as this behavior here will persist.

@ian-bartholomew
Copy link
Author

@anGie44 Sorry for the late reply, but thank you. I did what you suggested as a workaround and that worked. Thanks!

@likai057187
Copy link

likai057187 commented Nov 15, 2020

Hopefully the information below is helpful for you guys. My terraform version is 0.12.24 though. But by checking the release nots, I don't think it makes any difference from your TF version.

I think terraform is unable to remove the stickiness because it's trying to set duration value back to 0. However, the minimum value of the duration is 1 in AWS. That's exactly what you got from the error.

I'm actually getting the same error with different scenario, see follow steps:

  1. Apply a listener rule with 100% traffic forwarding to target group 1 and 0% traffic to target group 2.
  2. Adjust the percentages to 80% vs 20%
  3. Apply again.
  4. Got the same error as yours.

It seems like the default stickiness state in terraform is:
stickiness {
duration = 0
enabled = false
}
Which is wrong.

So couple of problems here:

  1. Default stickiness state is wrong.
  2. Why we even need to update the stickiness state since in my case I'm not using it from beginning to the end.
  3. "duration" is a required field in stickiness block. If that's intended, this document may need to be updated: https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lb_listener_rule

@bcsgh
Copy link

bcsgh commented Dec 1, 2020

I've run into exactly the same case as likai057187. It seems that a workaround is to use:

stickiness {
  duration = 1  // Or any other non-zero value.
  enabled  = false
}

@wesley-staples
Copy link

This is still an issue with terraform 14.4 and "registry.terraform.io/hashicorp/aws" 3.29.1

bcsgh's workaround has resolved this for me.

@nueces
Copy link

nueces commented Jun 24, 2021

Having the same issue here, this is my conf

resource "aws_lb_listener" "https" {
  load_balancer_arn = aws_lb.alb.arn
  port              = "443"
  protocol          = "HTTPS"
  ssl_policy        = "ELBSecurityPolicy-TLS-1-2-2017-01"
  certificate_arn   = data.aws_acm_certificate.main_domain.arn

  default_action {
    order = 1
    type  = "forward"

    forward {
      stickiness {
        duration = 1
        enabled  = false
      }
      target_group {
        arn    = aws_lb_target_group.blue.arn
        weight = 100
      }
      target_group {
        arn    = aws_lb_target_group.green.arn
        weight = 0
      }
    }
  }

but every time that I made a plan got this drift

      ~ default_action {
            # (2 unchanged attributes hidden)

          ~ forward {
              ~ stickiness {
                  ~ duration = 1 -> 0
                    # (1 unchanged attribute hidden)
                }

                # (2 unchanged blocks hidden)
            }
        }

But if inside of the stickiness block I set the duration = 0 got this error

Error: expected default_action.0.forward.0.stickiness.0.duration to be in the range (1 - 604800), got 0

  with aws_lb_listener.https,
  on webservers.tf line 194, in resource "aws_lb_listener" "https":
 194:         enabled  = false

I been try to add a ignore_changes in the lifecycle without luck

  lifecycle {
    ignore_changes = [
      default_action[0].forward[0].stickiness[0].duration,
    ]
  }

@deepdish24
Copy link

Has this issue been fixed yet? I am still running into it and the workarounds mentioned here did not work for me

@GreasyAvocado
Copy link

Any update on this?

@gdavison
Copy link
Contributor

Related to #22526

@gdavison gdavison self-assigned this Jan 15, 2024
@terraform-aws-provider terraform-aws-provider bot added the prioritized Part of the maintainer teams immediate focus. To be addressed within the current quarter. label Jan 15, 2024
@github-actions github-actions bot added this to the v5.36.0 milestone Feb 7, 2024
@github-actions github-actions bot removed the bug Addresses a defect in current functionality. label Feb 8, 2024
Copy link

github-actions bot commented Feb 8, 2024

This functionality has been released in v5.36.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. Thank you!

@justinretzolk justinretzolk added the bug Addresses a defect in current functionality. label Feb 10, 2024
Copy link

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 have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 12, 2024
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. prioritized Part of the maintainer teams immediate focus. To be addressed within the current quarter. service/elbv2 Issues and PRs that pertain to the elbv2 service.
Projects
None yet
10 participants