-
Notifications
You must be signed in to change notification settings - Fork 9.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Only accept lowercase names for aws_glue_catalog_database and aws_glue_catalog_table #8288
Changes from all commits
ab2576d
874c3d0
d7e87b4
10dfffe
a42300f
6047537
9c73bad
6cacfbb
96ab7a9
2a54335
0e6a4f5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -2,6 +2,7 @@ package aws | |||||
|
||||||
import ( | ||||||
"fmt" | ||||||
"regexp" | ||||||
"testing" | ||||||
|
||||||
"github.com/aws/aws-sdk-go/aws" | ||||||
|
@@ -12,6 +13,54 @@ import ( | |||||
"github.com/hashicorp/terraform/terraform" | ||||||
) | ||||||
|
||||||
func TestAccAWSGlueCatalogDatabase_importBasic(t *testing.T) { | ||||||
resourceName := "aws_glue_catalog_database.test" | ||||||
rInt := acctest.RandInt() | ||||||
|
||||||
resource.ParallelTest(t, resource.TestCase{ | ||||||
PreCheck: func() { testAccPreCheck(t) }, | ||||||
Providers: testAccProviders, | ||||||
CheckDestroy: testAccCheckGlueDatabaseDestroy, | ||||||
Steps: []resource.TestStep{ | ||||||
{ | ||||||
Config: testAccGlueCatalogDatabase_full(rInt, "A test catalog from terraform"), | ||||||
}, | ||||||
{ | ||||||
ResourceName: resourceName, | ||||||
ImportState: true, | ||||||
ImportStateVerify: true, | ||||||
}, | ||||||
}, | ||||||
}) | ||||||
} | ||||||
|
||||||
func TestAccAWSGlueCatalogDatabase_validation(t *testing.T) { | ||||||
resource.ParallelTest(t, resource.TestCase{ | ||||||
PreCheck: func() { testAccPreCheck(t) }, | ||||||
Providers: testAccProviders, | ||||||
CheckDestroy: testAccCheckGlueDatabaseDestroy, | ||||||
Steps: []resource.TestStep{ | ||||||
{ | ||||||
Config: testAccGlueCatalogDatabase_validation(acctest.RandString(256)), | ||||||
ExpectError: regexp.MustCompile(`"name" cannot be more than 255 characters long`), | ||||||
}, | ||||||
{ | ||||||
Config: testAccGlueCatalogDatabase_validation(""), | ||||||
ExpectError: regexp.MustCompile(`"name" must be at least 1 character long`), | ||||||
}, | ||||||
{ | ||||||
Config: testAccGlueCatalogDatabase_validation("ABCDEFG"), | ||||||
ExpectError: regexp.MustCompile(`"name" can only contain lowercase alphanumeric characters`), | ||||||
}, | ||||||
jukie marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
{ | ||||||
Config: testAccGlueCatalogDatabase_validation("valid_dbname"), | ||||||
ExpectNonEmptyPlan: true, | ||||||
PlanOnly: true, | ||||||
}, | ||||||
}, | ||||||
}) | ||||||
} | ||||||
|
||||||
func TestAccAWSGlueCatalogDatabase_full(t *testing.T) { | ||||||
rInt := acctest.RandInt() | ||||||
resourceName := "aws_glue_catalog_database.test" | ||||||
|
@@ -208,6 +257,21 @@ resource "aws_glue_catalog_database" "test" { | |||||
`, rInt, desc) | ||||||
} | ||||||
|
||||||
func testAccGlueCatalogDatabase_validation(rName string) string { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For clarity, it might be better if this was named against the attribute its testing:
Suggested change
|
||||||
return fmt.Sprintf(` | ||||||
resource "aws_glue_catalog_database" "test" { | ||||||
name = "%s" | ||||||
description = "validation test" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Given the rest of the arguments are optional and we're only looking to test the |
||||||
location_uri = "my-location" | ||||||
parameters = { | ||||||
param1 = "value1" | ||||||
param2 = true | ||||||
param3 = 50 | ||||||
} | ||||||
} | ||||||
`, rName) | ||||||
} | ||||||
|
||||||
func testAccCheckGlueCatalogDatabaseExists(name string) resource.TestCheckFunc { | ||||||
return func(s *terraform.State) error { | ||||||
rs, ok := s.RootModule().Resources[name] | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2371,3 +2371,31 @@ func validateRoute53ResolverName(v interface{}, k string) (ws []string, errors [ | |
|
||
return | ||
} | ||
|
||
func validateGlueCatalogDatabaseName(v interface{}, k string) (ws []string, errors []error) { | ||
value := v.(string) | ||
if regexp.MustCompile(`[A-Z]`).MatchString(value) { | ||
errors = append(errors, fmt.Errorf("%q can only contain lowercase alphanumeric characters", k)) | ||
} | ||
if len(value) < 1 { | ||
errors = append(errors, fmt.Errorf("%q must be at least 1 character long", k)) | ||
} | ||
if len(value) > 255 { | ||
errors = append(errors, fmt.Errorf("%q cannot be more than 255 characters long", k)) | ||
} | ||
return | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe also validate the whole string against a validity regex to stop special characters getting through. e.g.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. or even better use AWS's
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think that regex is valid, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Additionally, special characters are in fact allowed in both the table and database names. Technically, Uppercase is allowed in the api call as well but it's just converted to lowercase after. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, I think your right 👍 |
||
} | ||
|
||
func validateGlueCatalogTableName(v interface{}, k string) (ws []string, errors []error) { | ||
value := v.(string) | ||
if regexp.MustCompile(`[A-Z]`).MatchString(value) { | ||
errors = append(errors, fmt.Errorf("%q can only contain lowercase alphanumeric characters", k)) | ||
} | ||
if len(value) < 1 { | ||
errors = append(errors, fmt.Errorf("%q must be at least 1 character long", k)) | ||
} | ||
if len(value) > 255 { | ||
errors = append(errors, fmt.Errorf("%q cannot be more than 255 characters long", k)) | ||
} | ||
return | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're in the process of removing import-only testing (#8944). Please add the
ImportState
testing to existing tests if its not present, althoughTestAccAWSGlueCatalogDatabase_full
on master looks like it includes it already.