hashicorp / terraform-provider-aws

The AWS Provider enables Terraform to manage AWS resources.
https://registry.terraform.io/providers/hashicorp/aws
Mozilla Public License 2.0
9.8k stars 9.15k forks source link

[Bug]: Fixed-response in ALB listener rule fails with multibyte characters exceeding 342 characters #37802

Open akhn1004 opened 4 months ago

akhn1004 commented 4 months ago

Terraform Core Version

1.7.5

AWS Provider Version

5.5.2

Affected Resource(s)

Expected Behavior

Can be configured with 1024 characters (even multi byte characters).

Actual Behavior

Failure in terraform plan.

Error: expected length of action.0.fixed_response.0.message_body to be in the range (0 - 1024), got ......

Relevant Error/Panic Output Snippet

│ Error: expected length of action.0.fixed_response.0.message_body to be in the range (0 - 1024), got 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012
│
│   with aws_lb_listener_rule.test,
│   on share_elb_main.tf line 94, in resource "aws_lb_listener_rule" "test":
│   94:       message_body = "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012"

Terraform Configuration Files

resource "aws_lb_listener_rule" "test" {
  listener_arn = aws_alb_listener.test.arn
  priority     = 100
  action {
    type = "fixed-response"

    fixed_response {
      content_type = "text/plain"
      message_body = "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012"
      status_code  = 200
    }
  }

Steps to Reproduce

  1. Create an empty AWS ALB.
  2. Create an empty AWS ELB listener.
  3. Create an empty AWS ELB target group.
  4. Create a AWS ELB listerner rule with fixed_response. Set 342 characters in message body of fixed_response.

Debug Output

No response

Panic Output

No response

Important Factoids

No response

References

No response

Would you like to implement a fix?

None

github-actions[bot] commented 4 months ago

Community Note

Voting for Prioritization

Volunteering to Work on This Issue

akhn1004 commented 4 months ago

I set default_action / fixed_response to ELB listener and set more than 342 characters as well and it failed with plan as well.

justinretzolk commented 4 months ago

@akhn1004 👋 Thanks for taking the time to raise this! It looks like the validation is checking byte length rather than character length (removing a couple of characters to get it under 1024 bytes made the validation pass). Are you able to do the same from the API without issue?

$ export TEST_STRING='12345678901234567890123456789012345678901234567890123456789012345678901234567890 1234567890123456789012345678901234567890123456789012345678901234567890123456 789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012'

# byte count
$ echo "$TEST_STRING" | wc -c
    1028

# word count
$ echo "$TEST_STRING" | wc -m
     344
pf-siedler commented 1 month ago

I had same issue.

I tried it on managed console. I created listener rule contain multibyte strings (600 characters / 1800 bytes). It passed.

スクリーンショット 2024-09-18 13 37 09

but, terraform validation failed.

$ terraform plan
╷
│ Error: expected length of action.0.fixed_response.0.message_body to be in the range (0 - 1024), got ああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああ
│ 
│   with aws_lb_listener_rule.multibyte_string,
│   on main.tf line 47, in resource "aws_lb_listener_rule" "multibyte_string":
│   47:       message_body = "ああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああ"
│ 
╵

That validation is defined here. https://github.com/hashicorp/terraform-provider-aws/blob/c4fa4f55cf12c0472586ec756d047b3971444133/internal/service/elbv2/listener_rule.go#L205

StringLenBetween is defined here. https://github.com/hashicorp/terraform-plugin-sdk/blob/843f27434cd7d30104dbee895e5767a61239ccea/helper/validation/strings.go#L82

len() counts byte size (not character).