From 618ae2b509f8311ba5b0af6c4aca5ec614ccbebc Mon Sep 17 00:00:00 2001 From: SamuZad Date: Sat, 11 May 2024 16:55:21 +0100 Subject: [PATCH] sort aliases and implement diffsuppress --- internal/provider/resource_user.go | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/internal/provider/resource_user.go b/internal/provider/resource_user.go index db96f014..4827df2e 100644 --- a/internal/provider/resource_user.go +++ b/internal/provider/resource_user.go @@ -10,6 +10,7 @@ import ( "log" "net/mail" "reflect" + "sort" "strconv" "time" @@ -47,6 +48,18 @@ func diffSuppressEmails(k, old, new string, d *schema.ResourceData) bool { return reflect.DeepEqual(subsetEmails, configEmails.([]interface{})) } +func diffSuppressAliases(k, old, new string, d *schema.ResourceData) bool { + stateAliases, configAliases := d.GetChange("aliases") + + stateList := listOfInterfacestoStrings(stateAliases.([]interface{})) + configList := listOfInterfacestoStrings(configAliases.([]interface{})) + + sort.Strings(stateList) + sort.Strings(configList) + + return reflect.DeepEqual(stateList, configList) +} + func diffSuppressCustomSchemas(_, _, _ string, d *schema.ResourceData) bool { old, new := d.GetChange("custom_schemas") customSchemasOld := old.([]interface{}) @@ -352,9 +365,10 @@ func resourceUser() *schema.Resource { }, }, "aliases": { - Description: "asps.list of the user's alias email addresses.", - Type: schema.TypeList, - Optional: true, + Description: "asps.list of the user's alias email addresses.", + Type: schema.TypeList, + Optional: true, + DiffSuppressFunc: diffSuppressAliases, Elem: &schema.Schema{ Type: schema.TypeString, },