From ccae9372e5ac68f3378fd3b6d6a0df4111f3c20c Mon Sep 17 00:00:00 2001 From: Paul Thrasher Date: Wed, 3 May 2017 15:57:05 -0700 Subject: [PATCH] provider/aws: aws_db_option_group normalizes name to lowercase 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. --- builtin/providers/aws/resource_aws_db_option_group.go | 9 +++++++++ .../providers/aws/resource_aws_db_option_group_test.go | 10 +++++----- .../docs/providers/aws/r/db_option_group.html.markdown | 6 +++--- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/builtin/providers/aws/resource_aws_db_option_group.go b/builtin/providers/aws/resource_aws_db_option_group.go index e8ad1ac99..f1d962923 100644 --- a/builtin/providers/aws/resource_aws_db_option_group.go +++ b/builtin/providers/aws/resource_aws_db_option_group.go @@ -4,6 +4,7 @@ import ( "bytes" "fmt" "log" + "strings" "time" "github.com/aws/aws-sdk-go/aws" @@ -36,6 +37,10 @@ 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, @@ -43,6 +48,10 @@ func resourceAwsDbOptionGroup() *schema.Resource { 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, diff --git a/builtin/providers/aws/resource_aws_db_option_group_test.go b/builtin/providers/aws/resource_aws_db_option_group_test.go index 8e9b22e1b..a39aeb0bf 100644 --- a/builtin/providers/aws/resource_aws_db_option_group_test.go +++ b/builtin/providers/aws/resource_aws_db_option_group_test.go @@ -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-")), ), }, }, @@ -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) }, @@ -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) }, @@ -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) }, @@ -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" } diff --git a/website/source/docs/providers/aws/r/db_option_group.html.markdown b/website/source/docs/providers/aws/r/db_option_group.html.markdown index ee1f8804c..db2657a31 100644 --- a/website/source/docs/providers/aws/r/db_option_group.html.markdown +++ b/website/source/docs/providers/aws/r/db_option_group.html.markdown @@ -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, 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. * `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.