Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resource/aws_db_instance: Force update when snapshot_identifier is set #2869

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 19 additions & 39 deletions aws/resource_aws_db_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -500,50 +500,30 @@ 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
}

if err = resourceAwsDbInstanceUpdate(d, meta); err != nil {
return err
}
} else {
if _, ok := d.GetOk("allocated_storage"); !ok {
Expand Down