diff --git a/builtin/providers/aws/resource_aws_db_instance.go b/builtin/providers/aws/resource_aws_db_instance.go index 4b6c3985e..8dc6f115b 100644 --- a/builtin/providers/aws/resource_aws_db_instance.go +++ b/builtin/providers/aws/resource_aws_db_instance.go @@ -160,7 +160,6 @@ func resourceAwsDbInstance() *schema.Resource { Type: schema.TypeInt, Optional: true, Computed: true, - ForceNew: true, }, "publicly_accessible": &schema.Schema{ @@ -654,6 +653,7 @@ func resourceAwsDbInstanceRead(d *schema.ResourceData, meta interface{}) error { d.Set("publicly_accessible", v.PubliclyAccessible) d.Set("multi_az", v.MultiAZ) d.Set("kms_key_id", v.KmsKeyId) + d.Set("port", v.DbInstancePort) if v.DBSubnetGroup != nil { d.Set("db_subnet_group_name", v.DBSubnetGroup.DBSubnetGroupName) } @@ -923,6 +923,12 @@ func resourceAwsDbInstanceUpdate(d *schema.ResourceData, meta interface{}) error requestUpdate = true } + if d.HasChange("port") { + d.SetPartial("port") + req.DBPortNumber = aws.Int64(int64(d.Get("port").(int))) + requestUpdate = true + } + log.Printf("[DEBUG] Send DB Instance Modification request: %t", requestUpdate) if requestUpdate { log.Printf("[DEBUG] DB Instance Modification request: %s", req) @@ -930,6 +936,24 @@ func resourceAwsDbInstanceUpdate(d *schema.ResourceData, meta interface{}) error if err != nil { return fmt.Errorf("Error modifying DB Instance %s: %s", d.Id(), err) } + + log.Println("[INFO] Waiting for DB Instance to be available") + + stateConf := &resource.StateChangeConf{ + Pending: []string{"creating", "backing-up", "modifying", "resetting-master-credentials", + "maintenance", "renaming", "rebooting", "upgrading"}, + Target: []string{"available"}, + Refresh: resourceAwsDbInstanceStateRefreshFunc(d, meta), + Timeout: 80 * time.Minute, + MinTimeout: 10 * time.Second, + Delay: 30 * time.Second, // Wait 30 secs before starting + } + + // Wait, catching any errors + _, dbStateErr := stateConf.WaitForState() + if dbStateErr != nil { + return dbStateErr + } } // separate request to promote a database diff --git a/builtin/providers/aws/resource_aws_db_instance_test.go b/builtin/providers/aws/resource_aws_db_instance_test.go index 5db77b14c..36bf6e508 100644 --- a/builtin/providers/aws/resource_aws_db_instance_test.go +++ b/builtin/providers/aws/resource_aws_db_instance_test.go @@ -213,6 +213,37 @@ func TestAccAWSDBInstance_iops_update(t *testing.T) { }) } +func TestAccAWSDBInstance_portUpdate(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_mysqlPort(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSDBInstanceExists("aws_db_instance.bar", &v), + resource.TestCheckResourceAttr( + "aws_db_instance.bar", "port", "3306"), + ), + }, + + resource.TestStep{ + Config: testAccSnapshotInstanceConfig_updateMysqlPort(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSDBInstanceExists("aws_db_instance.bar", &v), + resource.TestCheckResourceAttr( + "aws_db_instance.bar", "port", "3305"), + ), + }, + }, + }) +} + func testAccCheckAWSDBInstanceDestroy(s *terraform.State) error { conn := testAccProvider.Meta().(*AWSClient).rdsconn @@ -701,3 +732,39 @@ resource "aws_db_instance" "bar" { iops = %d }`, rName, iops) } + +func testAccSnapshotInstanceConfig_mysqlPort(rName string) 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" + port = 3306 + allocated_storage = 10 + + apply_immediately = true +}`, rName) +} + +func testAccSnapshotInstanceConfig_updateMysqlPort(rName string) 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" + port = 3305 + allocated_storage = 10 + + apply_immediately = true +}`, rName) +}