From 4f9687e457eea8aa1963505029d934d950a30432 Mon Sep 17 00:00:00 2001 From: Paddy Date: Wed, 6 Dec 2017 11:56:17 -0800 Subject: [PATCH 1/3] Fix the database sweeper. It's getting hung up on a database replica instance that's not running, so it can't stop it. To resolve, we're only trying to stop replica instances that are in a running state. Also, I noticed a bug that we'd try to delete replicas twice, so I fixed that, as well. --- google/resource_sql_database_instance_test.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/google/resource_sql_database_instance_test.go b/google/resource_sql_database_instance_test.go index b9e1fde1..46d5496d 100644 --- a/google/resource_sql_database_instance_test.go +++ b/google/resource_sql_database_instance_test.go @@ -49,6 +49,8 @@ func testSweepDatabases(region string) error { return nil } + running := map[string]struct{}{} + for _, d := range found.Items { var testDbInstance bool for _, testName := range []string{"tf-lw-", "sqldatabasetest"} { @@ -61,7 +63,15 @@ func testSweepDatabases(region string) error { if !testDbInstance { 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) // replicas need to be stopped and destroyed before destroying a master @@ -69,6 +79,12 @@ func testSweepDatabases(region string) error { // and we call destroy on them before destroying the master var ordering []string 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 op, err := config.clientSqlAdmin.Instances.StopReplica(config.Project, replicaName).Do() From f717f878e731faa3fc58862ab68773a0d2d94788 Mon Sep 17 00:00:00 2001 From: Paddy Date: Wed, 6 Dec 2017 11:59:45 -0800 Subject: [PATCH 2/3] Actually check if an instance is running. Forgot the most important part of the fix! --- google/resource_sql_database_instance_test.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/google/resource_sql_database_instance_test.go b/google/resource_sql_database_instance_test.go index 46d5496d..2fccb1fb 100644 --- a/google/resource_sql_database_instance_test.go +++ b/google/resource_sql_database_instance_test.go @@ -63,6 +63,9 @@ func testSweepDatabases(region string) error { if !testDbInstance { continue } + if !d.State == "RUNNABLE" { + continue + } running[d.Name] = struct{}{} } From 04fb54a8fc00438f593a81661079c625508e5cd8 Mon Sep 17 00:00:00 2001 From: Paddy Date: Wed, 6 Dec 2017 12:01:30 -0800 Subject: [PATCH 3/3] I'm on a roll. How do program. --- google/resource_sql_database_instance_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google/resource_sql_database_instance_test.go b/google/resource_sql_database_instance_test.go index 2fccb1fb..627314cc 100644 --- a/google/resource_sql_database_instance_test.go +++ b/google/resource_sql_database_instance_test.go @@ -63,7 +63,7 @@ func testSweepDatabases(region string) error { if !testDbInstance { continue } - if !d.State == "RUNNABLE" { + if d.State != "RUNNABLE" { continue } running[d.Name] = struct{}{}