From 05fbf6137af57797ad3be7bdd548516fb954e93a Mon Sep 17 00:00:00 2001 From: Alexandre Garand Date: Fri, 2 Aug 2019 11:32:16 +0200 Subject: [PATCH] fix credentials and date --- mailgun/resource_mailgun_domain.go | 17 ++++++++++++----- mailgun/resource_mailgun_route.go | 2 +- 2 files changed, 13 insertions(+), 6 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 { }, "password": &schema.Schema{ Type: schema.TypeString, - Required: true, + Optional: true, }, }, }, @@ -314,7 +314,7 @@ func UpdateDomain(d *schema.ResourceData, meta interface{}) error { newCredential := j.(map[string]interface{}) if oldCredential["login"] == newCredential["login"] { found = true - if oldCredential["password"] != newCredential["password"] { + if oldCredential["password"] != newCredential["password"] && newCredential["password"] != "" { err := mg.ChangeCredentialPassword(ctx, oldCredential["login"].(string), newCredential["password"].(string)) if err != nil { return fmt.Errorf("Error updating mailgun credential password: %s", err.Error()) @@ -377,7 +377,7 @@ func ReadDomain(d *schema.ResourceData, meta interface{}) error { return fmt.Errorf("Error Getting mailgun domain Details for %s: Error: %s", d.Id(), err) } - d.Set("created_at", domainResponse.Domain.CreatedAt) + d.Set("created_at", domainResponse.Domain.CreatedAt.String()) d.Set("smtd_login", domainResponse.Domain.SMTPLogin) d.Set("name", domainResponse.Domain.Name) d.Set("smtd_password", domainResponse.Domain.SMTPPassword) @@ -444,12 +444,19 @@ func ReadDomain(d *schema.ResourceData, meta interface{}) error { } credentials := make([]map[string]interface{}, len(credentialsResponse)) + credentialsConf := d.Get("credentials").([]interface{}) for i, r := range credentialsResponse { credentials[i] = make(map[string]interface{}) - credentials[i]["created_at"] = r.CreatedAt + credentials[i]["created_at"] = r.CreatedAt.String() credentials[i]["login"] = r.Login - credentials[i]["password"] = r.Password + for _, c:= range credentialsConf { + conf:=c.(map[string]interface{}) + if conf["login"] == credentials[i]["login"] { + credentials[i]["password"] = conf["password"] + } + } } + d.Set("credentials", credentials) d.SetId(domainName) diff --git a/mailgun/resource_mailgun_route.go b/mailgun/resource_mailgun_route.go index cf8290f..308da44 100644 --- a/mailgun/resource_mailgun_route.go +++ b/mailgun/resource_mailgun_route.go @@ -123,7 +123,7 @@ func ReadRoute(d *schema.ResourceData, meta interface{}) error { d.Set("description", route.Description) d.Set("expression", route.Expression) d.Set("actions", route.Actions) - d.Set("created_at", route.CreatedAt) + d.Set("created_at", route.CreatedAt.String()) d.Set("route_id", route.Id) d.SetId(route.Id) -- 2.41.0