Merge pull request #4340 from stack72/f-aws-db_subnet_group_name-downcase
provider/aws: StateFunc on db_subnet_group name to be lowercase
This commit is contained in:
commit
19e68da388
|
@ -32,22 +32,7 @@ func resourceAwsDbSubnetGroup() *schema.Resource {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
Required: true,
|
Required: true,
|
||||||
ValidateFunc: func(v interface{}, k string) (ws []string, errors []error) {
|
ValidateFunc: validateSubnetGroupName,
|
||||||
value := v.(string)
|
|
||||||
if !regexp.MustCompile(`^[ .0-9A-Za-z-_]+$`).MatchString(value) {
|
|
||||||
errors = append(errors, fmt.Errorf(
|
|
||||||
"only alphanumeric characters, hyphens, underscores, periods, and spaces allowed in %q", k))
|
|
||||||
}
|
|
||||||
if len(value) > 255 {
|
|
||||||
errors = append(errors, fmt.Errorf(
|
|
||||||
"%q cannot be longer than 255 characters", k))
|
|
||||||
}
|
|
||||||
if regexp.MustCompile(`(?i)^default$`).MatchString(value) {
|
|
||||||
errors = append(errors, fmt.Errorf(
|
|
||||||
"%q is not allowed as %q", "Default", k))
|
|
||||||
}
|
|
||||||
return
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
|
|
||||||
"description": &schema.Schema{
|
"description": &schema.Schema{
|
||||||
|
@ -131,8 +116,8 @@ func resourceAwsDbSubnetGroupRead(d *schema.ResourceData, meta interface{}) erro
|
||||||
return fmt.Errorf("Unable to find DB Subnet Group: %#v", describeResp.DBSubnetGroups)
|
return fmt.Errorf("Unable to find DB Subnet Group: %#v", describeResp.DBSubnetGroups)
|
||||||
}
|
}
|
||||||
|
|
||||||
d.Set("name", d.Id())
|
d.Set("name", subnetGroup.DBSubnetGroupName)
|
||||||
d.Set("description", *subnetGroup.DBSubnetGroupDescription)
|
d.Set("description", subnetGroup.DBSubnetGroupDescription)
|
||||||
|
|
||||||
subnets := make([]string, 0, len(subnetGroup.Subnets))
|
subnets := make([]string, 0, len(subnetGroup.Subnets))
|
||||||
for _, s := range subnetGroup.Subnets {
|
for _, s := range subnetGroup.Subnets {
|
||||||
|
@ -252,3 +237,20 @@ func buildRDSsubgrpARN(d *schema.ResourceData, meta interface{}) (string, error)
|
||||||
arn := fmt.Sprintf("arn:aws:rds:%s:%s:subgrp:%s", region, accountID, d.Id())
|
arn := fmt.Sprintf("arn:aws:rds:%s:%s:subgrp:%s", region, accountID, d.Id())
|
||||||
return arn, nil
|
return arn, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func validateSubnetGroupName(v interface{}, k string) (ws []string, errors []error) {
|
||||||
|
value := v.(string)
|
||||||
|
if !regexp.MustCompile(`^[ .0-9a-z-_]+$`).MatchString(value) {
|
||||||
|
errors = append(errors, fmt.Errorf(
|
||||||
|
"only alphanumeric characters, hyphens, underscores, periods, and spaces allowed in %q", k))
|
||||||
|
}
|
||||||
|
if len(value) > 255 {
|
||||||
|
errors = append(errors, fmt.Errorf(
|
||||||
|
"%q cannot be longer than 255 characters", k))
|
||||||
|
}
|
||||||
|
if regexp.MustCompile(`(?i)^default$`).MatchString(value) {
|
||||||
|
errors = append(errors, fmt.Errorf(
|
||||||
|
"%q is not allowed as %q", "Default", k))
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
|
@ -66,6 +66,38 @@ func TestAccAWSDBSubnetGroup_withUndocumentedCharacters(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestResourceAWSDBSubnetGroupNameValidation(t *testing.T) {
|
||||||
|
cases := []struct {
|
||||||
|
Value string
|
||||||
|
ErrCount int
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
Value: "tEsting",
|
||||||
|
ErrCount: 1,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Value: "testing?",
|
||||||
|
ErrCount: 1,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Value: "default",
|
||||||
|
ErrCount: 1,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Value: randomString(300),
|
||||||
|
ErrCount: 1,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tc := range cases {
|
||||||
|
_, errors := validateSubnetGroupName(tc.Value, "aws_db_subnet_group")
|
||||||
|
|
||||||
|
if len(errors) != tc.ErrCount {
|
||||||
|
t.Fatalf("Expected the DB Subnet Group name to trigger a validation error")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func testAccCheckDBSubnetGroupDestroy(s *terraform.State) error {
|
func testAccCheckDBSubnetGroupDestroy(s *terraform.State) error {
|
||||||
conn := testAccProvider.Meta().(*AWSClient).rdsconn
|
conn := testAccProvider.Meta().(*AWSClient).rdsconn
|
||||||
|
|
||||||
|
@ -149,7 +181,7 @@ resource "aws_subnet" "bar" {
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "aws_db_subnet_group" "foo" {
|
resource "aws_db_subnet_group" "foo" {
|
||||||
name = "FOO"
|
name = "foo"
|
||||||
description = "foo description"
|
description = "foo description"
|
||||||
subnet_ids = ["${aws_subnet.foo.id}", "${aws_subnet.bar.id}"]
|
subnet_ids = ["${aws_subnet.foo.id}", "${aws_subnet.bar.id}"]
|
||||||
tags {
|
tags {
|
||||||
|
|
Loading…
Reference in New Issue