in terraformutils/walk.go [85:131]
func walkAndOverride(pathSegments []string, oldValue, newValue string, data interface{}) {
val := reflect.ValueOf(data)
switch {
case isArray(val.Interface()):
for i := 0; i < val.Len(); i++ {
arrayValue := val.Index(i).Interface()
walkAndOverride(pathSegments, oldValue, newValue, arrayValue)
}
case len(pathSegments) == 1:
if val.Kind() == reflect.Map {
for _, e := range val.MapKeys() {
v := val.MapIndex(e)
if e.String() == pathSegments[0] {
switch {
case isArray(v.Interface()):
valss := v.Interface().([]interface{})
for idx, currentValue := range valss {
curValString, ok := currentValue.(string)
if ok && oldValue == curValString {
valss[idx] = newValue
}
if !ok {
fmt.Printf("Warning: expected string at path: %s, but found: %+v\n", e.String(), currentValue)
}
}
case isStringArray(v.Interface()):
valss := v.Interface().([]string)
for idx, currentValue := range valss {
if oldValue == currentValue {
valss[idx] = newValue
}
}
case oldValue == fmt.Sprint(v.Interface()):
val.Interface().(map[string]interface{})[pathSegments[0]] = newValue
}
}
}
}
case val.Kind() == reflect.Map:
for _, e := range val.MapKeys() {
v := val.MapIndex(e)
if e.String() == pathSegments[0] {
walkAndOverride(pathSegments[1:], oldValue, newValue, v.Interface())
}
}
}
}