From 7b8db7c4924a2214f4a74e2ccf460f25d488d0e7 Mon Sep 17 00:00:00 2001 From: Venelin Date: Wed, 18 Dec 2024 16:13:11 +0200 Subject: [PATCH] use new TransformPropertyValueDirectional walker --- pkg/tfbridge/property_path.go | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/pkg/tfbridge/property_path.go b/pkg/tfbridge/property_path.go index 59ae46e18..27402999a 100644 --- a/pkg/tfbridge/property_path.go +++ b/pkg/tfbridge/property_path.go @@ -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{} } } } @@ -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 } @@ -187,7 +193,7 @@ func isPlanCompatibleWithInputs( return resource.NewNullProperty(), abortErr } - _, err := propertyvalue.TransformPropertyValueLimitDescent( + _, err := propertyvalue.TransformPropertyValueDirectional( resource.PropertyPath(path), visitor, plan, @@ -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{} } } } @@ -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 } @@ -258,7 +269,7 @@ func isInputCompatibleWithPlan( return resource.NewNullProperty(), abortErr } - _, err := propertyvalue.TransformPropertyValueLimitDescent( + _, err := propertyvalue.TransformPropertyValueDirectional( resource.PropertyPath(path), visitor, inputs,