mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-09-07 09:36:44 +00:00
Merge pull request #825 from terraform-providers/paddy_fix_db_sweeper
Fix the database sweeper.
This commit is contained in:
commit
e8cd017aac
@ -49,6 +49,8 @@ func testSweepDatabases(region string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
running := map[string]struct{}{}
|
||||||
|
|
||||||
for _, d := range found.Items {
|
for _, d := range found.Items {
|
||||||
var testDbInstance bool
|
var testDbInstance bool
|
||||||
for _, testName := range []string{"tf-lw-", "sqldatabasetest"} {
|
for _, testName := range []string{"tf-lw-", "sqldatabasetest"} {
|
||||||
@ -61,7 +63,18 @@ func testSweepDatabases(region string) error {
|
|||||||
if !testDbInstance {
|
if !testDbInstance {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
if d.State != "RUNNABLE" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
running[d.Name] = struct{}{}
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, d := range found.Items {
|
||||||
|
// don't delete replicas, we'll take care of that
|
||||||
|
// when deleting the database they replicate
|
||||||
|
if d.ReplicaConfiguration != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
log.Printf("Destroying SQL Instance (%s)", d.Name)
|
log.Printf("Destroying SQL Instance (%s)", d.Name)
|
||||||
|
|
||||||
// replicas need to be stopped and destroyed before destroying a master
|
// replicas need to be stopped and destroyed before destroying a master
|
||||||
@ -69,6 +82,12 @@ func testSweepDatabases(region string) error {
|
|||||||
// and we call destroy on them before destroying the master
|
// and we call destroy on them before destroying the master
|
||||||
var ordering []string
|
var ordering []string
|
||||||
for _, replicaName := range d.ReplicaNames {
|
for _, replicaName := range d.ReplicaNames {
|
||||||
|
// don't try to stop replicas that aren't running
|
||||||
|
if _, ok := running[replicaName]; !ok {
|
||||||
|
ordering = append(ordering, replicaName)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
// need to stop replication before being able to destroy a database
|
// need to stop replication before being able to destroy a database
|
||||||
op, err := config.clientSqlAdmin.Instances.StopReplica(config.Project, replicaName).Do()
|
op, err := config.clientSqlAdmin.Instances.StopReplica(config.Project, replicaName).Do()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user