From be59831847702a0fa9e1795adabd474c81c86fc8 Mon Sep 17 00:00:00 2001 From: Paul Hinze Date: Thu, 21 Jan 2016 09:51:08 -0600 Subject: [PATCH] mailgun: poll until domain destroy takes effect Test failures indicate that this operation doesn't always take effect immediately: https://travis-ci.org/hashicorp/terraform/builds/103764466 Add a simple poll to retry a few times until it does. ``` --- PASS: TestAccMailgunDomain_Basic (1.51s) ``` Verified that this does the trick by looping the test and watching the logs for the retry behavior to kick in. --- .../providers/mailgun/resource_mailgun_domain.go | 13 ++++++++++++- .../mailgun/resource_mailgun_domain_test.go | 4 ++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/builtin/providers/mailgun/resource_mailgun_domain.go b/builtin/providers/mailgun/resource_mailgun_domain.go index 7dd287c90..fb180bc0c 100644 --- a/builtin/providers/mailgun/resource_mailgun_domain.go +++ b/builtin/providers/mailgun/resource_mailgun_domain.go @@ -3,7 +3,9 @@ package mailgun import ( "fmt" "log" + "time" + "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/schema" "github.com/pearkes/mailgun" ) @@ -143,7 +145,16 @@ func resourceMailgunDomainDelete(d *schema.ResourceData, meta interface{}) error return fmt.Errorf("Error deleting domain: %s", err) } - return nil + // Give the destroy a chance to take effect + return resource.Retry(1*time.Minute, func() error { + _, err = client.RetrieveDomain(d.Id()) + if err == nil { + log.Printf("[INFO] Retrying until domain disappears...") + return fmt.Errorf("Domain seems to still exist; will check again.") + } + log.Printf("[INFO] Got error looking for domain, seems gone: %s", err) + return nil + }) } func resourceMailgunDomainRead(d *schema.ResourceData, meta interface{}) error { diff --git a/builtin/providers/mailgun/resource_mailgun_domain_test.go b/builtin/providers/mailgun/resource_mailgun_domain_test.go index 7bad19ddb..56e7f7bd2 100644 --- a/builtin/providers/mailgun/resource_mailgun_domain_test.go +++ b/builtin/providers/mailgun/resource_mailgun_domain_test.go @@ -48,10 +48,10 @@ func testAccCheckMailgunDomainDestroy(s *terraform.State) error { continue } - _, err := client.RetrieveDomain(rs.Primary.ID) + resp, err := client.RetrieveDomain(rs.Primary.ID) if err == nil { - return fmt.Errorf("Domain still exists") + return fmt.Errorf("Domain still exists: %s", resp) } }