Skip to content
This repository has been archived by the owner on Apr 9, 2021. It is now read-only.

Commit

Permalink
TER-240: Fix typo on supressDiffFeature and suppress empty struct
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordan Caussat committed Apr 3, 2018
1 parent 0b82d88 commit bda3178
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions ghost/resource_ghost_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ func resourceGhostApp() *schema.Resource {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.ValidateJsonString,
DiffSuppressFunc: SuppressDiffFeatureParameter(),
DiffSuppressFunc: SuppressDiffFeatureParameters(),
},
},
},
Expand Down Expand Up @@ -806,15 +806,19 @@ func flattenGhostAppFeatures(features *[]ghost.Feature) []interface{} {
return featureList
}

func SuppressDiffFeatureParameter() schema.SchemaDiffSuppressFunc {
func SuppressDiffFeatureParameters() schema.SchemaDiffSuppressFunc {
return func(k, old, new string, d *schema.ResourceData) bool {
var jsonDoc interface{}

if err := json.Unmarshal([]byte(new), &jsonDoc); err != nil {
log.Printf("Error loading feature paramaters json: %v", err)
}

return fmt.Sprintf("%v", jsonDoc) == old
newJsonParameter := fmt.Sprintf("%v", jsonDoc)

// If the new parameters structure is equivalent to the old one or is empty,
// ignores the diff during plan
return newJsonParameter == old || old == "map[]"
}
}

Expand Down

0 comments on commit bda3178

Please sign in to comment.