diff --git a/builtin/providers/aws/resource_aws_db_instance.go b/builtin/providers/aws/resource_aws_db_instance.go index 89a3945d9..7732689e1 100644 --- a/builtin/providers/aws/resource_aws_db_instance.go +++ b/builtin/providers/aws/resource_aws_db_instance.go @@ -637,6 +637,7 @@ func resourceAwsDbInstanceRead(d *schema.ResourceData, meta interface{}) error { d.Set("engine", v.Engine) d.Set("engine_version", v.EngineVersion) d.Set("allocated_storage", v.AllocatedStorage) + d.Set("iops", v.Iops) d.Set("copy_tags_to_snapshot", v.CopyTagsToSnapshot) d.Set("auto_minor_version_upgrade", v.AutoMinorVersionUpgrade) d.Set("storage_type", v.StorageType) @@ -798,8 +799,10 @@ func resourceAwsDbInstanceUpdate(d *schema.ResourceData, meta interface{}) error d.SetPartial("apply_immediately") requestUpdate := false - if d.HasChange("allocated_storage") { + if d.HasChange("allocated_storage") || d.HasChange("iops") { d.SetPartial("allocated_storage") + d.SetPartial("iops") + req.Iops = aws.Int64(int64(d.Get("iops").(int))) req.AllocatedStorage = aws.Int64(int64(d.Get("allocated_storage").(int))) requestUpdate = true } @@ -833,11 +836,6 @@ func resourceAwsDbInstanceUpdate(d *schema.ResourceData, meta interface{}) error req.EngineVersion = aws.String(d.Get("engine_version").(string)) requestUpdate = true } - if d.HasChange("iops") { - d.SetPartial("iops") - req.Iops = aws.Int64(int64(d.Get("iops").(int))) - requestUpdate = true - } if d.HasChange("backup_window") { d.SetPartial("backup_window") req.PreferredBackupWindow = aws.String(d.Get("backup_window").(string)) @@ -918,9 +916,9 @@ func resourceAwsDbInstanceUpdate(d *schema.ResourceData, meta interface{}) error requestUpdate = true } - log.Printf("[DEBUG] Send DB Instance Modification request: %#v", requestUpdate) + log.Printf("[DEBUG] Send DB Instance Modification request: %t", requestUpdate) if requestUpdate { - log.Printf("[DEBUG] DB Instance Modification request: %#v", req) + log.Printf("[DEBUG] DB Instance Modification request: %s", req) _, err := conn.ModifyDBInstance(req) if err != nil { return fmt.Errorf("Error modifying DB Instance %s: %s", d.Id(), err) diff --git a/builtin/providers/aws/resource_aws_db_instance_test.go b/builtin/providers/aws/resource_aws_db_instance_test.go index 1398f82aa..5db77b14c 100644 --- a/builtin/providers/aws/resource_aws_db_instance_test.go +++ b/builtin/providers/aws/resource_aws_db_instance_test.go @@ -176,6 +176,43 @@ func TestAccAWSDBInstance_enhancedMonitoring(t *testing.T) { }) } +// Regression test for https://github.com/hashicorp/terraform/issues/3760 . +// We apply a plan, then change just the iops. If the apply succeeds, we +// consider this a pass, as before in 3760 the request would fail +func TestAccAWSDBInstance_iops_update(t *testing.T) { + var v rds.DBInstance + + rName := acctest.RandString(5) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSDBInstanceDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccSnapshotInstanceConfig_iopsUpdate(rName, 1000), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSDBInstanceExists("aws_db_instance.bar", &v), + testAccCheckAWSDBInstanceAttributes(&v), + ), + }, + + resource.TestStep{ + Config: testAccSnapshotInstanceConfig_iopsUpdate(rName, 2000), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSDBInstanceExists("aws_db_instance.bar", &v), + testAccCheckAWSDBInstanceAttributes(&v), + ), + // The plan will be non-empty because even with apply_immediatley, the + // instance has to apply the change via reboot, so follow up plans will + // show a non empty plan. The test is considered "successful" if the + // follow up change is applied at all. + ExpectNonEmptyPlan: true, + }, + }, + }) +} + func testAccCheckAWSDBInstanceDestroy(s *terraform.State) error { conn := testAccProvider.Meta().(*AWSClient).rdsconn @@ -644,3 +681,23 @@ resource "aws_db_instance" "enhanced_monitoring" { skip_final_snapshot = true } ` + +func testAccSnapshotInstanceConfig_iopsUpdate(rName string, iops int) string { + return fmt.Sprintf(` +resource "aws_db_instance" "bar" { + identifier = "mydb-rds-%s" + engine = "mysql" + engine_version = "5.6.23" + instance_class = "db.t2.micro" + name = "mydb" + username = "foo" + password = "barbarbar" + parameter_group_name = "default.mysql5.6" + + apply_immediately = true + + storage_type = "io1" + allocated_storage = 200 + iops = %d +}`, rName, iops) +}