Skip to content

Commit

Permalink
provider/aws: aws_db_option_group normalizes name to lowercase
Browse files Browse the repository at this point in the history
This is a fix for PR #11040. The code here lowercases the name and/or prefix before sending it to the AWS API and the terraform state. This means the state will match the actual resource name and be able to converge the diff.
  • Loading branch information
thrashr888 committed May 3, 2017
1 parent 2aaabf7 commit 7e1f158
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
9 changes: 9 additions & 0 deletions builtin/providers/aws/resource_aws_db_option_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"fmt"
"log"
"strings"
"time"

"github.com/aws/aws-sdk-go/aws"
Expand Down Expand Up @@ -36,13 +37,21 @@ 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
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
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ 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.
* `name_prefix` - (Optional, Forces new resource) Creates a unique name beginning with the specified prefix. Conflicts with `name`.
* `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.
* `name_prefix` - (Optional, Forces new resource) Creates a unique name beginning with the specified prefix. Conflicts with `name`. This is converted to lowercase.
* `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..
* `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.
* `option` - (Optional) A list of Options to apply.
* `tags` - (Optional) A mapping of tags to assign to the resource.
Expand Down

0 comments on commit 7e1f158

Please sign in to comment.