"context"
"fmt"
"github.com/hashicorp/terraform/helper/schema"
- "github.com/mailgun/mailgun-go"
+ "github.com/mailgun/mailgun-go/v3"
"log"
"time"
)
Delete: DeleteDomain,
Read: ReadDomain,
Importer: &schema.ResourceImporter{
- State: schema.ImportStatePassthrough,
+ State: ImportStatePassthroughDomain,
},
Schema: map[string]*schema.Schema{
func ReadDomain(d *schema.ResourceData, meta interface{}) error {
mg := meta.(*mailgun.MailgunImpl)
- ctx, cancel := context.WithTimeout(context.Background(), time.Second*30)
+ ctx, cancel := context.WithTimeout(context.Background(), time.Second*120)
defer cancel()
- domainName := d.Get("name").(string)
+ domainName := d.Id()
mg = mailgun.NewMailgun(domainName, mg.APIKey())
domainResponse, err := mg.GetDomain(ctx, domainName)
d.Set("unsubscribe_tracking_settings_html_footer", domainTracking.Unsubscribe.HTMLFooter)
d.Set("unsubscribe_tracking_settings_text_footer", domainTracking.Unsubscribe.TextFooter)
- time.Sleep(20 * time.Second)
-
- ipAddress, err := mg.ListDomainIPS(ctx)
+ ipAddress, err := getIps(ctx, mg)
if err != nil {
return fmt.Errorf("Error Getting mailgun domain ips1 for %s: Error: %s", d.Id(), err)
}
return result, nil
}
+
+func ImportStatePassthroughDomain(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
+ if _, ok := d.GetOk("dkim_key_size"); !ok {
+ d.Set("dkim_key_size", 1024)
+ }
+
+ if _, ok := d.GetOk("force_dkim_authority"); !ok {
+ d.Set("force_dkim_authority", false)
+ }
+ return []*schema.ResourceData{d}, nil
+}
+
+func getIps(ctx context.Context,mg *mailgun.MailgunImpl) ([]mailgun.IPAddress, error){
+ start := time.Now()
+ t := time.Now()
+ ipAddress, err := mg.ListDomainIPS(ctx)
+ for (err != nil && t.Sub(start)< 120 * time.Second) {
+ ipAddress, err = mg.ListDomainIPS(ctx)
+ time.Sleep(5 * time.Second)
+ t = time.Now()
+ }
+ return ipAddress, err
+}