Merge pull request #4777 from hashicorp/phinze/mailgun-domain-destroy-takes-a-sec

mailgun: poll until domain destroy takes effect
This commit is contained in:
Paul Hinze 2016-01-21 11:56:37 -06:00
commit 8d2e18234e
2 changed files with 14 additions and 3 deletions

View File

@ -3,7 +3,9 @@ package mailgun
import ( import (
"fmt" "fmt"
"log" "log"
"time"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
"github.com/pearkes/mailgun" "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 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 { func resourceMailgunDomainRead(d *schema.ResourceData, meta interface{}) error {

View File

@ -48,10 +48,10 @@ func testAccCheckMailgunDomainDestroy(s *terraform.State) error {
continue continue
} }
_, err := client.RetrieveDomain(rs.Primary.ID) resp, err := client.RetrieveDomain(rs.Primary.ID)
if err == nil { if err == nil {
return fmt.Errorf("Domain still exists") return fmt.Errorf("Domain still exists: %s", resp)
} }
} }