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.go17
1 files changed, 12 insertions, 5 deletions
diff --git a/mailgun/resource_mailgun_domain.go b/mailgun/resource_mailgun_domain.go
index c195cf0..c6bc775 100644
--- a/mailgun/resource_mailgun_domain.go
+++ b/mailgun/resource_mailgun_domain.go
@@ -99,7 +99,7 @@ func resourceMailgunDomain() *schema.Resource {
99 }, 99 },
100 "password": &schema.Schema{ 100 "password": &schema.Schema{
101 Type: schema.TypeString, 101 Type: schema.TypeString,
102 Required: true, 102 Optional: true,
103 }, 103 },
104 }, 104 },
105 }, 105 },
@@ -314,7 +314,7 @@ func UpdateDomain(d *schema.ResourceData, meta interface{}) error {
314 newCredential := j.(map[string]interface{}) 314 newCredential := j.(map[string]interface{})
315 if oldCredential["login"] == newCredential["login"] { 315 if oldCredential["login"] == newCredential["login"] {
316 found = true 316 found = true
317 if oldCredential["password"] != newCredential["password"] { 317 if oldCredential["password"] != newCredential["password"] && newCredential["password"] != "" {
318 err := mg.ChangeCredentialPassword(ctx, oldCredential["login"].(string), newCredential["password"].(string)) 318 err := mg.ChangeCredentialPassword(ctx, oldCredential["login"].(string), newCredential["password"].(string))
319 if err != nil { 319 if err != nil {
320 return fmt.Errorf("Error updating mailgun credential password: %s", err.Error()) 320 return fmt.Errorf("Error updating mailgun credential password: %s", err.Error())
@@ -377,7 +377,7 @@ func ReadDomain(d *schema.ResourceData, meta interface{}) error {
377 return fmt.Errorf("Error Getting mailgun domain Details for %s: Error: %s", d.Id(), err) 377 return fmt.Errorf("Error Getting mailgun domain Details for %s: Error: %s", d.Id(), err)
378 } 378 }
379 379
380 d.Set("created_at", domainResponse.Domain.CreatedAt) 380 d.Set("created_at", domainResponse.Domain.CreatedAt.String())
381 d.Set("smtd_login", domainResponse.Domain.SMTPLogin) 381 d.Set("smtd_login", domainResponse.Domain.SMTPLogin)
382 d.Set("name", domainResponse.Domain.Name) 382 d.Set("name", domainResponse.Domain.Name)
383 d.Set("smtd_password", domainResponse.Domain.SMTPPassword) 383 d.Set("smtd_password", domainResponse.Domain.SMTPPassword)
@@ -444,12 +444,19 @@ func ReadDomain(d *schema.ResourceData, meta interface{}) error {
444 } 444 }
445 445
446 credentials := make([]map[string]interface{}, len(credentialsResponse)) 446 credentials := make([]map[string]interface{}, len(credentialsResponse))
447 credentialsConf := d.Get("credentials").([]interface{})
447 for i, r := range credentialsResponse { 448 for i, r := range credentialsResponse {
448 credentials[i] = make(map[string]interface{}) 449 credentials[i] = make(map[string]interface{})
449 credentials[i]["created_at"] = r.CreatedAt 450 credentials[i]["created_at"] = r.CreatedAt.String()
450 credentials[i]["login"] = r.Login 451 credentials[i]["login"] = r.Login
451 credentials[i]["password"] = r.Password 452 for _, c:= range credentialsConf {
453 conf:=c.(map[string]interface{})
454 if conf["login"] == credentials[i]["login"] {
455 credentials[i]["password"] = conf["password"]
456 }
457 }
452 } 458 }
459
453 d.Set("credentials", credentials) 460 d.Set("credentials", credentials)
454 461
455 d.SetId(domainName) 462 d.SetId(domainName)