Skip to content

Commit be59831

Browse files
committed
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.
1 parent a5b2886 commit be59831

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

builtin/providers/mailgun/resource_mailgun_domain.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ package mailgun
33
import (
44
"fmt"
55
"log"
6+
"time"
67

8+
"github.com/hashicorp/terraform/helper/resource"
79
"github.com/hashicorp/terraform/helper/schema"
810
"github.com/pearkes/mailgun"
911
)
@@ -143,7 +145,16 @@ func resourceMailgunDomainDelete(d *schema.ResourceData, meta interface{}) error
143145
return fmt.Errorf("Error deleting domain: %s", err)
144146
}
145147

146-
return nil
148+
// Give the destroy a chance to take effect
149+
return resource.Retry(1*time.Minute, func() error {
150+
_, err = client.RetrieveDomain(d.Id())
151+
if err == nil {
152+
log.Printf("[INFO] Retrying until domain disappears...")
153+
return fmt.Errorf("Domain seems to still exist; will check again.")
154+
}
155+
log.Printf("[INFO] Got error looking for domain, seems gone: %s", err)
156+
return nil
157+
})
147158
}
148159

149160
func resourceMailgunDomainRead(d *schema.ResourceData, meta interface{}) error {

builtin/providers/mailgun/resource_mailgun_domain_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ func testAccCheckMailgunDomainDestroy(s *terraform.State) error {
4848
continue
4949
}
5050

51-
_, err := client.RetrieveDomain(rs.Primary.ID)
51+
resp, err := client.RetrieveDomain(rs.Primary.ID)
5252

5353
if err == nil {
54-
return fmt.Errorf("Domain still exists")
54+
return fmt.Errorf("Domain still exists: %s", resp)
5555
}
5656
}
5757

0 commit comments

Comments
 (0)