terraform-plugin-sdk icon indicating copy to clipboard operation
terraform-plugin-sdk copied to clipboard

DiffSupressFunc on TypeLists operates on the `{foo}.#` marker value.

Open toumorokoshi opened this issue 4 years ago • 1 comments

SDK version

2.5.0 (but looks to exist in head as of this issue creation)

Relevant provider source code

See https://github.com/hashicorp/terraform-provider-google/blob/master/google/resource_dns_resource_dns_record_set.go#L91.

Terraform Configuration Files

resource "google_dns_record_set" "resource-recordset" {
  managed_zone = google_dns_managed_zone.parent-zone.name
  name         = "test-record.my-zone.hashicorptest.com."
  type         = "AAAA"
  rrdatas = [
      "7777:7777:7777:7777::",
      "8888:8888:8888:8888::",
  ]
  ttl          = 86400
}

Debug Output

out of plan:

  # google_dns_record_set.resource-recordset will be created
  + resource "google_dns_record_set" "resource-recordset" {
      + id           = (known after apply)
      + managed_zone = "my-zone"
      + name         = "test-record.my-zone.hashicorptest.com."
      + project      = (known after apply)
      + rrdatas      = []
      + ttl          = 86400
      + type         = "AAAA"
    }

Expected Behavior

rrdatas has the list of values added in the schema.

Actual Behavior

A bug is already filed with the provider, but a DiffSuppressFunc which was applied to a TypeList attribute resulted in also operating on the {fieldname}.# marker value used to determine the length of the field. In this case, the DiffSuppressFunc outputted that the diff for that field should be suppressed, effectively eliminating that value in the final diffAttributes.

That marker value for the length is also used to determine the existence of the value at all. So the result is that the whole TypeList value is missing.

I think the right fix would be only running DiffSuppressFunc on the individual elements, rather than the marker {fieldname}.# value.

Steps to Reproduce

See https://github.com/hashicorp/terraform-provider-google/issues/8935.

References

toumorokoshi avatar Apr 16 '21 17:04 toumorokoshi

I recently ran into this as well - specifically the part where suppressing a diff on the # field causes the entire value to be seen as empty when applying the plan, even if there are unsuppressed diffs in the actual values for the fields.

melinath avatar May 24 '24 17:05 melinath