]> git.immae.eu Git - github/fretlink/terraform-provider-mailgun.git/commitdiff
fix credentials and date
authorAlexandre Garand <alexandre.garand@fretlink.com>
Fri, 2 Aug 2019 09:32:16 +0000 (11:32 +0200)
committerAlexandre Garand <alexandre.garand@fretlink.com>
Fri, 2 Aug 2019 09:32:16 +0000 (11:32 +0200)
mailgun/resource_mailgun_domain.go
mailgun/resource_mailgun_route.go

index c195cf0010bc1f98615f83b92d3982431a79ee44..c6bc775ad9c133bfb10a8f774c855f19df0e6240 100644 (file)
@@ -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)
index cf8290fecd428b4bd66df3d4bf583c10bdf048fc..308da4425055c61eed4138891a703ace6ff9fd74 100644 (file)
@@ -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)