From: Alexandre Garand Date: Fri, 2 Aug 2019 09:32:16 +0000 (+0200) Subject: fix credentials and date X-Git-Tag: v0.1.0~1^2~1 X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=05fbf6137af57797ad3be7bdd548516fb954e93a;p=github%2Ffretlink%2Fterraform-provider-mailgun.git fix credentials and date --- 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)