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!