in helper/utils.go [154:193]
func ToHclSearchReplace(input interface{}, search []string, replacement []string) (string, bool) {
found := false
switch value := input.(type) {
case []interface{}:
if len(value) == 0 {
return "[]", false
}
res := make([]string, 0)
for _, element := range value {
config, ok := ToHclSearchReplace(element, search, replacement)
found = found || ok
res = append(res, config)
}
return fmt.Sprintf("[\n%s\n]", strings.Join(res, ",\n")), found
case map[string]interface{}:
if len(value) == 0 {
return "{}", found
}
attrs := make([]string, 0)
for k, v := range value {
if v == nil {
attrs = append(attrs, fmt.Sprintf("%s = null", quotedKey(k)))
continue
}
config, ok := ToHclSearchReplace(v, search, replacement)
found = found || ok
attrs = append(attrs, fmt.Sprintf("%s = %s", quotedKey(k), config))
}
return fmt.Sprintf("{\n%s\n}", strings.Join(attrs, "\n")), found
case string:
for i := range search {
if search[i] == value {
return replacement[i], true
}
}
return fmt.Sprintf(`"%s"`, strings.ReplaceAll(value, "\"", "\\\"")), false
default:
return fmt.Sprintf("%v", value), false
}
}