From 229c2734b4a559c1d7d6dccba407aa25261f6cea Mon Sep 17 00:00:00 2001 From: Erhan Cagirici Date: Thu, 2 Nov 2023 17:01:46 +0300 Subject: [PATCH] change TF CustomDiff func signature to accept state and config Signed-off-by: Alper Rifat Ulucinar --- pkg/config/resource.go | 2 +- pkg/controller/external_nofork.go | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/pkg/config/resource.go b/pkg/config/resource.go index 7e106af8..876ec6f5 100644 --- a/pkg/config/resource.go +++ b/pkg/config/resource.go @@ -350,7 +350,7 @@ func (r *Resource) ShouldUseNoForkClient() bool { // CustomDiff customizes the computed Terraform InstanceDiff. This can be used // in cases where, for example, changes in a certain argument should just be // dismissed. The new InstanceDiff is returned along with any errors. -type CustomDiff func(diff *terraform.InstanceDiff) (*terraform.InstanceDiff, error) +type CustomDiff func(diff *terraform.InstanceDiff, state *terraform.InstanceState, config *terraform.ResourceConfig) (*terraform.InstanceDiff, error) // ConfigurationInjector is a function that injects Terraform configuration // values from the specified managed resource into the specified configuration diff --git a/pkg/controller/external_nofork.go b/pkg/controller/external_nofork.go index 2484d8e9..bb559d40 100644 --- a/pkg/controller/external_nofork.go +++ b/pkg/controller/external_nofork.go @@ -340,12 +340,13 @@ func filterInitExclusiveDiffs(tr resource.Terraformed, instanceDiff *tf.Instance } func (n *noForkExternal) getResourceDataDiff(tr resource.Terraformed, ctx context.Context, s *tf.InstanceState, resourceExists bool) (*tf.InstanceDiff, error) { - instanceDiff, err := schema.InternalMap(n.resourceSchema.Schema).Diff(ctx, s, tf.NewResourceConfigRaw(n.params), nil, n.ts.Meta, false) + resourceConfig := tf.NewResourceConfigRaw(n.params) + instanceDiff, err := schema.InternalMap(n.resourceSchema.Schema).Diff(ctx, s, resourceConfig, nil, n.ts.Meta, false) if err != nil { return nil, errors.Wrap(err, "failed to get *terraform.InstanceDiff") } if n.config.TerraformCustomDiff != nil { - instanceDiff, err = n.config.TerraformCustomDiff(instanceDiff) + instanceDiff, err = n.config.TerraformCustomDiff(instanceDiff, s, resourceConfig) if err != nil { return nil, errors.Wrap(err, "failed to compute the customized terraform.InstanceDiff") }