TypeSet with computed attributes alway returns dirty plan

I’m using terraform-plugin-sdk to write a provider and it has a TypeSet which contains computed attributes (which also contain computed nested attributes).

"metric_fields": {
			Type:     schema.TypeSet,
			Optional: true,
			Elem: &schema.Resource{
				Schema: map[string]*schema.Schema{
					"aggregations": {
						Type:     schema.TypeList,
						MaxItems: 1,
						Optional: true,
						Computed: true,
						Elem: &schema.Resource{
							Schema: map[string]*schema.Schema{
                                                        ....
					},
				},
			},
		},

After applying, the plan phase always returns not empty.
when I change it from TypeSet to TypeList It doesn’t seem to be reproduced.

What is the best practice to handle this issue?

Hi @OrNovo,

I would first make sure you are using the latest SDK and Terraform cli versions. I don’t know what the missing section of schema is, or what the plan is showing as changed, but the reason is probably something not set correctly during apply, which is being reverted during the next plan. You may be able to better determine what is happening by looking for warnings about the resource in the core logs, both when using the set type, and a list.

The legacy SDK can’t correctly handle nested types like this in many cases, so if you are working on a new provider, you may want to look into using the Plugin Framework instead.

Thanks for answering!

Hi @jbardin .
using CustomizeDiff can help with that maybe?

It’s possible that CustomizeDiff might be part of a solution, but I can’t say without seeing the entire problem. If you can’t move away from the legacy SDK yet, any warnings in the core logs referring to that resource would be a good place to start investigating. If there are no warnings, then the plan+apply were at least valid, and the changes shown in the next plan should indicate what the provider needs to do to converge on a stable state,

1 Like

Just to plug some recently written docs: https://developer.hashicorp.com/terraform/plugin/sdkv2/resources/data-consistency-errors#finding-data-consistency-errors

This should help you determine if what you have written follows Terraform’s data consistency rules.