hashicorp / terraform-plugin-sdk

Terraform Plugin SDK enables building plugins (providers) to manage any service providers or custom in-house solutions
https://developer.hashicorp.com/terraform/plugin
Mozilla Public License 2.0
439 stars 232 forks source link

feat: add validation function for string length in bytes with min and max constraints #1350

Open akhn1004 opened 5 months ago

akhn1004 commented 5 months ago

Summary

Adds a new validation function for validating string lengths in bytes with specified minimum and maximum constraints. The new function, StringLenBytesBetween, ensures that the length of a given string falls within the specified byte range.

Background

In many cases, especially when dealing with APIs or data storage, it is crucial to validate that string inputs meet specific length requirements to prevent errors and ensure data integrity. The existing validation functions did not provide a way to validate string lengths based on byte count, which is important for handling multi-byte characters correctly.

Related Issue

This issue has been raised in the context of ALB listener rules in Terraform AWS provider, as outlined in hashicorp/terraform-provider-aws#37802. The problem manifests when attempting to set fixed responses with multi-byte characters. For example, Japanese characters, which are typically 2-3 bytes each, quickly exceed the byte limits imposed by ALB, leading to validation errors even though the number of characters might be within acceptable limits.

hashicorp-cla-app[bot] commented 5 months ago

CLA assistant check

Thank you for your submission! We require that all contributors sign our Contributor License Agreement ("CLA") before we can accept the contribution. Read and sign the agreement

Learn more about why HashiCorp requires a CLA and what the CLA includes

Have you signed the CLA already but the status is still pending? Recheck it.

yutachaos commented 1 month ago

@akhn1004 Your PR is looks good.But looks like you hasn't signed the CLA.