aboutsummaryrefslogtreecommitdiffhomepage
path: root/mailgun
diff options
context:
space:
mode:
authorAlexandre Garand <alexandre.garand@fretlink.com>2019-07-09 13:48:52 +0200
committerAlexandre Garand <alexandre.garand@fretlink.com>2019-07-09 13:48:52 +0200
commit1de838cb1473ab472860ebe63a22d56aba5468b6 (patch)
tree162f6d79d63f3612dcdfa5de95e99d3214467ee7 /mailgun
parent5976bba0b5dd67d2169641a5c3dab935155fb885 (diff)
downloadterraform-provider-mailgun-1de838cb1473ab472860ebe63a22d56aba5468b6.tar.gz
terraform-provider-mailgun-1de838cb1473ab472860ebe63a22d56aba5468b6.tar.zst
terraform-provider-mailgun-1de838cb1473ab472860ebe63a22d56aba5468b6.zip
replace sleep by resource.Retry
Diffstat (limited to 'mailgun')
-rw-r--r--mailgun/resource_mailgun_domain.go20
-rw-r--r--mailgun/resource_mailgun_domain_test.go20
2 files changed, 27 insertions, 13 deletions
diff --git a/mailgun/resource_mailgun_domain.go b/mailgun/resource_mailgun_domain.go
index e2bfe73..c195cf0 100644
--- a/mailgun/resource_mailgun_domain.go
+++ b/mailgun/resource_mailgun_domain.go
@@ -4,6 +4,7 @@ import (
4 "context" 4 "context"
5 "fmt" 5 "fmt"
6 "github.com/hashicorp/terraform/helper/schema" 6 "github.com/hashicorp/terraform/helper/schema"
7 "github.com/hashicorp/terraform/helper/resource"
7 "github.com/mailgun/mailgun-go/v3" 8 "github.com/mailgun/mailgun-go/v3"
8 "log" 9 "log"
9 "time" 10 "time"
@@ -493,13 +494,18 @@ func ImportStatePassthroughDomain(d *schema.ResourceData, meta interface{}) ([]*
493} 494}
494 495
495func getIps(ctx context.Context,mg *mailgun.MailgunImpl) ([]mailgun.IPAddress, error){ 496func getIps(ctx context.Context,mg *mailgun.MailgunImpl) ([]mailgun.IPAddress, error){
496 start := time.Now() 497 var ipAddress []mailgun.IPAddress
497 t := time.Now() 498 log.Printf("[DEBUG] begin to fetch ips for %s",mg.Domain())
498 ipAddress, err := mg.ListDomainIPS(ctx) 499 err := resource.Retry(2*time.Minute, func() *resource.RetryError {
499 for (err != nil && t.Sub(start)< 120 * time.Second) { 500 var err error
500 ipAddress, err = mg.ListDomainIPS(ctx) 501 ipAddress, err = mg.ListDomainIPS(ctx)
501 time.Sleep(5 * time.Second) 502 if err != nil {
502 t = time.Now() 503 log.Printf("[DEBUG] failed to fetch ips for %s",mg.Domain())
503 } 504 return resource.RetryableError(err)
505 }
506 log.Printf("[DEBUG] managed to fetch ips for %s",mg.Domain())
507
508 return nil
509 })
504 return ipAddress, err 510 return ipAddress, err
505} 511}
diff --git a/mailgun/resource_mailgun_domain_test.go b/mailgun/resource_mailgun_domain_test.go
index a129b1f..57aa630 100644
--- a/mailgun/resource_mailgun_domain_test.go
+++ b/mailgun/resource_mailgun_domain_test.go
@@ -10,6 +10,7 @@ import (
10 "strconv" 10 "strconv"
11 "testing" 11 "testing"
12 "time" 12 "time"
13 "log"
13) 14)
14 15
15type fullDomain struct { 16type fullDomain struct {
@@ -210,13 +211,20 @@ func testAccDomainCheckDestroy(domain *fullDomain) resource.TestCheckFunc {
210 mg := testAccProvider.Meta().(*mailgun.MailgunImpl) 211 mg := testAccProvider.Meta().(*mailgun.MailgunImpl)
211 ctx, cancel := context.WithTimeout(context.Background(), time.Second*30) 212 ctx, cancel := context.WithTimeout(context.Background(), time.Second*30)
212 defer cancel() 213 defer cancel()
213 time.Sleep(5 * time.Second)
214 _, err := mg.GetDomain(ctx, domain.domainResponse.Domain.Name)
215 if err == nil {
216 return fmt.Errorf("domain still exists")
217 }
218 214
219 return nil 215 log.Printf("[DEBUG] try to fetch destroyed domain %s",mg.Domain())
216
217 return resource.Retry(1*time.Minute, func() *resource.RetryError {
218 _, err := mg.GetDomain(ctx, domain.domainResponse.Domain.Name)
219 if err == nil {
220 log.Printf("[DEBUG] managed to fetch destroyed domain %s",mg.Domain())
221 return resource.RetryableError(err)
222 }
223
224 log.Printf("[DEBUG] failed to fetch destroyed domain %s",mg.Domain())
225
226 return nil
227 })
220 } 228 }
221} 229}
222 230