diff --git a/.changelog/31352.txt b/.changelog/31352.txt new file mode 100644 index 00000000000..fea17218a3c --- /dev/null +++ b/.changelog/31352.txt @@ -0,0 +1,7 @@ +```release-note:bug +resource/aws_keyspaces_keyspace: Correct plan time validation for `name` +``` + +```release-note:bug +resource/aws_keyspaces_table: Correct plan time validation for `keyspace_name`, `table_name` and column names +``` \ No newline at end of file diff --git a/internal/service/keyspaces/keyspace.go b/internal/service/keyspaces/keyspace.go index 29451230630..43d5be382d1 100644 --- a/internal/service/keyspaces/keyspace.go +++ b/internal/service/keyspaces/keyspace.go @@ -48,12 +48,9 @@ func ResourceKeyspace() *schema.Resource { Type: schema.TypeString, ForceNew: true, Required: true, - ValidateFunc: validation.All( - validation.StringLenBetween(1, 48), - validation.StringMatch( - regexp.MustCompile(`^[a-zA-Z0-9][a-zA-Z0-9_]{1,47}$`), - "The name must consist of alphanumerics and underscores.", - ), + ValidateFunc: validation.StringMatch( + regexp.MustCompile(`^[a-zA-Z0-9][a-zA-Z0-9_]{0,47}$`), + "The name can have up to 48 characters. It must begin with an alpha-numeric character and can only contain alpha-numeric characters and underscores.", ), }, names.AttrTags: tftags.TagsSchema(), diff --git a/internal/service/keyspaces/table.go b/internal/service/keyspaces/table.go index ccdd5c30bd2..9585cc916be 100644 --- a/internal/service/keyspaces/table.go +++ b/internal/service/keyspaces/table.go @@ -136,12 +136,9 @@ func ResourceTable() *schema.Resource { Type: schema.TypeString, ForceNew: true, Required: true, - ValidateFunc: validation.All( - validation.StringLenBetween(1, 48), - validation.StringMatch( - regexp.MustCompile(`^[a-zA-Z0-9][a-zA-Z0-9_]{1,47}$`), - "The name must consist of alphanumerics and underscores.", - ), + ValidateFunc: validation.StringMatch( + regexp.MustCompile(`^[a-zA-Z0-9][a-zA-Z0-9_]{0,47}$`), + "The keyspace name can have up to 48 characters. It must begin with an alpha-numeric character and can only contain alpha-numeric characters and underscores.", ), }, "point_in_time_recovery": { @@ -176,12 +173,9 @@ func ResourceTable() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: validation.All( - validation.StringLenBetween(1, 48), - validation.StringMatch( - regexp.MustCompile(`^[a-z0-9][a-z0-9_]{1,47}$`), - "The name must consist of lower case alphanumerics and underscores.", - ), + ValidateFunc: validation.StringMatch( + regexp.MustCompile(`^[a-z0-9_]{1,48}$`), + "The column name can have up to 48 characters. It can only contain lowercase alpha-numeric characters and underscores.", ), }, "order_by": { @@ -201,12 +195,9 @@ func ResourceTable() *schema.Resource { "name": { Type: schema.TypeString, Required: true, - ValidateFunc: validation.All( - validation.StringLenBetween(1, 48), - validation.StringMatch( - regexp.MustCompile(`^[a-z0-9][a-z0-9_]{1,47}$`), - "The name must consist of lower case alphanumerics and underscores.", - ), + ValidateFunc: validation.StringMatch( + regexp.MustCompile(`^[a-z0-9_]{1,48}$`), + "The column name can have up to 48 characters. It can only contain lowercase alpha-numeric characters and underscores.", ), }, "type": { @@ -230,12 +221,9 @@ func ResourceTable() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: validation.All( - validation.StringLenBetween(1, 48), - validation.StringMatch( - regexp.MustCompile(`^[a-z0-9][a-z0-9_]{1,47}$`), - "The name must consist of lower case alphanumerics and underscores.", - ), + ValidateFunc: validation.StringMatch( + regexp.MustCompile(`^[a-z0-9_]{1,48}$`), + "The column name can have up to 48 characters. It can only contain lowercase alpha-numeric characters and underscores.", ), }, }, @@ -251,12 +239,9 @@ func ResourceTable() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: validation.All( - validation.StringLenBetween(1, 48), - validation.StringMatch( - regexp.MustCompile(`^[a-z0-9][a-z0-9_]{1,47}$`), - "The name must consist of lower case alphanumerics and underscores.", - ), + ValidateFunc: validation.StringMatch( + regexp.MustCompile(`^[a-z0-9_]{1,48}$`), + "The column name can have up to 48 characters. It can only contain lowercase alpha-numeric characters and underscores.", ), }, }, @@ -269,12 +254,9 @@ func ResourceTable() *schema.Resource { Type: schema.TypeString, ForceNew: true, Required: true, - ValidateFunc: validation.All( - validation.StringLenBetween(1, 48), - validation.StringMatch( - regexp.MustCompile(`^[a-zA-Z0-9][a-zA-Z0-9_]{1,47}$`), - "The name must consist of alphanumerics and underscores.", - ), + ValidateFunc: validation.StringMatch( + regexp.MustCompile(`^[a-zA-Z0-9_]{1,48}$`), + "The table name can have up to 48 characters. It can only contain alpha-numeric characters and underscores.", ), }, names.AttrTags: tftags.TagsSchema(), diff --git a/internal/service/keyspaces/table_test.go b/internal/service/keyspaces/table_test.go index 06acbc2ba94..98605bcb3af 100644 --- a/internal/service/keyspaces/table_test.go +++ b/internal/service/keyspaces/table_test.go @@ -176,7 +176,7 @@ func TestAccKeyspacesTable_multipleColumns(t *testing.T) { "type": "text", }), resource.TestCheckTypeSetElemNestedAttrs(resourceName, "schema_definition.0.column.*", map[string]string{ - "name": "name", + "name": "n", "type": "text", }), resource.TestCheckTypeSetElemNestedAttrs(resourceName, "schema_definition.0.column.*", map[string]string{ @@ -196,7 +196,7 @@ func TestAccKeyspacesTable_multipleColumns(t *testing.T) { "type": "text", }), resource.TestCheckTypeSetElemNestedAttrs(resourceName, "schema_definition.0.column.*", map[string]string{ - "name": "pay_scale", + "name": "pay_scale0", "type": "int", }), resource.TestCheckTypeSetElemNestedAttrs(resourceName, "schema_definition.0.column.*", map[string]string{ @@ -224,7 +224,7 @@ func TestAccKeyspacesTable_multipleColumns(t *testing.T) { "name": "role", }), resource.TestCheckTypeSetElemNestedAttrs(resourceName, "schema_definition.0.static_column.*", map[string]string{ - "name": "pay_scale", + "name": "pay_scale0", }), ), }, @@ -626,7 +626,7 @@ resource "aws_keyspaces_table" "test" { } column { - name = "name" + name = "n" type = "text" } @@ -651,7 +651,7 @@ resource "aws_keyspaces_table" "test" { } column { - name = "pay_scale" + name = "pay_scale0" type = "int" } @@ -694,7 +694,7 @@ resource "aws_keyspaces_table" "test" { } static_column { - name = "pay_scale" + name = "pay_scale0" } } }