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 19, 2024
1 parent 48c9929 commit 42ba75a
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 @@ -254,13 +254,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 @@ -293,7 +299,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 @@ -304,7 +310,7 @@ func isPlanCompatibleWithInputs(

return resource.NewNullProperty(), abortErr
}
_, err := propertyvalue.TransformPropertyValueLimitDescent(
_, err := propertyvalue.TransformPropertyValueDirectional(
resource.PropertyPath(path),
visitor,
plan,
Expand All @@ -324,13 +330,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 @@ -364,7 +375,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 @@ -375,7 +386,7 @@ func isInputCompatibleWithPlan(

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

0 comments on commit 42ba75a

Please sign in to comment.