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) } }