From 32d04797f92627d266566598ed2bffe9c9b93572 Mon Sep 17 00:00:00 2001 From: Michael Austin Date: Wed, 14 Oct 2015 13:23:11 -0400 Subject: [PATCH 1/4] update security group after restore from snapshot --- .../providers/aws/resource_aws_db_instance.go | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/builtin/providers/aws/resource_aws_db_instance.go b/builtin/providers/aws/resource_aws_db_instance.go index 78c6a0acd..405967888 100644 --- a/builtin/providers/aws/resource_aws_db_instance.go +++ b/builtin/providers/aws/resource_aws_db_instance.go @@ -350,6 +350,42 @@ func resourceAwsDbInstanceCreate(d *schema.ResourceData, meta interface{}) error if err != nil { return fmt.Errorf("Error creating DB Instance: %s", err) } + + if attr := d.Get("vpc_security_group_ids").(*schema.Set); attr.Len() > 0 { + var s []*string + for _, v := range attr.List() { + s = append(s, aws.String(v.(string))) + } + log.Printf("[INFO] DB is restoring from snapshot with default security, but should be set to %s", s) + // 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.Println( + "[INFO] Waiting for DB Instance to be available") + + stateConf := &resource.StateChangeConf{ + Pending: []string{"creating", "backing-up", "modifying"}, + Target: "available", + Refresh: resourceAwsDbInstanceStateRefreshFunc(d, meta), + Timeout: 40 * time.Minute, + MinTimeout: 10 * time.Second, + Delay: 30 * time.Second, // Wait 30 secs before starting + } + + // Wait, catching any errors + _, err := stateConf.WaitForState() + if err != nil { + return err + } + + err = resourceAwsDbInstanceUpdate(d, meta) + if err != nil { + return err + } + + } } else { opts := rds.CreateDBInstanceInput{ AllocatedStorage: aws.Int64(int64(d.Get("allocated_storage").(int))), From 53e196eaedda86c61f1e7e882531f2cf0540ad3b Mon Sep 17 00:00:00 2001 From: Michael Austin Date: Thu, 15 Oct 2015 12:55:33 -0400 Subject: [PATCH 2/4] fix vet error --- builtin/providers/aws/resource_aws_db_instance.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builtin/providers/aws/resource_aws_db_instance.go b/builtin/providers/aws/resource_aws_db_instance.go index efb6a17c2..4fbf7b410 100644 --- a/builtin/providers/aws/resource_aws_db_instance.go +++ b/builtin/providers/aws/resource_aws_db_instance.go @@ -356,7 +356,7 @@ func resourceAwsDbInstanceCreate(d *schema.ResourceData, meta interface{}) error for _, v := range attr.List() { s = append(s, aws.String(v.(string))) } - log.Printf("[INFO] DB is restoring from snapshot with default security, but should be set to %s", s) + log.Printf("[INFO] DB is restoring from snapshot with default security, but should be set to %s", v.(string)) // wait for instance to get up and then modify security d.SetId(d.Get("identifier").(string)) From 5448e01269fc4534dc8a5f48ae5c88d4c97354c8 Mon Sep 17 00:00:00 2001 From: Michael Austin Date: Thu, 29 Oct 2015 17:53:40 -0400 Subject: [PATCH 3/4] removed extraneous debug code and clarified INFO logging --- builtin/providers/aws/resource_aws_db_instance.go | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/builtin/providers/aws/resource_aws_db_instance.go b/builtin/providers/aws/resource_aws_db_instance.go index 4fbf7b410..eddc7bcb5 100644 --- a/builtin/providers/aws/resource_aws_db_instance.go +++ b/builtin/providers/aws/resource_aws_db_instance.go @@ -352,11 +352,8 @@ func resourceAwsDbInstanceCreate(d *schema.ResourceData, meta interface{}) error } if attr := d.Get("vpc_security_group_ids").(*schema.Set); attr.Len() > 0 { - var s []*string - for _, v := range attr.List() { - s = append(s, aws.String(v.(string))) - } - log.Printf("[INFO] DB is restoring from snapshot with default security, but should be set to %s", v.(string)) + 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)) From a0322f9b8ce4b1c4179e8098f9d503c40f0cb297 Mon Sep 17 00:00:00 2001 From: Michael Austin Date: Thu, 29 Oct 2015 17:55:23 -0400 Subject: [PATCH 4/4] go fmt --- builtin/providers/aws/resource_aws_db_instance.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builtin/providers/aws/resource_aws_db_instance.go b/builtin/providers/aws/resource_aws_db_instance.go index eddc7bcb5..1975c5e52 100644 --- a/builtin/providers/aws/resource_aws_db_instance.go +++ b/builtin/providers/aws/resource_aws_db_instance.go @@ -352,7 +352,7 @@ func resourceAwsDbInstanceCreate(d *schema.ResourceData, meta interface{}) error } if attr := d.Get("vpc_security_group_ids").(*schema.Set); attr.Len() > 0 { - log.Printf("[INFO] DB is restoring from snapshot with default security, but custom security should be set, will now update after snapshot is restored!"); + 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))