Skip to content

Commit

Permalink
Merge pull request #31352 from bsamsom/patch-1
Browse files Browse the repository at this point in the history
Bug #31348 - update regex for single character columns
  • Loading branch information
ewbankkit authored Jun 9, 2023
2 parents 6029285 + 18486bf commit 6bc458d
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 48 deletions.
7 changes: 7 additions & 0 deletions .changelog/31352.txt
Original file line number Diff line number Diff line change
@@ -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
```
9 changes: 3 additions & 6 deletions internal/service/keyspaces/keyspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
54 changes: 18 additions & 36 deletions internal/service/keyspaces/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -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": {
Expand All @@ -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": {
Expand All @@ -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.",
),
},
},
Expand All @@ -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.",
),
},
},
Expand All @@ -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(),
Expand Down
12 changes: 6 additions & 6 deletions internal/service/keyspaces/table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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{
Expand Down Expand Up @@ -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",
}),
),
},
Expand Down Expand Up @@ -626,7 +626,7 @@ resource "aws_keyspaces_table" "test" {
}
column {
name = "name"
name = "n"
type = "text"
}
Expand All @@ -651,7 +651,7 @@ resource "aws_keyspaces_table" "test" {
}
column {
name = "pay_scale"
name = "pay_scale0"
type = "int"
}
Expand Down Expand Up @@ -694,7 +694,7 @@ resource "aws_keyspaces_table" "test" {
}
static_column {
name = "pay_scale"
name = "pay_scale0"
}
}
}
Expand Down

0 comments on commit 6bc458d

Please sign in to comment.