Provider Schema TypeSet - Detect Changes

Hello,

I’m bulding a new Terraform Provider.
I have the following schema:

"multicast_quota": {
				Type:     schema.TypeSet,
				Optional: true,
				MaxItems: 1,
				ConfigMode: schema.SchemaConfigModeAttr,
				Elem: &schema.Resource{
					Schema: map[string]*schema.Schema{
						"acl_num": {
							Type:        schema.TypeInt,
							Description: "Quota of ACLs.",
							Optional:    true,
							ValidateDiagFunc: validation.ToDiagFunc(
								validation.IntBetween(0, 1000),
							),
						},
						"acl_rule_num": {
							Type:        schema.TypeInt,
							Description: "Quota of ACL rules.",
							Optional:    true,
							ValidateDiagFunc: validation.ToDiagFunc(
								validation.IntBetween(0, 3000),
							),
						},
					},
				},
			},

Everytime i change one of attributes from typeset (acl_num or acl_rule_num) the terraform plans show that will remove the set item and create new one. Is Possible doing this with the terraform plan show only the attribute changed (so it’s edit one attribute from type set item and not delete the item and create a new one) ? There is a better way to do it?

  # agilec_tenant.demotenant has been changed
  ~ resource "agilec_tenant" "demotenant" {
      ~ multicast_quota = [
          + {
              + acl_num      = 10
              + acl_rule_num = 12
            },
          - {
              - acl_num      = 10
              - acl_rule_num = 10
            },
        ]
        # (5 unchanged attributes hidden)
    }

Thanks.

Hi @fdmsantos,

Changing a single value within a set can be construed as replacing the entire set. In this case however, only the single value which has changes is being shown, that single value though happens to have multiple attributes and there is no way for Terraform to guess how those two structural values may be correlated (i.e. do they represent different logical values rather than a update of a single value?).

The only way to ensure that the Terraform CLI can correlate the specific values is to use a list rather than a set, since list values are identified by index rather than value alone.

Thanks for the response. I’m changing for TypeList, that supports update in place.

Thanks,
Fábio Santos