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

provider/aws: Force lowercasing for DB Option group name or name_prefix #14366

Merged
merged 1 commit into from
May 10, 2017
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
10 changes: 1 addition & 9 deletions builtin/providers/aws/resource_aws_db_option_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,13 @@ func resourceAwsDbOptionGroup() *schema.Resource {
ForceNew: true,
ConflictsWith: []string{"name_prefix"},
ValidateFunc: validateDbOptionGroupName,
StateFunc: func(v interface{}) string {
value := v.(string)
return strings.ToLower(value)
},
},
"name_prefix": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
ValidateFunc: validateDbOptionGroupNamePrefix,
StateFunc: func(v interface{}) string {
value := v.(string)
return strings.ToLower(value)
},
},
"engine_name": &schema.Schema{
Type: schema.TypeString,
Expand Down Expand Up @@ -148,7 +140,7 @@ func resourceAwsDbOptionGroupCreate(d *schema.ResourceData, meta interface{}) er
return fmt.Errorf("Error creating DB Option Group: %s", err)
}

d.SetId(groupName)
d.SetId(strings.ToLower(groupName))
log.Printf("[INFO] DB Option Group ID: %s", d.Id())

return resourceAwsDbOptionGroupUpdate(d, meta)
Expand Down
10 changes: 5 additions & 5 deletions builtin/providers/aws/resource_aws_db_option_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func TestAccAWSDBOptionGroup_namePrefix(t *testing.T) {
testAccCheckAWSDBOptionGroupExists("aws_db_option_group.test", &v),
testAccCheckAWSDBOptionGroupAttributes(&v),
resource.TestMatchResourceAttr(
"aws_db_option_group.test", "name", regexp.MustCompile("^tf-TEST-")),
"aws_db_option_group.test", "name", regexp.MustCompile("^tf-test-")),
),
},
},
Expand Down Expand Up @@ -112,7 +112,7 @@ func TestAccAWSDBOptionGroup_basicDestroyWithInstance(t *testing.T) {

func TestAccAWSDBOptionGroup_OptionSettings(t *testing.T) {
var v rds.OptionGroup
rName := fmt.Sprintf("option-group-TEST-terraform-%s", acctest.RandString(5))
rName := fmt.Sprintf("option-group-test-terraform-%s", acctest.RandString(5))

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand Down Expand Up @@ -149,7 +149,7 @@ func TestAccAWSDBOptionGroup_OptionSettings(t *testing.T) {

func TestAccAWSDBOptionGroup_sqlServerOptionsUpdate(t *testing.T) {
var v rds.OptionGroup
rName := fmt.Sprintf("option-group-TEST-terraform-%s", acctest.RandString(5))
rName := fmt.Sprintf("option-group-test-terraform-%s", acctest.RandString(5))

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand Down Expand Up @@ -181,7 +181,7 @@ func TestAccAWSDBOptionGroup_sqlServerOptionsUpdate(t *testing.T) {

func TestAccAWSDBOptionGroup_multipleOptions(t *testing.T) {
var v rds.OptionGroup
rName := fmt.Sprintf("option-group-TEST-terraform-%s", acctest.RandString(5))
rName := fmt.Sprintf("option-group-test-terraform-%s", acctest.RandString(5))

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand Down Expand Up @@ -434,7 +434,7 @@ resource "aws_db_option_group" "test" {
func testAccAWSDBOptionGroup_defaultDescription(n int) string {
return fmt.Sprintf(`
resource "aws_db_option_group" "test" {
name = "tf-TEST-%d"
name = "tf-test-%d"
engine_name = "mysql"
major_engine_version = "5.6"
}
Expand Down
6 changes: 3 additions & 3 deletions builtin/providers/aws/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -1141,9 +1141,9 @@ func validateDbOptionGroupName(v interface{}, k string) (ws []string, errors []e
errors = append(errors, fmt.Errorf(
"first character of %q must be a letter", k))
}
if !regexp.MustCompile(`^[0-9A-Za-z-]+$`).MatchString(value) {
if !regexp.MustCompile(`^[0-9a-z-]+$`).MatchString(value) {
errors = append(errors, fmt.Errorf(
"only alphanumeric characters and hyphens allowed in %q", k))
"only lowercase alphanumeric characters and hyphens allowed in %q", k))
}
if regexp.MustCompile(`--`).MatchString(value) {
errors = append(errors, fmt.Errorf(
Expand All @@ -1166,7 +1166,7 @@ func validateDbOptionGroupNamePrefix(v interface{}, k string) (ws []string, erro
errors = append(errors, fmt.Errorf(
"first character of %q must be a letter", k))
}
if !regexp.MustCompile(`^[0-9A-Za-z-]+$`).MatchString(value) {
if !regexp.MustCompile(`^[0-9a-z-]+$`).MatchString(value) {
errors = append(errors, fmt.Errorf(
"only alphanumeric characters and hyphens allowed in %q", k))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ resource "aws_db_option_group" "bar" {

The following arguments are supported:

* `name` - (Optional, Forces new resource) The name of the option group. If omitted, Terraform will assign a random, unique name. This is converted to lowercase, as is stored in AWS.
* `name_prefix` - (Optional, Forces new resource) Creates a unique name beginning with the specified prefix. Conflicts with `name`. This is converted to lowercase, as is stored in AWS.
* `name` - (Optional, Forces new resource) The name of the option group. If omitted, Terraform will assign a random, unique name. Must be lowercase, to match as it is stored in AWS.
* `name_prefix` - (Optional, Forces new resource) Creates a unique name beginning with the specified prefix. Conflicts with `name`. Must be lowercase, to match as it is stored in AWS.
* `option_group_description` - (Optional) The description of the option group. Defaults to "Managed by Terraform".
* `engine_name` - (Required) Specifies the name of the engine that this option group should be associated with.
* `major_engine_version` - (Required) Specifies the major version of the engine that this option group should be associated with.
Expand Down