Skip to content
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

Allow underscore in database_name [redshift] #10019

Merged
merged 4 commits into from
Nov 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions builtin/providers/aws/resource_aws_redshift_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -844,9 +844,13 @@ func validateRedshiftClusterIdentifier(v interface{}, k string) (ws []string, er

func validateRedshiftClusterDbName(v interface{}, k string) (ws []string, errors []error) {
value := v.(string)
if !regexp.MustCompile(`^[0-9a-z]+$`).MatchString(value) {
if !regexp.MustCompile(`^[0-9A-Za-z_$]+$`).MatchString(value) {
errors = append(errors, fmt.Errorf(
"only lowercase letters and numeric characters allowed in %q", k))
"only alphanumeric characters, underscores, and dollar signs are allowed in %q", k))
}
if !regexp.MustCompile(`^[a-zA-Z_]`).MatchString(value) {
errors = append(errors, fmt.Errorf(
"first character of %q must be a letter or underscore", k))
}
if len(value) > 64 {
errors = append(errors, fmt.Errorf(
Expand Down
72 changes: 36 additions & 36 deletions builtin/providers/aws/resource_aws_redshift_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,42 @@ import (
"github.com/hashicorp/terraform/terraform"
)

func TestValidateRedshiftClusterDbName(t *testing.T) {
validNames := []string{
"testdbname",
"test_dbname",
"testdbname123",
"TestDBname",
"testdbname$hashicorp",
"_dbname",
}
for _, v := range validNames {
_, errors := validateRedshiftClusterDbName(v, "name")
if len(errors) != 0 {
t.Fatalf("%q should be a valid Redshift DBName: %q", v, errors)
}
}

invalidNames := []string{
"!",
"/",
" ",
":",
";",
"test name",
"/slash-at-the-beginning",
"slash-at-the-end/",
"",
randomString(100),
}
for _, v := range invalidNames {
_, errors := validateRedshiftClusterDbName(v, "name")
if len(errors) == 0 {
t.Fatalf("%q should be an invalid Redshift DBName", v)
}
}
}

func TestAccAWSRedshiftCluster_basic(t *testing.T) {
var v redshift.Cluster

Expand Down Expand Up @@ -340,42 +376,6 @@ func TestResourceAWSRedshiftClusterIdentifierValidation(t *testing.T) {
}
}

func TestResourceAWSRedshiftClusterDbNameValidation(t *testing.T) {
cases := []struct {
Value string
ErrCount int
}{
{
Value: "tEsting",
ErrCount: 1,
},
{
Value: "testing1",
ErrCount: 0,
},
{
Value: "testing-",
ErrCount: 1,
},
{
Value: "",
ErrCount: 2,
},
{
Value: randomString(65),
ErrCount: 1,
},
}

for _, tc := range cases {
_, errors := validateRedshiftClusterDbName(tc.Value, "aws_redshift_cluster_database_name")

if len(errors) != tc.ErrCount {
t.Fatalf("Expected the Redshift Cluster database_name to trigger a validation error")
}
}
}

func TestResourceAWSRedshiftClusterFinalSnapshotIdentifierValidation(t *testing.T) {
cases := []struct {
Value string
Expand Down