Closed
Description
Terraform CLI and Framework Versions
❯ terraform version
Terraform v1.2.3
on darwin_arm64
...
❯ go list -m github.com/hashicorp/terraform-plugin-framework
github.com/hashicorp/terraform-plugin-framework v0.17.0
Terraform Plugin Framework Code
[]validator.String{
stringvalidator.LengthBetween(1, 5),
},
Terraform Configuration
resource "examplecloud_thing" "test" {
display_name = "あいうえお"
}
Expected Behavior
No errors are returned.
Actual Behavior
│ Error: Invalid Attribute Value Length
│
│ with examplecloud_thing.test,
│ on ../../example/test.tf line 2, in resource "examplecloud_thing" "test":
│ 2: display_name = "あいうえお"
│
│ Attribute display_name string length must be between 1 and 5, got: 15
Steps to Reproduce
terraform apply
Logs
No response
Additional Information
len(string)
does not count by characters but by bytes, so if a multibyte string is specified for validation, it cannot be validated by characters.
In order to accurately determine the number of characters, utf8.RuneCountInString()
should be used.
When developing services for Japan etc, It is convenient to handle the length of multibyte characters.
ref: https://pkg.go.dev/unicode/utf8#RuneCountInString
Code of Conduct
- I agree to follow this project's Code of Conduct