diff options
Diffstat (limited to 'mailgun/resource_mailgun_domain.go')
-rw-r--r-- | mailgun/resource_mailgun_domain.go | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/mailgun/resource_mailgun_domain.go b/mailgun/resource_mailgun_domain.go index c195cf0..48f3a1a 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()) |
@@ -376,11 +376,10 @@ func ReadDomain(d *schema.ResourceData, meta interface{}) error { | |||
376 | if err != nil { | 376 | if err != nil { |
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 | d.Set("created_at", domainResponse.Domain.CreatedAt.String()) | |
380 | d.Set("created_at", domainResponse.Domain.CreatedAt) | 380 | d.Set("smtp_login", domainResponse.Domain.SMTPLogin) |
381 | d.Set("smtd_login", domainResponse.Domain.SMTPLogin) | ||
382 | d.Set("name", domainResponse.Domain.Name) | 381 | d.Set("name", domainResponse.Domain.Name) |
383 | d.Set("smtd_password", domainResponse.Domain.SMTPPassword) | 382 | d.Set("smtp_password", domainResponse.Domain.SMTPPassword) |
384 | d.Set("wildcard", domainResponse.Domain.Wildcard) | 383 | d.Set("wildcard", domainResponse.Domain.Wildcard) |
385 | d.Set("spam_action", domainResponse.Domain.SpamAction) | 384 | d.Set("spam_action", domainResponse.Domain.SpamAction) |
386 | d.Set("state", domainResponse.Domain.State) | 385 | d.Set("state", domainResponse.Domain.State) |
@@ -444,12 +443,19 @@ func ReadDomain(d *schema.ResourceData, meta interface{}) error { | |||
444 | } | 443 | } |
445 | 444 | ||
446 | credentials := make([]map[string]interface{}, len(credentialsResponse)) | 445 | credentials := make([]map[string]interface{}, len(credentialsResponse)) |
446 | credentialsConf := d.Get("credentials").([]interface{}) | ||
447 | for i, r := range credentialsResponse { | 447 | for i, r := range credentialsResponse { |
448 | credentials[i] = make(map[string]interface{}) | 448 | credentials[i] = make(map[string]interface{}) |
449 | credentials[i]["created_at"] = r.CreatedAt | 449 | credentials[i]["created_at"] = r.CreatedAt.String() |
450 | credentials[i]["login"] = r.Login | 450 | credentials[i]["login"] = r.Login |
451 | credentials[i]["password"] = r.Password | 451 | for _, c:= range credentialsConf { |
452 | conf:=c.(map[string]interface{}) | ||
453 | if conf["login"] == credentials[i]["login"] { | ||
454 | credentials[i]["password"] = conf["password"] | ||
455 | } | ||
456 | } | ||
452 | } | 457 | } |
458 | |||
453 | d.Set("credentials", credentials) | 459 | d.Set("credentials", credentials) |
454 | 460 | ||
455 | d.SetId(domainName) | 461 | d.SetId(domainName) |