Skip to content

Commit

Permalink
Configuration Resource Details update (#39)
Browse files Browse the repository at this point in the history
* Only set details if details is originally set by user

Signed-off-by: Cari Albritton <carialbritton1@gmail.com>

* Update to check for details being set before setting to nil

Signed-off-by: Cari Albritton <carialbritton1@gmail.com>
  • Loading branch information
calbritt authored Jun 9, 2022
1 parent 3ecbe73 commit 7bed0f1
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions kaleido/resource_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ package kaleido
import (
"encoding/json"
"fmt"
"github.com/hashicorp/terraform-plugin-sdk/helper/customdiff"
"time"

"github.com/hashicorp/terraform-plugin-sdk/helper/customdiff"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
kaleido "github.com/kaleido-io/kaleido-sdk-go/kaleido"
)
Expand Down Expand Up @@ -125,7 +126,7 @@ func resourceConfigurationCreate(d *schema.ResourceData, meta interface{}) error
d.SetId(configuration.ID)
d.Set("last_updated", time.Now().UnixNano())

return nil
return resourceConfigurationRead(d, meta)
}

func resourceConfigurationUpdate(d *schema.ResourceData, meta interface{}) error {
Expand Down Expand Up @@ -158,7 +159,7 @@ func resourceConfigurationUpdate(d *schema.ResourceData, meta interface{}) error

d.Set("last_updated", time.Now().UnixNano())

return nil
return resourceConfigurationRead(d, meta)
}

func resourceConfigurationRead(d *schema.ResourceData, meta interface{}) error {
Expand Down Expand Up @@ -187,7 +188,6 @@ func resourceConfigurationRead(d *schema.ResourceData, meta interface{}) error {

d.Set("name", configuration.Name)
d.Set("type", configuration.Type)
d.Set("details", configuration.Details)

// if details_json is set, we need it to reflect the state for diffing
detailsJSON := d.Get("details_json").(string)
Expand All @@ -197,9 +197,15 @@ func resourceConfigurationRead(d *schema.ResourceData, meta interface{}) error {
msg := "Could not parse configuration details to JSON for config %s in consortium %s in environment %s with status %d: %s"
return fmt.Errorf(msg, configurationID, consortiumID, environmentID, status, res.String())
}
// if details is also set, set to nil and use details_json only
d.Set("details_json", string(detailsJSON))
details := d.Get("details").(map[string]interface{})
if len(details) != 0 {
d.Set("details", nil)
}
} else {
d.Set("details", configuration.Details)
}

return nil
}

Expand Down

0 comments on commit 7bed0f1

Please sign in to comment.