From 4040eaba55afcff4b3a182e8ba70b7990831f015 Mon Sep 17 00:00:00 2001 From: Atsushi Ishibashi Date: Fri, 5 Jan 2018 11:01:50 +0900 Subject: [PATCH 1/3] Force update when snapshot_identifier is set --- aws/resource_aws_db_instance.go | 59 +++++++++++---------------------- 1 file changed, 20 insertions(+), 39 deletions(-) diff --git a/aws/resource_aws_db_instance.go b/aws/resource_aws_db_instance.go index b52d856a1e28..ef1aff864124 100644 --- a/aws/resource_aws_db_instance.go +++ b/aws/resource_aws_db_instance.go @@ -500,50 +500,31 @@ func resourceAwsDbInstanceCreate(d *schema.ResourceData, meta interface{}) error return fmt.Errorf("Error creating DB Instance: %s", err) } - var sgUpdate bool - var passwordUpdate bool + // wait for instance to get up and then modify + d.SetId(d.Get("identifier").(string)) - if _, ok := d.GetOk("password"); ok { - passwordUpdate = true - } - - if attr := d.Get("vpc_security_group_ids").(*schema.Set); attr.Len() > 0 { - sgUpdate = true - } - if attr := d.Get("security_group_names").(*schema.Set); attr.Len() > 0 { - sgUpdate = true - } - if sgUpdate || passwordUpdate { - log.Printf("[INFO] DB is restoring from snapshot with default security, but custom security should be set, will now update after snapshot is restored!") - - // wait for instance to get up and then modify security - d.SetId(d.Get("identifier").(string)) + log.Printf("[INFO] DB Instance ID: %s", d.Id()) - log.Printf("[INFO] DB Instance ID: %s", d.Id()) - - log.Println( - "[INFO] Waiting for DB Instance to be available") - - stateConf := &resource.StateChangeConf{ - Pending: resourceAwsDbInstanceCreatePendingStates, - Target: []string{"available", "storage-optimization"}, - Refresh: resourceAwsDbInstanceStateRefreshFunc(d.Id(), conn), - Timeout: d.Timeout(schema.TimeoutCreate), - MinTimeout: 10 * time.Second, - Delay: 30 * time.Second, // Wait 30 secs before starting - } + log.Println("[INFO] Waiting for DB Instance to be available") - // Wait, catching any errors - _, err := stateConf.WaitForState() - if err != nil { - return err - } + stateConf := &resource.StateChangeConf{ + Pending: resourceAwsDbInstanceCreatePendingStates, + Target: []string{"available", "storage-optimization"}, + Refresh: resourceAwsDbInstanceStateRefreshFunc(d.Id(), conn), + Timeout: d.Timeout(schema.TimeoutCreate), + MinTimeout: 10 * time.Second, + Delay: 30 * time.Second, // Wait 30 secs before starting + } - err = resourceAwsDbInstanceUpdate(d, meta) - if err != nil { - return err - } + // Wait, catching any errors + _, err := stateConf.WaitForState() + if err != nil { + return err + } + err = resourceAwsDbInstanceUpdate(d, meta) + if err != nil { + return err } } else { if _, ok := d.GetOk("allocated_storage"); !ok { From cc0d8805b4b2672d4ad5154daf82d7b010fc2f60 Mon Sep 17 00:00:00 2001 From: Atsushi Ishibashi Date: Sat, 6 Jan 2018 17:11:43 +0900 Subject: [PATCH 2/3] change --- aws/resource_aws_db_instance.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/aws/resource_aws_db_instance.go b/aws/resource_aws_db_instance.go index ef1aff864124..2703bb5b794f 100644 --- a/aws/resource_aws_db_instance.go +++ b/aws/resource_aws_db_instance.go @@ -522,8 +522,7 @@ func resourceAwsDbInstanceCreate(d *schema.ResourceData, meta interface{}) error return err } - err = resourceAwsDbInstanceUpdate(d, meta) - if err != nil { + if err = resourceAwsDbInstanceUpdate(d, meta); err != nil { return err } } else { From 27d504ac22cd69d2c7f77f2744f730b4f628d7c3 Mon Sep 17 00:00:00 2001 From: Atsushi Ishibashi Date: Sat, 6 Jan 2018 18:26:48 +0900 Subject: [PATCH 3/3] fix --- aws/resource_aws_db_instance.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aws/resource_aws_db_instance.go b/aws/resource_aws_db_instance.go index 2703bb5b794f..8189ecf4a82d 100644 --- a/aws/resource_aws_db_instance.go +++ b/aws/resource_aws_db_instance.go @@ -517,7 +517,7 @@ func resourceAwsDbInstanceCreate(d *schema.ResourceData, meta interface{}) error } // Wait, catching any errors - _, err := stateConf.WaitForState() + _, err = stateConf.WaitForState() if err != nil { return err }