Slice of Strings Diff

Hi

I work on one of the Terraform AWS provider resources (aws_workspaces_directory) and need to calculate added and removed elements for the string slice attribute. Does provider already have some func for this or should I add my own? What is the regular location for this helper funcs in the codebase?

"ip_group_ids": {
	Type:     schema.TypeSet,
	Elem:     &schema.Schema{Type: schema.TypeString},
	Optional: true,
},
...
if d.HasChange("ip_group_ids") {
	o, n := d.GetChange("ip_group_ids")
	// Need to calculate diff
	// added := ...
	// removed := ...

	_, err := conn.AssociateIpGroups(&workspaces.AssociateIpGroupsInput{
		DirectoryId: aws.String(d.Id()),
		GroupIds:    added,
	})
		   ...
	_, err := conn. DisassociateIpGroups(&workspaces. DisassociateIpGroupsInput{
		DirectoryId: aws.String(d.Id()),
		GroupIds:    removed,
	})
}

As far as this is Set (not List) it’s easy to achive with Difference() func:

if d.HasChange("ip_group_ids") {
	o, n := d.GetChange("ip_group_ids")
	old := o.(*schema.Set)
	new := n.(*schema.Set)
	added := new.Difference(old)
	removed := old.Difference(new)
...

Hi @Tensho,

I suggest adding this functionality to the Plugin SDK - https://github.com/hashicorp/terraform-plugin-sdk - maybe in the helper/structure package?