provider/aws: Allow `port` on `aws_db_instance` to be updated (#7441)
Fixes #2439 Port used to ForceNew, it has now been changed to allow it to be updated. 2 changes were needed: 1. Setting the port back to state 2. Adding the wait for state function to the Update func ``` make testacc TEST=./builtin/providers/aws TESTARGS='-run=TestAccAWSDBInstance_portUpdate' ==> Checking that code complies with gofmt requirements... go generate $(go list ./... | grep -v /vendor/) TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSDBInstance_portUpdate -timeout 120m === RUN TestAccAWSDBInstance_portUpdate --- PASS: TestAccAWSDBInstance_portUpdate (699.84s) PASS ok github.com/hashicorp/terraform/builtin/providers/aws 699.861s ```
This commit is contained in:
parent
c990625516
commit
303ba86cf6
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue