Skip to content

Commit 6bc458d

Browse files
authored
Merge pull request #31352 from bsamsom/patch-1
Bug #31348 - update regex for single character columns
2 parents 6029285 + 18486bf commit 6bc458d

File tree

4 files changed

+34
-48
lines changed

4 files changed

+34
-48
lines changed

.changelog/31352.txt

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
```release-note:bug
2+
resource/aws_keyspaces_keyspace: Correct plan time validation for `name`
3+
```
4+
5+
```release-note:bug
6+
resource/aws_keyspaces_table: Correct plan time validation for `keyspace_name`, `table_name` and column names
7+
```

internal/service/keyspaces/keyspace.go

+3-6
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,9 @@ func ResourceKeyspace() *schema.Resource {
4848
Type: schema.TypeString,
4949
ForceNew: true,
5050
Required: true,
51-
ValidateFunc: validation.All(
52-
validation.StringLenBetween(1, 48),
53-
validation.StringMatch(
54-
regexp.MustCompile(`^[a-zA-Z0-9][a-zA-Z0-9_]{1,47}$`),
55-
"The name must consist of alphanumerics and underscores.",
56-
),
51+
ValidateFunc: validation.StringMatch(
52+
regexp.MustCompile(`^[a-zA-Z0-9][a-zA-Z0-9_]{0,47}$`),
53+
"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.",
5754
),
5855
},
5956
names.AttrTags: tftags.TagsSchema(),

internal/service/keyspaces/table.go

+18-36
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,9 @@ func ResourceTable() *schema.Resource {
136136
Type: schema.TypeString,
137137
ForceNew: true,
138138
Required: true,
139-
ValidateFunc: validation.All(
140-
validation.StringLenBetween(1, 48),
141-
validation.StringMatch(
142-
regexp.MustCompile(`^[a-zA-Z0-9][a-zA-Z0-9_]{1,47}$`),
143-
"The name must consist of alphanumerics and underscores.",
144-
),
139+
ValidateFunc: validation.StringMatch(
140+
regexp.MustCompile(`^[a-zA-Z0-9][a-zA-Z0-9_]{0,47}$`),
141+
"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.",
145142
),
146143
},
147144
"point_in_time_recovery": {
@@ -176,12 +173,9 @@ func ResourceTable() *schema.Resource {
176173
Type: schema.TypeString,
177174
Required: true,
178175
ForceNew: true,
179-
ValidateFunc: validation.All(
180-
validation.StringLenBetween(1, 48),
181-
validation.StringMatch(
182-
regexp.MustCompile(`^[a-z0-9][a-z0-9_]{1,47}$`),
183-
"The name must consist of lower case alphanumerics and underscores.",
184-
),
176+
ValidateFunc: validation.StringMatch(
177+
regexp.MustCompile(`^[a-z0-9_]{1,48}$`),
178+
"The column name can have up to 48 characters. It can only contain lowercase alpha-numeric characters and underscores.",
185179
),
186180
},
187181
"order_by": {
@@ -201,12 +195,9 @@ func ResourceTable() *schema.Resource {
201195
"name": {
202196
Type: schema.TypeString,
203197
Required: true,
204-
ValidateFunc: validation.All(
205-
validation.StringLenBetween(1, 48),
206-
validation.StringMatch(
207-
regexp.MustCompile(`^[a-z0-9][a-z0-9_]{1,47}$`),
208-
"The name must consist of lower case alphanumerics and underscores.",
209-
),
198+
ValidateFunc: validation.StringMatch(
199+
regexp.MustCompile(`^[a-z0-9_]{1,48}$`),
200+
"The column name can have up to 48 characters. It can only contain lowercase alpha-numeric characters and underscores.",
210201
),
211202
},
212203
"type": {
@@ -230,12 +221,9 @@ func ResourceTable() *schema.Resource {
230221
Type: schema.TypeString,
231222
Required: true,
232223
ForceNew: true,
233-
ValidateFunc: validation.All(
234-
validation.StringLenBetween(1, 48),
235-
validation.StringMatch(
236-
regexp.MustCompile(`^[a-z0-9][a-z0-9_]{1,47}$`),
237-
"The name must consist of lower case alphanumerics and underscores.",
238-
),
224+
ValidateFunc: validation.StringMatch(
225+
regexp.MustCompile(`^[a-z0-9_]{1,48}$`),
226+
"The column name can have up to 48 characters. It can only contain lowercase alpha-numeric characters and underscores.",
239227
),
240228
},
241229
},
@@ -251,12 +239,9 @@ func ResourceTable() *schema.Resource {
251239
Type: schema.TypeString,
252240
Required: true,
253241
ForceNew: true,
254-
ValidateFunc: validation.All(
255-
validation.StringLenBetween(1, 48),
256-
validation.StringMatch(
257-
regexp.MustCompile(`^[a-z0-9][a-z0-9_]{1,47}$`),
258-
"The name must consist of lower case alphanumerics and underscores.",
259-
),
242+
ValidateFunc: validation.StringMatch(
243+
regexp.MustCompile(`^[a-z0-9_]{1,48}$`),
244+
"The column name can have up to 48 characters. It can only contain lowercase alpha-numeric characters and underscores.",
260245
),
261246
},
262247
},
@@ -269,12 +254,9 @@ func ResourceTable() *schema.Resource {
269254
Type: schema.TypeString,
270255
ForceNew: true,
271256
Required: true,
272-
ValidateFunc: validation.All(
273-
validation.StringLenBetween(1, 48),
274-
validation.StringMatch(
275-
regexp.MustCompile(`^[a-zA-Z0-9][a-zA-Z0-9_]{1,47}$`),
276-
"The name must consist of alphanumerics and underscores.",
277-
),
257+
ValidateFunc: validation.StringMatch(
258+
regexp.MustCompile(`^[a-zA-Z0-9_]{1,48}$`),
259+
"The table name can have up to 48 characters. It can only contain alpha-numeric characters and underscores.",
278260
),
279261
},
280262
names.AttrTags: tftags.TagsSchema(),

internal/service/keyspaces/table_test.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ func TestAccKeyspacesTable_multipleColumns(t *testing.T) {
176176
"type": "text",
177177
}),
178178
resource.TestCheckTypeSetElemNestedAttrs(resourceName, "schema_definition.0.column.*", map[string]string{
179-
"name": "name",
179+
"name": "n",
180180
"type": "text",
181181
}),
182182
resource.TestCheckTypeSetElemNestedAttrs(resourceName, "schema_definition.0.column.*", map[string]string{
@@ -196,7 +196,7 @@ func TestAccKeyspacesTable_multipleColumns(t *testing.T) {
196196
"type": "text",
197197
}),
198198
resource.TestCheckTypeSetElemNestedAttrs(resourceName, "schema_definition.0.column.*", map[string]string{
199-
"name": "pay_scale",
199+
"name": "pay_scale0",
200200
"type": "int",
201201
}),
202202
resource.TestCheckTypeSetElemNestedAttrs(resourceName, "schema_definition.0.column.*", map[string]string{
@@ -224,7 +224,7 @@ func TestAccKeyspacesTable_multipleColumns(t *testing.T) {
224224
"name": "role",
225225
}),
226226
resource.TestCheckTypeSetElemNestedAttrs(resourceName, "schema_definition.0.static_column.*", map[string]string{
227-
"name": "pay_scale",
227+
"name": "pay_scale0",
228228
}),
229229
),
230230
},
@@ -626,7 +626,7 @@ resource "aws_keyspaces_table" "test" {
626626
}
627627
628628
column {
629-
name = "name"
629+
name = "n"
630630
type = "text"
631631
}
632632
@@ -651,7 +651,7 @@ resource "aws_keyspaces_table" "test" {
651651
}
652652
653653
column {
654-
name = "pay_scale"
654+
name = "pay_scale0"
655655
type = "int"
656656
}
657657
@@ -694,7 +694,7 @@ resource "aws_keyspaces_table" "test" {
694694
}
695695
696696
static_column {
697-
name = "pay_scale"
697+
name = "pay_scale0"
698698
}
699699
}
700700
}

0 commit comments

Comments
 (0)