diff --git a/builtin/providers/aws/resource_aws_db_parameter_group.go b/builtin/providers/aws/resource_aws_db_parameter_group.go index 984e36ba9..93f0efa4f 100644 --- a/builtin/providers/aws/resource_aws_db_parameter_group.go +++ b/builtin/providers/aws/resource_aws_db_parameter_group.go @@ -37,7 +37,7 @@ func resourceAwsDbParameterGroup() *schema.Resource { "parameter": &schema.Schema{ Type: schema.TypeSet, Optional: true, - ForceNew: true, + ForceNew: false, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "apply_method": &schema.Schema{ @@ -85,6 +85,12 @@ func resourceAwsDbParameterGroupCreate(d *schema.ResourceData, meta interface{}) return fmt.Errorf("Error creating DB Parameter Group: %s", err) } + d.Partial(true) + d.SetPartial("name") + d.SetPartial("family") + d.SetPartial("description") + d.Partial(false) + d.SetId(createOpts.DBParameterGroupName) log.Printf("[INFO] DB Parameter Group ID: %s", d.Id()) @@ -95,6 +101,8 @@ func resourceAwsDbParameterGroupUpdate(d *schema.ResourceData, meta interface{}) p := meta.(*ResourceProvider) rdsconn := p.rdsconn + d.Partial(true) + if d.HasChange("parameter") { o, n := d.GetChange("parameter") if o == nil { @@ -125,9 +133,12 @@ func resourceAwsDbParameterGroupUpdate(d *schema.ResourceData, meta interface{}) return fmt.Errorf("Error modifying DB Parameter Group: %s", err) } } + d.SetPartial("parameter") } - return nil + d.Partial(false) + + return resourceAwsDbParameterGroupRead(d, meta) } func resourceAwsDbParameterGroupDelete(d *schema.ResourceData, meta interface{}) error { @@ -175,6 +186,9 @@ func resourceAwsDbParameterGroupRead(d *schema.ResourceData, meta interface{}) e return err } + // apply_method is only relevant for creates and AWS does not maintain its state. + + d.Set("parameter", flattenParameters(describeParametersResp.Parameters)) return nil diff --git a/builtin/providers/aws/resource_aws_db_parameter_group_test.go b/builtin/providers/aws/resource_aws_db_parameter_group_test.go index 4a6b25e8e..f406a3986 100644 --- a/builtin/providers/aws/resource_aws_db_parameter_group_test.go +++ b/builtin/providers/aws/resource_aws_db_parameter_group_test.go @@ -19,6 +19,31 @@ func TestAccAWSDBParameterGroup(t *testing.T) { Steps: []resource.TestStep{ resource.TestStep{ Config: testAccAWSDBParameterGroupConfig, + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSDBParameterGroupExists("aws_db_parameter_group.bar", &v), + testAccCheckAWSDBParameterGroupAttributes(&v), + resource.TestCheckResourceAttr( + "aws_db_parameter_group.bar", "name", "parameter-group-test-terraform"), + resource.TestCheckResourceAttr( + "aws_db_parameter_group.bar", "family", "mysql5.6"), + resource.TestCheckResourceAttr( + "aws_db_parameter_group.bar", "description", "Test parameter group for terraform"), + resource.TestCheckResourceAttr( + "aws_db_parameter_group.bar", "parameter.0.name", "character_set_results"), + resource.TestCheckResourceAttr( + "aws_db_parameter_group.bar", "parameter.0.value", "utf8"), + resource.TestCheckResourceAttr( + "aws_db_parameter_group.bar", "parameter.1.name", "character_set_server"), + resource.TestCheckResourceAttr( + "aws_db_parameter_group.bar", "parameter.1.value", "utf8"), + resource.TestCheckResourceAttr( + "aws_db_parameter_group.bar", "parameter.2.name", "character_set_client"), + resource.TestCheckResourceAttr( + "aws_db_parameter_group.bar", "parameter.2.value", "utf8"), + ), + }, + resource.TestStep{ + Config: testAccAWSDBParameterGroupAddParametersConfig, Check: resource.ComposeTestCheckFunc( testAccCheckAWSDBParameterGroupExists("aws_db_parameter_group.bar", &v), testAccCheckAWSDBParameterGroupAttributes(&v), @@ -32,32 +57,22 @@ func TestAccAWSDBParameterGroup(t *testing.T) { "aws_db_parameter_group.bar", "parameter.0.name", "collation_connection"), resource.TestCheckResourceAttr( "aws_db_parameter_group.bar", "parameter.0.value", "utf8_unicode_ci"), - resource.TestCheckResourceAttr( - "aws_db_parameter_group.bar", "parameter.0.apply_method", "immediate"), resource.TestCheckResourceAttr( "aws_db_parameter_group.bar", "parameter.1.name", "character_set_results"), resource.TestCheckResourceAttr( "aws_db_parameter_group.bar", "parameter.1.value", "utf8"), - resource.TestCheckResourceAttr( - "aws_db_parameter_group.bar", "parameter.1.apply_method", "immediate"), resource.TestCheckResourceAttr( "aws_db_parameter_group.bar", "parameter.2.name", "character_set_server"), resource.TestCheckResourceAttr( "aws_db_parameter_group.bar", "parameter.2.value", "utf8"), - resource.TestCheckResourceAttr( - "aws_db_parameter_group.bar", "parameter.2.apply_method", "immediate"), resource.TestCheckResourceAttr( "aws_db_parameter_group.bar", "parameter.3.name", "collation_server"), resource.TestCheckResourceAttr( "aws_db_parameter_group.bar", "parameter.3.value", "utf8_unicode_ci"), - resource.TestCheckResourceAttr( - "aws_db_parameter_group.bar", "parameter.3.apply_method", "immediate"), resource.TestCheckResourceAttr( "aws_db_parameter_group.bar", "parameter.4.name", "character_set_client"), resource.TestCheckResourceAttr( "aws_db_parameter_group.bar", "parameter.4.value", "utf8"), - resource.TestCheckResourceAttr( - "aws_db_parameter_group.bar", "parameter.4.apply_method", "immediate"), ), }, }, @@ -65,14 +80,14 @@ func TestAccAWSDBParameterGroup(t *testing.T) { } func TestAccAWSDBParameterGroupOnly(t *testing.T) { - var v rds.DBParameterGroup + var v rds.DBParameterGroup - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAWSDBParameterGroupDestroy, - Steps: []resource.TestStep{ - resource.TestStep{ + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSDBParameterGroupDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ Config: testAccAWSDBParameterGroupOnlyConfig, Check: resource.ComposeTestCheckFunc( testAccCheckAWSDBParameterGroupExists("aws_db_parameter_group.bar", &v), @@ -177,6 +192,29 @@ func testAccCheckAWSDBParameterGroupExists(n string, v *rds.DBParameterGroup) re } const testAccAWSDBParameterGroupConfig = ` +resource "aws_db_parameter_group" "bar" { + name = "parameter-group-test-terraform" + family = "mysql5.6" + description = "Test parameter group for terraform" + parameter { + name = "character_set_server" + value = "utf8" + apply_method = "immediate" + } + parameter { + name = "character_set_client" + value = "utf8" + apply_method = "immediate" + } + parameter{ + name = "character_set_results" + value = "utf8" + apply_method = "immediate" + } +} +` + +const testAccAWSDBParameterGroupAddParametersConfig = ` resource "aws_db_parameter_group" "bar" { name = "parameter-group-test-terraform" family = "mysql5.6" diff --git a/builtin/providers/aws/structure.go b/builtin/providers/aws/structure.go index 288e9d46c..3e00a0308 100644 --- a/builtin/providers/aws/structure.go +++ b/builtin/providers/aws/structure.go @@ -190,8 +190,11 @@ func flattenParameters(list []rds.Parameter) []map[string]interface{} { result := make([]map[string]interface{}, 0, len(list)) for _, i := range list { result = append(result, map[string]interface{}{ - "name": strings.ToLower(i.ParameterName), - "value": strings.ToLower(i.ParameterValue), + "name": strings.ToLower(i.ParameterName), + "value": strings.ToLower(i.ParameterValue), + // apply_method is only used on create/modify and is not returned when reading from AWS. + // This is a dummy value to print out as it's not used when doing the state diff for updating + "apply_method": "applied", }) } return result diff --git a/builtin/providers/aws/structure_test.go b/builtin/providers/aws/structure_test.go index 46d013ef3..de72c59a3 100644 --- a/builtin/providers/aws/structure_test.go +++ b/builtin/providers/aws/structure_test.go @@ -297,8 +297,9 @@ func Test_flattenParameters(t *testing.T) { }, Output: []map[string]interface{}{ map[string]interface{}{ - "name": "character_set_client", - "value": "utf8", + "name": "character_set_client", + "value": "utf8", + "apply_method": "applied", }, }, },