Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions pkg/module/drift/terraform.go
Original file line number Diff line number Diff line change
Expand Up @@ -462,9 +462,9 @@ func isEmptyStringSliceOrMap(val interface{}) bool {

func registerGJsonHelpers() {
if !gjson.ModifierExists("inverse", nil) {
// inverse a boolean
// inverse a boolean (null input returns true)
gjson.AddModifier("inverse", func(body, arg string) string {
if body == "false" {
if body == "false" || body == "" {
return "true"
}
return "false"
Expand All @@ -484,4 +484,26 @@ func registerGJsonHelpers() {
return ""
})
}
if !gjson.ModifierExists("getbool", nil) {
// extract the given arg as key from the given object and expect it to be a boolean. returns false if doesn't exist. returns nil if not an object.
gjson.AddModifier("getbool", func(body, arg string) string {
if body == "" { // nil input
return "false"
}
var v map[string]interface{}
if err := json.Unmarshal([]byte(body), &v); err != nil {
return "" // invalid input
}
b, ok := v[arg]
if !ok {
return "false" // key not in map
}

var bb bool
if bb, ok = b.(bool); !ok {
bb, _ = strconv.ParseBool(fmt.Sprintf("%v", b))
}
return strconv.FormatBool(bb)
})
}
}