Skip to content

Commit

Permalink
Merge pull request #4777 from hashicorp/phinze/mailgun-domain-destroy…
Browse files Browse the repository at this point in the history
…-takes-a-sec

mailgun: poll until domain destroy takes effect
  • Loading branch information
phinze committed Jan 21, 2016
2 parents 0942252 + be59831 commit 8d2e182
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
13 changes: 12 additions & 1 deletion builtin/providers/mailgun/resource_mailgun_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions builtin/providers/mailgun/resource_mailgun_domain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down

0 comments on commit 8d2e182

Please sign in to comment.