Skip to content

Commit

Permalink
use new TransformPropertyValueDirectional walker
Browse files Browse the repository at this point in the history
  • Loading branch information
VenelinMartinov committed Dec 18, 2024
1 parent e09c20b commit 7b8db7c
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions pkg/tfbridge/property_path.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,19 @@ func isPlanCompatibleWithInputs(
ps map[string]*info.Schema,
) bool {
abortErr := errors.New("abort")
visitor := func(subpath resource.PropertyPath, planSubVal resource.PropertyValue) (resource.PropertyValue, error) {
visitor := func(
subpath resource.PropertyPath, planSubVal resource.PropertyValue, entering bool,
) (resource.PropertyValue, error) {
if !entering {
return planSubVal, nil
}

// Do not compare and do not descend into internal properties.
{
lastPathStep := subpath[len(subpath)-1]
if stepStr, ok := lastPathStep.(string); ok {
if resource.IsInternalPropertyKey(resource.PropertyKey(stepStr)) {
return planSubVal, propertyvalue.LimitDescentError{}
return planSubVal, propertyvalue.SkipChildrenError{}
}
}
}
Expand Down Expand Up @@ -176,7 +182,7 @@ func isPlanCompatibleWithInputs(
if tfs.Type() == shim.TypeSet {
// TODO: more sophisticated comparison of nested sets
if planSubVal.DeepEquals(inputsSubVal) {
return planSubVal, propertyvalue.LimitDescentError{}
return planSubVal, propertyvalue.SkipChildrenError{}
}
return resource.NewNullProperty(), abortErr
}
Expand All @@ -187,7 +193,7 @@ func isPlanCompatibleWithInputs(

return resource.NewNullProperty(), abortErr
}
_, err := propertyvalue.TransformPropertyValueLimitDescent(
_, err := propertyvalue.TransformPropertyValueDirectional(
resource.PropertyPath(path),
visitor,
plan,
Expand All @@ -207,13 +213,18 @@ func isInputCompatibleWithPlan(
ps map[string]*info.Schema,
) bool {
abortErr := errors.New("abort")
visitor := func(subpath resource.PropertyPath, inputsSubVal resource.PropertyValue) (resource.PropertyValue, error) {
visitor := func(
subpath resource.PropertyPath, inputsSubVal resource.PropertyValue, entering bool,
) (resource.PropertyValue, error) {
if !entering {
return inputsSubVal, nil
}
// Do not compare and do not descend into internal properties.
{
lastPathStep := subpath[len(subpath)-1]
if stepStr, ok := lastPathStep.(string); ok {
if resource.IsInternalPropertyKey(resource.PropertyKey(stepStr)) {
return inputsSubVal, propertyvalue.LimitDescentError{}
return inputsSubVal, propertyvalue.SkipChildrenError{}
}
}
}
Expand Down Expand Up @@ -247,7 +258,7 @@ func isInputCompatibleWithPlan(
if tfs.Type() == shim.TypeSet {
// TODO: more sophisticated comparison of nested sets
if inputsSubVal.DeepEquals(planSubVal) {
return inputsSubVal, propertyvalue.LimitDescentError{}
return inputsSubVal, propertyvalue.SkipChildrenError{}
}
return resource.NewNullProperty(), abortErr
}
Expand All @@ -258,7 +269,7 @@ func isInputCompatibleWithPlan(

return resource.NewNullProperty(), abortErr
}
_, err := propertyvalue.TransformPropertyValueLimitDescent(
_, err := propertyvalue.TransformPropertyValueDirectional(
resource.PropertyPath(path),
visitor,
inputs,
Expand Down

0 comments on commit 7b8db7c

Please sign in to comment.