diff options
-rw-r--r-- | mailgun/resource_mailgun_domain.go | 9 | ||||
-rw-r--r-- | mailgun/resource_mailgun_domain_test.go | 29 | ||||
-rw-r--r-- | mailgun/resource_mailgun_route_test.go | 23 |
3 files changed, 60 insertions, 1 deletions
diff --git a/mailgun/resource_mailgun_domain.go b/mailgun/resource_mailgun_domain.go index 1fcba83..8ba0704 100644 --- a/mailgun/resource_mailgun_domain.go +++ b/mailgun/resource_mailgun_domain.go | |||
@@ -368,13 +368,20 @@ func ReadDomain(d *schema.ResourceData, meta interface{}) error { | |||
368 | mg := meta.(*mailgun.MailgunImpl) | 368 | mg := meta.(*mailgun.MailgunImpl) |
369 | ctx, cancel := context.WithTimeout(context.Background(), time.Second*30) | 369 | ctx, cancel := context.WithTimeout(context.Background(), time.Second*30) |
370 | defer cancel() | 370 | defer cancel() |
371 | domainName := d.Get("name").(string) | 371 | domainName := d.Id() |
372 | mg = mailgun.NewMailgun(domainName, mg.APIKey()) | 372 | mg = mailgun.NewMailgun(domainName, mg.APIKey()) |
373 | 373 | ||
374 | domainResponse, err := mg.GetDomain(ctx, domainName) | 374 | domainResponse, err := mg.GetDomain(ctx, domainName) |
375 | if err != nil { | 375 | if err != nil { |
376 | return fmt.Errorf("Error Getting mailgun domain Details for %s: Error: %s", d.Id(), err) | 376 | return fmt.Errorf("Error Getting mailgun domain Details for %s: Error: %s", d.Id(), err) |
377 | } | 377 | } |
378 | if _, ok := d.GetOk("dkim_key_size"); !ok { | ||
379 | d.Set("dkim_key_size", 1024) | ||
380 | } | ||
381 | |||
382 | if _, ok := d.GetOk("force_dkim_authority"); !ok { | ||
383 | d.Set("force_dkim_authority", false) | ||
384 | } | ||
378 | 385 | ||
379 | d.Set("created_at", domainResponse.Domain.CreatedAt) | 386 | d.Set("created_at", domainResponse.Domain.CreatedAt) |
380 | d.Set("smtd_login", domainResponse.Domain.SMTPLogin) | 387 | d.Set("smtd_login", domainResponse.Domain.SMTPLogin) |
diff --git a/mailgun/resource_mailgun_domain_test.go b/mailgun/resource_mailgun_domain_test.go index 6096c60..952e013 100644 --- a/mailgun/resource_mailgun_domain_test.go +++ b/mailgun/resource_mailgun_domain_test.go | |||
@@ -105,6 +105,30 @@ func TestAccMailgunDomain_withUpdate(t *testing.T) { | |||
105 | }) | 105 | }) |
106 | } | 106 | } |
107 | 107 | ||
108 | |||
109 | func TestDomain_importBasic(t *testing.T) { | ||
110 | var domain fullDomain | ||
111 | |||
112 | resource.Test(t, resource.TestCase{ | ||
113 | PreCheck: func() { testAccPreCheck(t) }, | ||
114 | Providers: testAccProviders, | ||
115 | CheckDestroy: testAccDomainCheckDestroy(&domain), | ||
116 | Steps: []resource.TestStep{ | ||
117 | { | ||
118 | Config: interpolateTerraformTemplateDomain(testAccDomainConfig_import), | ||
119 | Check: resource.ComposeTestCheckFunc( | ||
120 | testAccDomainCheckExists("mailgun_domain.exemple",&domain), | ||
121 | ), | ||
122 | }, | ||
123 | { | ||
124 | ResourceName: "mailgun_domain.exemple", | ||
125 | ImportState: true, | ||
126 | ImportStateVerify: true, | ||
127 | }, | ||
128 | }, | ||
129 | }) | ||
130 | } | ||
131 | |||
108 | func testAccDomainCheckExists(rn string, domain *fullDomain) resource.TestCheckFunc { | 132 | func testAccDomainCheckExists(rn string, domain *fullDomain) resource.TestCheckFunc { |
109 | return func(s *terraform.State) error { | 133 | return func(s *terraform.State) error { |
110 | rs, ok := s.RootModule().Resources[rn] | 134 | rs, ok := s.RootModule().Resources[rn] |
@@ -226,3 +250,8 @@ resource "mailgun_domain" "exemple" { | |||
226 | 250 | ||
227 | } | 251 | } |
228 | ` | 252 | ` |
253 | const testAccDomainConfig_import = ` | ||
254 | resource "mailgun_domain" "exemple" { | ||
255 | name = "%s" | ||
256 | } | ||
257 | ` | ||
diff --git a/mailgun/resource_mailgun_route_test.go b/mailgun/resource_mailgun_route_test.go index 2d7b221..02d552a 100644 --- a/mailgun/resource_mailgun_route_test.go +++ b/mailgun/resource_mailgun_route_test.go | |||
@@ -57,6 +57,29 @@ func TestAccMailgunRoute_withUpdate(t *testing.T) { | |||
57 | }) | 57 | }) |
58 | } | 58 | } |
59 | 59 | ||
60 | func TestRoute_importBasic(t *testing.T) { | ||
61 | var route mailgun.Route | ||
62 | |||
63 | resource.Test(t, resource.TestCase{ | ||
64 | PreCheck: func() { testAccPreCheck(t) }, | ||
65 | Providers: testAccProviders, | ||
66 | CheckDestroy: testAccRouteCheckDestroy(&route), | ||
67 | Steps: []resource.TestStep{ | ||
68 | { | ||
69 | Config: testAccRouteConfig_basic, | ||
70 | Check: resource.ComposeTestCheckFunc( | ||
71 | testAccRouteCheckExists("mailgun_route.exemple",&route), | ||
72 | ), | ||
73 | }, | ||
74 | { | ||
75 | ResourceName: "mailgun_route.exemple", | ||
76 | ImportState: true, | ||
77 | ImportStateVerify: true, | ||
78 | }, | ||
79 | }, | ||
80 | }) | ||
81 | } | ||
82 | |||
60 | func testAccRouteCheckExists(rn string, route *mailgun.Route) resource.TestCheckFunc { | 83 | func testAccRouteCheckExists(rn string, route *mailgun.Route) resource.TestCheckFunc { |
61 | return func(s *terraform.State) error { | 84 | return func(s *terraform.State) error { |
62 | rs, ok := s.RootModule().Resources[rn] | 85 | rs, ok := s.RootModule().Resources[rn] |