diffutils

package
v2.8.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 21, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SuppressAWSParameterGroupDiff

func SuppressAWSParameterGroupDiff(r *config.Resource, diff *terraform.InstanceDiff, s *terraform.InstanceState) (*terraform.InstanceDiff, error)

SuppressAWSParameterGroupDiff suppresses diff for AWS DB parameter group diff when the diff is only on `ApplyMethod` causing perpetual diff. See https://github.com/hashicorp/terraform-provider-aws/blob/v6.55.0/website/docs/r/db_parameter_group.html.markdown#problematic-plan-changes

func SuppressComputedOnlySetRehash

func SuppressComputedOnlySetRehash(r *config.Resource, diff *terraform.InstanceDiff, s *terraform.InstanceState, fields ...string) (*terraform.InstanceDiff, error)

SuppressComputedOnlySetRehash suppresses the perpetual diff a TypeSet block produces when its elements are re-keyed only because the desired configuration leaves an Optional+Computed attribute of an element unset.

A set element's identity is a hash of its content, so an Optional+Computed attribute that the external API fills in - an ARN, a generated ID, a server-side default - makes the observed element hash differently from the element the configuration produces. The plugin SDK can only express that as a removal of one element plus an addition of another, and no apply can settle it: the next observation re-populates the attribute and the diff comes back. Terraform itself does not hit this, because Terraform core merges prior values into null Optional+Computed attributes (objchange.ProposedNew) before the legacy differ ever runs; upjet calls the differ directly with the desired configuration as-is, so the merge never happens.

This function performs the equivalent correlation after the fact: for each named field it pairs every desired element with a distinct observed element that could have produced it - equal in every attribute the configuration actually specifies, differing only where the configuration leaves an Optional+Computed attribute at its zero value - and drops the field's attributes from the diff when, and only when, every element pairs up.

It deliberately does not suppress:

  • element additions or removals, i.e. a differing element count. An API that returns more set elements than the configuration declares is a separate problem, and one that plain Terraform reports too. The configuration has to declare them (or drop the block entirely).
  • a change to any attribute the configuration does specify, including one that is Optional+Computed.
  • a change nested inside a non-Optional+Computed sub-block. Nested content is compared exactly, so such a difference blocks the pairing and the diff survives. Conservative by design: it errs towards reporting drift.

Known limitation: the plugin SDK cannot distinguish "unset" from "set to the zero value" in a diff, so a configuration that deliberately sets an Optional+Computed attribute to "", 0 or false is read as leaving it unset, and a change to that attribute alone is suppressed. This is the same conflation the SDK's own DiffSuppressFunc machinery lives with.

Each field must name a TypeSet whose Elem is a *schema.Resource, addressable the way helper/schema.ResourceData.GetChange addresses it - a top-level attribute, or a dotted path through the collections that contain it, e.g. "policy_details.0.schedule".

A "*" segment stands in for an index that is not known when the resource is configured: the position of an element in a list of arbitrary length, or a set element hash. It is expanded against the keys the calculated diff actually carries, so "policy_details.0.schedule.*.cross_region_copy_rule" addresses the nested set of every schedule the diff mentions, and each expansion is then considered independently - one schedule can be suppressed while another keeps a real change. A path may not end in "*", since it has to name the set itself.

An unknown or unsuitable field is a configuration error and is reported as one.

func SuppressComputedOnlySetRehashFor

func SuppressComputedOnlySetRehashFor(r *config.Resource, fields ...string) config.CustomDiff

SuppressComputedOnlySetRehashFor returns a config.CustomDiff that applies SuppressComputedOnlySetRehash to the given fields, for the common case of a resource that needs no other diff customization:

p.AddResourceConfigurator("aws_appstream_stack", func(r *config.Resource) {
	r.TerraformCustomDiff = diffutils.SuppressComputedOnlySetRehashFor(r, "storage_connectors")
})

Compose SuppressComputedOnlySetRehash directly when the resource already has a TerraformCustomDiff.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL