diff options
author | Alexandre Garand <alexandre.garand@fretlink.com> | 2019-08-02 11:32:16 +0200 |
---|---|---|
committer | Alexandre Garand <alexandre.garand@fretlink.com> | 2019-08-02 11:32:16 +0200 |
commit | 05fbf6137af57797ad3be7bdd548516fb954e93a (patch) | |
tree | 6ef69c806540b8198aff7f09e5341b56e5238c12 /mailgun/resource_mailgun_domain.go | |
parent | 9d6df78b1174819ed7660295aa42d7fa9c3e647c (diff) | |
download | terraform-provider-mailgun-05fbf6137af57797ad3be7bdd548516fb954e93a.tar.gz terraform-provider-mailgun-05fbf6137af57797ad3be7bdd548516fb954e93a.tar.zst terraform-provider-mailgun-05fbf6137af57797ad3be7bdd548516fb954e93a.zip |
fix credentials and date
Diffstat (limited to 'mailgun/resource_mailgun_domain.go')
-rw-r--r-- | mailgun/resource_mailgun_domain.go | 17 |
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) |