Skip to content

Commit

Permalink
change TF CustomDiff func signature to accept state and config
Browse files Browse the repository at this point in the history
Signed-off-by: Alper Rifat Ulucinar <[email protected]>
  • Loading branch information
erhancagirici authored and ulucinar committed Nov 2, 2023
1 parent e4d7b4e commit 229c273
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pkg/config/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions pkg/controller/external_nofork.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down

0 comments on commit 229c273

Please sign in to comment.