aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authoralexandreFre <51956137+alexandreFre@users.noreply.github.com>2019-07-11 12:31:07 +0200
committerGitHub <noreply@github.com>2019-07-11 12:31:07 +0200
commit9d6df78b1174819ed7660295aa42d7fa9c3e647c (patch)
tree162f6d79d63f3612dcdfa5de95e99d3214467ee7
parentdbbb014f494c502d8ac26437acd02412ee275b5a (diff)
parent1de838cb1473ab472860ebe63a22d56aba5468b6 (diff)
downloadterraform-provider-mailgun-9d6df78b1174819ed7660295aa42d7fa9c3e647c.tar.gz
terraform-provider-mailgun-9d6df78b1174819ed7660295aa42d7fa9c3e647c.tar.zst
terraform-provider-mailgun-9d6df78b1174819ed7660295aa42d7fa9c3e647c.zip
Merge pull request #16 from alexandreFre/fix_test
fix the tests and ensure the ips are fetched correctly
-rw-r--r--mailgun/resource_mailgun_domain.go24
-rw-r--r--mailgun/resource_mailgun_domain_test.go23
2 files changed, 36 insertions, 11 deletions
diff --git a/mailgun/resource_mailgun_domain.go b/mailgun/resource_mailgun_domain.go
index 86531c6..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"
@@ -366,7 +367,7 @@ func DeleteDomain(d *schema.ResourceData, meta interface{}) error {
366 367
367func ReadDomain(d *schema.ResourceData, meta interface{}) error { 368func ReadDomain(d *schema.ResourceData, meta interface{}) error {
368 mg := meta.(*mailgun.MailgunImpl) 369 mg := meta.(*mailgun.MailgunImpl)
369 ctx, cancel := context.WithTimeout(context.Background(), time.Second*30) 370 ctx, cancel := context.WithTimeout(context.Background(), time.Second*120)
370 defer cancel() 371 defer cancel()
371 domainName := d.Id() 372 domainName := d.Id()
372 mg = mailgun.NewMailgun(domainName, mg.APIKey()) 373 mg = mailgun.NewMailgun(domainName, mg.APIKey())
@@ -425,9 +426,7 @@ func ReadDomain(d *schema.ResourceData, meta interface{}) error {
425 d.Set("unsubscribe_tracking_settings_html_footer", domainTracking.Unsubscribe.HTMLFooter) 426 d.Set("unsubscribe_tracking_settings_html_footer", domainTracking.Unsubscribe.HTMLFooter)
426 d.Set("unsubscribe_tracking_settings_text_footer", domainTracking.Unsubscribe.TextFooter) 427 d.Set("unsubscribe_tracking_settings_text_footer", domainTracking.Unsubscribe.TextFooter)
427 428
428 time.Sleep(25 * time.Second) 429 ipAddress, err := getIps(ctx, mg)
429
430 ipAddress, err := mg.ListDomainIPS(ctx)
431 430
432 if err != nil { 431 if err != nil {
433 return fmt.Errorf("Error Getting mailgun domain ips1 for %s: Error: %s", d.Id(), err) 432 return fmt.Errorf("Error Getting mailgun domain ips1 for %s: Error: %s", d.Id(), err)
@@ -493,3 +492,20 @@ func ImportStatePassthroughDomain(d *schema.ResourceData, meta interface{}) ([]*
493 } 492 }
494 return []*schema.ResourceData{d}, nil 493 return []*schema.ResourceData{d}, nil
495} 494}
495
496func getIps(ctx context.Context,mg *mailgun.MailgunImpl) ([]mailgun.IPAddress, error){
497 var ipAddress []mailgun.IPAddress
498 log.Printf("[DEBUG] begin to fetch ips for %s",mg.Domain())
499 err := resource.Retry(2*time.Minute, func() *resource.RetryError {
500 var err error
501 ipAddress, err = mg.ListDomainIPS(ctx)
502 if err != nil {
503 log.Printf("[DEBUG] failed to fetch ips for %s",mg.Domain())
504 return resource.RetryableError(err)
505 }
506 log.Printf("[DEBUG] managed to fetch ips for %s",mg.Domain())
507
508 return nil
509 })
510 return ipAddress, err
511}
diff --git a/mailgun/resource_mailgun_domain_test.go b/mailgun/resource_mailgun_domain_test.go
index 952e013..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 {
@@ -21,7 +22,7 @@ type fullDomain struct {
21} 22}
22 23
23func getFullDomain(mg *mailgun.MailgunImpl, domainName string) (*fullDomain, error) { 24func getFullDomain(mg *mailgun.MailgunImpl, domainName string) (*fullDomain, error) {
24 ctx, cancel := context.WithTimeout(context.Background(), time.Second*30) 25 ctx, cancel := context.WithTimeout(context.Background(), time.Second*120)
25 defer cancel() 26 defer cancel()
26 mg = mailgun.NewMailgun(domainName, mg.APIKey()) 27 mg = mailgun.NewMailgun(domainName, mg.APIKey())
27 28
@@ -42,7 +43,8 @@ func getFullDomain(mg *mailgun.MailgunImpl, domainName string) (*fullDomain, err
42 return nil, fmt.Errorf("Error Getting mailgun domain tracking Details for %s: Error: %s", domainName, err) 43 return nil, fmt.Errorf("Error Getting mailgun domain tracking Details for %s: Error: %s", domainName, err)
43 } 44 }
44 45
45 ipAddress, err := mg.ListDomainIPS(ctx) 46 ipAddress, err := getIps(ctx, mg)
47
46 if err != nil { 48 if err != nil {
47 return nil, fmt.Errorf("Error Getting mailgun domain ips2 for %s: Error: %s", domainName, err) 49 return nil, fmt.Errorf("Error Getting mailgun domain ips2 for %s: Error: %s", domainName, err)
48 } 50 }
@@ -210,12 +212,19 @@ func testAccDomainCheckDestroy(domain *fullDomain) resource.TestCheckFunc {
210 ctx, cancel := context.WithTimeout(context.Background(), time.Second*30) 212 ctx, cancel := context.WithTimeout(context.Background(), time.Second*30)
211 defer cancel() 213 defer cancel()
212 214
213 _, err := mg.GetDomain(ctx, domain.domainResponse.Domain.Name) 215 log.Printf("[DEBUG] try to fetch destroyed domain %s",mg.Domain())
214 if err == nil {
215 return fmt.Errorf("domain still exists")
216 }
217 216
218 return nil 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 })
219 } 228 }
220} 229}
221 230