Skip to content

Commit 6492853

Browse files
committed
Merge pull request hashicorp#3513 from iJoinSolutions/5873-terraform-snapshot-security-v6.3
Provider/aws Apply security group after restoring db_instance from snapshot
2 parents 232a538 + a0322f9 commit 6492853

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

builtin/providers/aws/resource_aws_db_instance.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,39 @@ func resourceAwsDbInstanceCreate(d *schema.ResourceData, meta interface{}) error
351351
if err != nil {
352352
return fmt.Errorf("Error creating DB Instance: %s", err)
353353
}
354+
355+
if attr := d.Get("vpc_security_group_ids").(*schema.Set); attr.Len() > 0 {
356+
log.Printf("[INFO] DB is restoring from snapshot with default security, but custom security should be set, will now update after snapshot is restored!")
357+
358+
// wait for instance to get up and then modify security
359+
d.SetId(d.Get("identifier").(string))
360+
361+
log.Printf("[INFO] DB Instance ID: %s", d.Id())
362+
363+
log.Println(
364+
"[INFO] Waiting for DB Instance to be available")
365+
366+
stateConf := &resource.StateChangeConf{
367+
Pending: []string{"creating", "backing-up", "modifying"},
368+
Target: "available",
369+
Refresh: resourceAwsDbInstanceStateRefreshFunc(d, meta),
370+
Timeout: 40 * time.Minute,
371+
MinTimeout: 10 * time.Second,
372+
Delay: 30 * time.Second, // Wait 30 secs before starting
373+
}
374+
375+
// Wait, catching any errors
376+
_, err := stateConf.WaitForState()
377+
if err != nil {
378+
return err
379+
}
380+
381+
err = resourceAwsDbInstanceUpdate(d, meta)
382+
if err != nil {
383+
return err
384+
}
385+
386+
}
354387
} else {
355388
opts := rds.CreateDBInstanceInput{
356389
AllocatedStorage: aws.Int64(int64(d.Get("allocated_storage").(int))),

0 commit comments

Comments
 (0)