aboutsummaryrefslogtreecommitdiffhomepage
path: root/mailgun/resource_mailgun_domain.go
diff options
context:
space:
mode:
Diffstat (limited to 'mailgun/resource_mailgun_domain.go')
-rw-r--r--mailgun/resource_mailgun_domain.go24
1 files changed, 20 insertions, 4 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}