From 5568f2b93a7c36649edb4d0126ff73dbc306017d Mon Sep 17 00:00:00 2001 From: GlennChia Date: Sat, 6 Aug 2022 04:00:32 +0000 Subject: [PATCH 1/9] refactor(connect): update to quick_connect_ids associate new elements and disassoicate only those removed --- internal/service/connect/queue.go | 54 ++++++++++++++++--------------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/internal/service/connect/queue.go b/internal/service/connect/queue.go index f9937ca72cb..a0ad38deb74 100644 --- a/internal/service/connect/queue.go +++ b/internal/service/connect/queue.go @@ -93,13 +93,6 @@ func ResourceQueue() *schema.Resource { Type: schema.TypeString, }, }, - "quick_connect_ids_associated": { - Type: schema.TypeSet, - Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - }, "status": { Type: schema.TypeString, Optional: true, @@ -216,7 +209,6 @@ func resourceQueueRead(ctx context.Context, d *schema.ResourceData, meta interfa } d.Set("quick_connect_ids", flex.FlattenStringSet(quickConnectIds)) - d.Set("quick_connect_ids_associated", flex.FlattenStringSet(quickConnectIds)) tags := KeyValueTags(ctx, resp.Queue.Tags).IgnoreAWS().IgnoreConfig(ignoreTagsConfig) @@ -322,29 +314,39 @@ func resourceQueueUpdate(ctx context.Context, d *schema.ResourceData, meta inter // updates to quick_connect_ids if d.HasChange("quick_connect_ids") { - // first disassociate all existing quick connects - if v, ok := d.GetOk("quick_connect_ids_associated"); ok && v.(*schema.Set).Len() > 0 { - input := &connect.DisassociateQueueQuickConnectsInput{ - InstanceId: aws.String(instanceID), - QueueId: aws.String(queueID), - } - input.QuickConnectIds = flex.ExpandStringSet(v.(*schema.Set)) - _, err = conn.DisassociateQueueQuickConnectsWithContext(ctx, input) + o, n := d.GetChange("quick_connect_ids") + + if o == nil { + o = new(schema.Set) + } + if n == nil { + n = new(schema.Set) + } + + os := o.(*schema.Set) + ns := n.(*schema.Set) + quickConnectIdsUpdateAdd := ns.Difference(os) + quickConnectIdsUpdateRemove := os.Difference(ns) + + if len(quickConnectIdsUpdateAdd.List()) > 0 { + _, err = conn.AssociateQueueQuickConnectsWithContext(ctx, &connect.AssociateQueueQuickConnectsInput{ + InstanceId: aws.String(instanceID), + QueueId: aws.String(queueID), + QuickConnectIds: flex.ExpandStringSet(quickConnectIdsUpdateAdd), + }) if err != nil { - return diag.FromErr(fmt.Errorf("updating Queues Quick Connect IDs, specifically disassociating quick connects from queue (%s): %w", d.Id(), err)) + return diag.FromErr(fmt.Errorf("updating Queues Quick Connect IDs, specifically associating quick connects to queue (%s): %w", d.Id(), err)) } } - // re-associate the quick connects - if v, ok := d.GetOk("quick_connect_ids"); ok && v.(*schema.Set).Len() > 0 { - input := &connect.AssociateQueueQuickConnectsInput{ - InstanceId: aws.String(instanceID), - QueueId: aws.String(queueID), - } - input.QuickConnectIds = flex.ExpandStringSet(v.(*schema.Set)) - _, err = conn.AssociateQueueQuickConnectsWithContext(ctx, input) + if len(quickConnectIdsUpdateRemove.List()) > 0 { + _, err = conn.DisassociateQueueQuickConnectsWithContext(ctx, &connect.DisassociateQueueQuickConnectsInput{ + InstanceId: aws.String(instanceID), + QueueId: aws.String(queueID), + QuickConnectIds: flex.ExpandStringSet(quickConnectIdsUpdateRemove), + }) if err != nil { - return diag.FromErr(fmt.Errorf("updating Queues Quick Connect IDs, specifically associating quick connects to queue (%s): %w", d.Id(), err)) + return diag.FromErr(fmt.Errorf("updating Queues Quick Connect IDs, specifically disassociating quick connects from queue (%s): %w", d.Id(), err)) } } } From 16ff76924efad29ed3d7012a690fe554945c9526 Mon Sep 17 00:00:00 2001 From: GlennChia Date: Sat, 6 Aug 2022 04:06:08 +0000 Subject: [PATCH 2/9] refactor(connect): update to queue_configs disassociate updated elements and assoicate only those updated --- internal/service/connect/routing_profile.go | 80 +++++++-------------- 1 file changed, 27 insertions(+), 53 deletions(-) diff --git a/internal/service/connect/routing_profile.go b/internal/service/connect/routing_profile.go index 740d8ab1d7e..a3ef6f993a2 100644 --- a/internal/service/connect/routing_profile.go +++ b/internal/service/connect/routing_profile.go @@ -109,39 +109,6 @@ func ResourceRoutingProfile() *schema.Resource { }, }, }, - // used to update the queue configs by first disassociating the existing set and re-associating them - "queue_configs_associated": { - Type: schema.TypeSet, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "channel": { - Type: schema.TypeString, - Computed: true, - }, - "delay": { - Type: schema.TypeInt, - Computed: true, - }, - "priority": { - Type: schema.TypeInt, - Computed: true, - }, - "queue_arn": { - Type: schema.TypeString, - Computed: true, - }, - "queue_id": { - Type: schema.TypeString, - Computed: true, - }, - "queue_name": { - Type: schema.TypeString, - Computed: true, - }, - }, - }, - }, "routing_profile_id": { Type: schema.TypeString, Computed: true, @@ -244,7 +211,6 @@ func resourceRoutingProfileRead(ctx context.Context, d *schema.ResourceData, met } d.Set("queue_configs", queueConfigs) - d.Set("queue_configs_associated", queueConfigs) tags := KeyValueTags(ctx, routingProfile.Tags).IgnoreAWS().IgnoreConfig(ignoreTagsConfig) @@ -328,31 +294,39 @@ func resourceRoutingProfileUpdate(ctx context.Context, d *schema.ResourceData, m // UpdateRoutingProfileQueues - Updates the properties associated with a set of queues for a routing profile. // since the update only updates the existing queues that are associated, we will instead disassociate (if there are any queues) // and then associate all the queues again to ensure new queues can be added and unused queues can be removed - inputQueueAssociate := &connect.AssociateRoutingProfileQueuesInput{ - InstanceId: aws.String(instanceID), - RoutingProfileId: aws.String(routingProfileID), - } + if d.HasChange("queue_configs") { + o, n := d.GetChange("queue_configs") - inputQueueDisassociate := &connect.DisassociateRoutingProfileQueuesInput{ - InstanceId: aws.String(instanceID), - RoutingProfileId: aws.String(routingProfileID), - } + if o == nil { + o = new(schema.Set) + } + if n == nil { + n = new(schema.Set) + } - if d.HasChange("queue_configs") { - // first disassociate all existing queues - currentAssociatedQueueReferences := expandRoutingProfileQueueReferences(d.Get("queue_configs_associated").(*schema.Set).List()) - if currentAssociatedQueueReferences != nil { - inputQueueDisassociate.QueueReferences = currentAssociatedQueueReferences - _, err = conn.DisassociateRoutingProfileQueuesWithContext(ctx, inputQueueDisassociate) + os := o.(*schema.Set) + ns := n.(*schema.Set) + queueConfigsUpdateAdd := ns.Difference(os).List() + queueConfigsUpdateRemove := os.Difference(ns).List() + + // disassociate first since Queue and channel type combination cannot be duplicated + if len(queueConfigsUpdateRemove) > 0 { + _, err = conn.DisassociateRoutingProfileQueuesWithContext(ctx, &connect.DisassociateRoutingProfileQueuesInput{ + InstanceId: aws.String(instanceID), + QueueReferences: expandRoutingProfileQueueReferences(queueConfigsUpdateRemove), + RoutingProfileId: aws.String(routingProfileID), + }) if err != nil { return diag.FromErr(fmt.Errorf("updating RoutingProfile Queue Configs, specifically disassociating queues from routing profile (%s): %w", d.Id(), err)) } } - // re-associate the queues - updatedQueueConfigs := expandRoutingProfileQueueConfigs(d.Get("queue_configs").(*schema.Set).List()) - if updatedQueueConfigs != nil { - inputQueueAssociate.QueueConfigs = updatedQueueConfigs - _, err = conn.AssociateRoutingProfileQueuesWithContext(ctx, inputQueueAssociate) + + if len(queueConfigsUpdateAdd) > 0 { + _, err = conn.AssociateRoutingProfileQueuesWithContext(ctx, &connect.AssociateRoutingProfileQueuesInput{ + InstanceId: aws.String(instanceID), + QueueConfigs: expandRoutingProfileQueueConfigs(queueConfigsUpdateAdd), + RoutingProfileId: aws.String(routingProfileID), + }) if err != nil { return diag.FromErr(fmt.Errorf("updating RoutingProfile Queue Configs, specifically associating queues to routing profile (%s): %w", d.Id(), err)) } From a73fdc0375745a0c9083eee7bd81e75330f05473 Mon Sep 17 00:00:00 2001 From: GlennChia Date: Sat, 6 Aug 2022 06:52:33 +0000 Subject: [PATCH 3/9] chore(connect): routing profile update comment --- internal/service/connect/routing_profile.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/service/connect/routing_profile.go b/internal/service/connect/routing_profile.go index a3ef6f993a2..2008fd9061e 100644 --- a/internal/service/connect/routing_profile.go +++ b/internal/service/connect/routing_profile.go @@ -292,8 +292,8 @@ func resourceRoutingProfileUpdate(ctx context.Context, d *schema.ResourceData, m // AssociateRoutingProfileQueues - Associates a set of queues with a routing profile. // DisassociateRoutingProfileQueues - Disassociates a set of queues from a routing profile. // UpdateRoutingProfileQueues - Updates the properties associated with a set of queues for a routing profile. - // since the update only updates the existing queues that are associated, we will instead disassociate (if there are any queues) - // and then associate all the queues again to ensure new queues can be added and unused queues can be removed + // since the update only updates the existing queues that are associated, we will instead disassociate and associate + // the respective queues based on the diff detected if d.HasChange("queue_configs") { o, n := d.GetChange("queue_configs") From 66fbd1139a56840ea843b22e55854a031858b8b3 Mon Sep 17 00:00:00 2001 From: GlennChia Date: Tue, 18 Oct 2022 21:37:25 +0000 Subject: [PATCH 4/9] refactor(connect): err message --- internal/service/connect/routing_profile.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/service/connect/routing_profile.go b/internal/service/connect/routing_profile.go index 2008fd9061e..60e696c9fe7 100644 --- a/internal/service/connect/routing_profile.go +++ b/internal/service/connect/routing_profile.go @@ -328,7 +328,7 @@ func resourceRoutingProfileUpdate(ctx context.Context, d *schema.ResourceData, m RoutingProfileId: aws.String(routingProfileID), }) if err != nil { - return diag.FromErr(fmt.Errorf("updating RoutingProfile Queue Configs, specifically associating queues to routing profile (%s): %w", d.Id(), err)) + return diag.Errorf("updating RoutingProfile Queue Configs, specifically associating queues to routing profile (%s): %s", d.Id(), err) } } } From 9d4ef6376dfa5206f35d195b33b2ef4278fc9123 Mon Sep 17 00:00:00 2001 From: GlennChia Date: Sun, 26 Feb 2023 01:37:21 +0000 Subject: [PATCH 5/9] chore(connect): deprecate unused attributes --- internal/service/connect/queue.go | 9 ++++++ internal/service/connect/routing_profile.go | 34 +++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/internal/service/connect/queue.go b/internal/service/connect/queue.go index a0ad38deb74..3cf3f353f13 100644 --- a/internal/service/connect/queue.go +++ b/internal/service/connect/queue.go @@ -93,6 +93,14 @@ func ResourceQueue() *schema.Resource { Type: schema.TypeString, }, }, + "quick_connect_ids_associated": { + Deprecated: "Use the quick_connect_ids instead", + Type: schema.TypeSet, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, "status": { Type: schema.TypeString, Optional: true, @@ -209,6 +217,7 @@ func resourceQueueRead(ctx context.Context, d *schema.ResourceData, meta interfa } d.Set("quick_connect_ids", flex.FlattenStringSet(quickConnectIds)) + d.Set("quick_connect_ids_associated", flex.FlattenStringSet(quickConnectIds)) tags := KeyValueTags(ctx, resp.Queue.Tags).IgnoreAWS().IgnoreConfig(ignoreTagsConfig) diff --git a/internal/service/connect/routing_profile.go b/internal/service/connect/routing_profile.go index 60e696c9fe7..e67d243dc4e 100644 --- a/internal/service/connect/routing_profile.go +++ b/internal/service/connect/routing_profile.go @@ -109,6 +109,39 @@ func ResourceRoutingProfile() *schema.Resource { }, }, }, + "queue_configs_associated": { + Deprecated: "Use the queue_configs instead", + Type: schema.TypeSet, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "channel": { + Type: schema.TypeString, + Computed: true, + }, + "delay": { + Type: schema.TypeInt, + Computed: true, + }, + "priority": { + Type: schema.TypeInt, + Computed: true, + }, + "queue_arn": { + Type: schema.TypeString, + Computed: true, + }, + "queue_id": { + Type: schema.TypeString, + Computed: true, + }, + "queue_name": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, "routing_profile_id": { Type: schema.TypeString, Computed: true, @@ -211,6 +244,7 @@ func resourceRoutingProfileRead(ctx context.Context, d *schema.ResourceData, met } d.Set("queue_configs", queueConfigs) + d.Set("queue_configs_associated", queueConfigs) tags := KeyValueTags(ctx, routingProfile.Tags).IgnoreAWS().IgnoreConfig(ignoreTagsConfig) From bacdf7dd7e8af59eecf9824db96155abf9c988ba Mon Sep 17 00:00:00 2001 From: GlennChia Date: Sun, 26 Feb 2023 01:37:49 +0000 Subject: [PATCH 6/9] ci(connect): changelog deprecate unused attributes --- .changelog/26151.txt | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .changelog/26151.txt diff --git a/.changelog/26151.txt b/.changelog/26151.txt new file mode 100644 index 00000000000..4caf3839245 --- /dev/null +++ b/.changelog/26151.txt @@ -0,0 +1,7 @@ +```release-note:note +resource/aws_connect_queue: The `quick_connect_ids_associated` attribute is being deprecated in favor of `quick_connect_ids` +``` + +```release-note:note +resource/aws_connect_routing_profile: The `queue_configs_associated` attribute is being deprecated in favor of `queue_configs` +``` \ No newline at end of file From 8a955a85031f3ad58e8bdcbe1434f7641324bff3 Mon Sep 17 00:00:00 2001 From: GlennChia Date: Sun, 26 Feb 2023 01:50:18 +0000 Subject: [PATCH 7/9] refactor(connect): use diag.Errorf context errs --- internal/service/connect/queue.go | 4 ++-- internal/service/connect/routing_profile.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/service/connect/queue.go b/internal/service/connect/queue.go index 3cf3f353f13..10c662dde07 100644 --- a/internal/service/connect/queue.go +++ b/internal/service/connect/queue.go @@ -344,7 +344,7 @@ func resourceQueueUpdate(ctx context.Context, d *schema.ResourceData, meta inter QuickConnectIds: flex.ExpandStringSet(quickConnectIdsUpdateAdd), }) if err != nil { - return diag.FromErr(fmt.Errorf("updating Queues Quick Connect IDs, specifically associating quick connects to queue (%s): %w", d.Id(), err)) + return diag.Errorf("updating Queues Quick Connect IDs, specifically associating quick connects to queue (%s): %s", d.Id(), err) } } @@ -355,7 +355,7 @@ func resourceQueueUpdate(ctx context.Context, d *schema.ResourceData, meta inter QuickConnectIds: flex.ExpandStringSet(quickConnectIdsUpdateRemove), }) if err != nil { - return diag.FromErr(fmt.Errorf("updating Queues Quick Connect IDs, specifically disassociating quick connects from queue (%s): %w", d.Id(), err)) + return diag.Errorf("updating Queues Quick Connect IDs, specifically disassociating quick connects from queue (%s): %s", d.Id(), err) } } } diff --git a/internal/service/connect/routing_profile.go b/internal/service/connect/routing_profile.go index e67d243dc4e..33f4c40f76a 100644 --- a/internal/service/connect/routing_profile.go +++ b/internal/service/connect/routing_profile.go @@ -351,7 +351,7 @@ func resourceRoutingProfileUpdate(ctx context.Context, d *schema.ResourceData, m RoutingProfileId: aws.String(routingProfileID), }) if err != nil { - return diag.FromErr(fmt.Errorf("updating RoutingProfile Queue Configs, specifically disassociating queues from routing profile (%s): %w", d.Id(), err)) + return diag.Errorf("updating RoutingProfile Queue Configs, specifically disassociating queues from routing profile (%s): %s", d.Id(), err) } } From f349e432b13b25138867145ac582bf32c919b480 Mon Sep 17 00:00:00 2001 From: GlennChia Date: Sun, 26 Feb 2023 01:51:25 +0000 Subject: [PATCH 8/9] ci(connect): semgrep ignore WithContext --- internal/service/connect/queue.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/service/connect/queue.go b/internal/service/connect/queue.go index 10c662dde07..3db203132c2 100644 --- a/internal/service/connect/queue.go +++ b/internal/service/connect/queue.go @@ -337,7 +337,7 @@ func resourceQueueUpdate(ctx context.Context, d *schema.ResourceData, meta inter quickConnectIdsUpdateAdd := ns.Difference(os) quickConnectIdsUpdateRemove := os.Difference(ns) - if len(quickConnectIdsUpdateAdd.List()) > 0 { + if len(quickConnectIdsUpdateAdd.List()) > 0 { // nosemgrep:ci.semgrep.migrate.aws-api-context _, err = conn.AssociateQueueQuickConnectsWithContext(ctx, &connect.AssociateQueueQuickConnectsInput{ InstanceId: aws.String(instanceID), QueueId: aws.String(queueID), @@ -348,7 +348,7 @@ func resourceQueueUpdate(ctx context.Context, d *schema.ResourceData, meta inter } } - if len(quickConnectIdsUpdateRemove.List()) > 0 { + if len(quickConnectIdsUpdateRemove.List()) > 0 { // nosemgrep:ci.semgrep.migrate.aws-api-context _, err = conn.DisassociateQueueQuickConnectsWithContext(ctx, &connect.DisassociateQueueQuickConnectsInput{ InstanceId: aws.String(instanceID), QueueId: aws.String(queueID), From c738b831c46403c0df451727965b50c230012b0e Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 14 Mar 2023 16:21:34 -0400 Subject: [PATCH 9/9] r/aws_connect_instance: Always send attribute values on Create, not just if they're 'true'. --- internal/service/connect/instance.go | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/internal/service/connect/instance.go b/internal/service/connect/instance.go index be55c20819a..efe8ce90ee0 100644 --- a/internal/service/connect/instance.go +++ b/internal/service/connect/instance.go @@ -148,15 +148,12 @@ func resourceInstanceCreate(ctx context.Context, d *schema.ResourceData, meta in for att := range InstanceAttributeMapping() { rKey := InstanceAttributeMapping()[att] - - if v, ok := d.GetOk(rKey); ok { - err := resourceInstanceUpdateAttribute(ctx, conn, d.Id(), att, strconv.FormatBool(v.(bool))) - //Pre-release attribute, user/account/instance now allow-listed - if err != nil && tfawserr.ErrCodeEquals(err, ErrCodeAccessDeniedException) || tfawserr.ErrMessageContains(err, ErrCodeAccessDeniedException, "not authorized to update") { - log.Printf("[WARN] error setting Connect instance (%s) attribute (%s): %s", d.Id(), att, err) - } else if err != nil { - return diag.FromErr(fmt.Errorf("error setting Connect instance (%s) attribute (%s): %w", d.Id(), att, err)) - } + err := resourceInstanceUpdateAttribute(ctx, conn, d.Id(), att, strconv.FormatBool(d.Get(rKey).(bool))) + //Pre-release attribute, user/account/instance now allow-listed + if err != nil && tfawserr.ErrCodeEquals(err, ErrCodeAccessDeniedException) || tfawserr.ErrMessageContains(err, ErrCodeAccessDeniedException, "not authorized to update") { + log.Printf("[WARN] error setting Connect instance (%s) attribute (%s): %s", d.Id(), att, err) + } else if err != nil { + return diag.FromErr(fmt.Errorf("error setting Connect instance (%s) attribute (%s): %w", d.Id(), att, err)) } }