providers/aws: db instance wait for destroy, allow destroy config
This commit is contained in:
parent
dec733f7ed
commit
e07dc8891d
|
@ -4,6 +4,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform/flatmap"
|
"github.com/hashicorp/terraform/flatmap"
|
||||||
|
@ -156,16 +157,29 @@ func resource_aws_db_instance_destroy(
|
||||||
|
|
||||||
if s.Attributes["skip_final_snapshot"] == "true" {
|
if s.Attributes["skip_final_snapshot"] == "true" {
|
||||||
opts.SkipFinalSnapshot = true
|
opts.SkipFinalSnapshot = true
|
||||||
|
} else {
|
||||||
|
opts.FinalDBSnapshotIdentifier = s.Attributes["final_snapshot_identifier"]
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("[DEBUG] DB Instance destroy configuration: %v", opts)
|
log.Printf("[DEBUG] DB Instance destroy configuration: %v", opts)
|
||||||
_, err := conn.DeleteDBInstance(&opts)
|
_, err := conn.DeleteDBInstance(&opts)
|
||||||
|
|
||||||
if err != nil {
|
log.Println(
|
||||||
newerr, ok := err.(*rds.Error)
|
"[INFO] Waiting for DB Instance to be destroyed")
|
||||||
if ok && newerr.Code == "InvalidDBInstance.NotFound" {
|
|
||||||
return nil
|
stateConf := &resource.StateChangeConf{
|
||||||
|
Pending: []string{"creating", "backing-up",
|
||||||
|
"modifying", "deleting", "available"},
|
||||||
|
Target: "",
|
||||||
|
Refresh: DBInstanceStateRefreshFunc(s.ID, conn),
|
||||||
|
Timeout: 10 * 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
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -212,6 +226,8 @@ func resource_aws_db_instance_diff(
|
||||||
"username": diff.AttrTypeCreate,
|
"username": diff.AttrTypeCreate,
|
||||||
"vpc_security_group_ids": diff.AttrTypeCreate,
|
"vpc_security_group_ids": diff.AttrTypeCreate,
|
||||||
"security_group_names": diff.AttrTypeCreate,
|
"security_group_names": diff.AttrTypeCreate,
|
||||||
|
"skip_final_snapshot": diff.AttrTypeUpdate,
|
||||||
|
"final_snapshot_identifier": diff.AttrTypeUpdate,
|
||||||
},
|
},
|
||||||
|
|
||||||
ComputedAttrs: []string{
|
ComputedAttrs: []string{
|
||||||
|
@ -230,17 +246,7 @@ func resource_aws_db_instance_diff(
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
rd, err := b.Diff(s, c)
|
return b.Diff(s, c)
|
||||||
if err != nil {
|
|
||||||
return rd, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove the password from the resource diff, so Terraform
|
|
||||||
// doesn't think it will change (we don't store the password)
|
|
||||||
// in state for security reasons, so it will always be "" otherwise
|
|
||||||
delete(rd.Attributes, "password")
|
|
||||||
|
|
||||||
return rd, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func resource_aws_db_instance_update_state(
|
func resource_aws_db_instance_update_state(
|
||||||
|
@ -344,6 +350,12 @@ func DBInstanceStateRefreshFunc(id string, conn *rds.Rds) resource.StateRefreshF
|
||||||
v, err := resource_aws_db_instance_retrieve(id, conn)
|
v, err := resource_aws_db_instance_retrieve(id, conn)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
// We want to special-case "not found" instances because
|
||||||
|
// it could be waiting for it to be gone.
|
||||||
|
if strings.Contains(err.Error(), "DBInstanceNotFound") {
|
||||||
|
return nil, "", nil
|
||||||
|
}
|
||||||
|
|
||||||
log.Printf("Error on retrieving DB Instance when waiting: %s", err)
|
log.Printf("Error on retrieving DB Instance when waiting: %s", err)
|
||||||
return nil, "", err
|
return nil, "", err
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,9 +23,9 @@ func TestAccAWSDBInstance(t *testing.T) {
|
||||||
testAccCheckAWSDBInstanceExists("aws_db_instance.bar", &v),
|
testAccCheckAWSDBInstanceExists("aws_db_instance.bar", &v),
|
||||||
testAccCheckAWSDBInstanceAttributes(&v),
|
testAccCheckAWSDBInstanceAttributes(&v),
|
||||||
resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
"aws_db_instance.bar", "instance_identifier", "foobarbaz-test-terraform"),
|
"aws_db_instance.bar", "identifier", "foobarbaz-test-terraform"),
|
||||||
resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
"aws_db_instance.bar", "allocated_storage", "foobarbaz-test-terraform"),
|
"aws_db_instance.bar", "allocated_storage", "10"),
|
||||||
resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
"aws_db_instance.bar", "engine", "mysql"),
|
"aws_db_instance.bar", "engine", "mysql"),
|
||||||
resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
|
@ -35,7 +35,8 @@ func TestAccAWSDBInstance(t *testing.T) {
|
||||||
resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
"aws_db_instance.bar", "name", "baz"),
|
"aws_db_instance.bar", "name", "baz"),
|
||||||
resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
"aws_db_instance.bar", "password", "barbarbarbar"),
|
// Shouldn't save password to state
|
||||||
|
"aws_db_instance.bar", "password", ""),
|
||||||
resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
"aws_db_instance.bar", "username", "foo"),
|
"aws_db_instance.bar", "username", "foo"),
|
||||||
resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
|
|
Loading…
Reference in New Issue