Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

r/aws_connect_queue-update quick connect ids #22821

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/22821.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_connect_queue: The `quick_connect_ids` argument can now be updated in-place
```
3 changes: 3 additions & 0 deletions internal/service/connect/enum.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ const (
// MaxResults Valid Range: Minimum value of 1. Maximum value of 1000
// https://docs.aws.amazon.com/connect/latest/APIReference/API_ListPrompts.html
ListPromptsMaxResults = 60
// ListQueueQuickConnectsMaxResults Valid Range: Minimum value of 1. Maximum value of 100.
// https://docs.aws.amazon.com/connect/latest/APIReference/API_ListQueueQuickConnects.html
ListQueueQuickConnectsMaxResults = 60
// ListQuickConnectsMaxResults Valid Range: Minimum value of 1. Maximum value of 1000.
// https://docs.aws.amazon.com/connect/latest/APIReference/API_ListQuickConnects.html
ListQuickConnectsMaxResults = 60
Expand Down
82 changes: 80 additions & 2 deletions internal/service/connect/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,13 @@ func ResourceQueue() *schema.Resource {
"quick_connect_ids": {
Type: schema.TypeSet,
Optional: true,
ForceNew: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"quick_connect_ids_associated": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Expand Down Expand Up @@ -200,6 +206,16 @@ func resourceQueueRead(ctx context.Context, d *schema.ResourceData, meta interfa
d.Set("queue_id", resp.Queue.QueueId)
d.Set("status", resp.Queue.Status)

// reading quick_connect_ids requires a separate API call
quickConnectIds, err := getConnectQueueQuickConnectIds(ctx, conn, instanceID, queueID)

if err != nil {
return diag.FromErr(fmt.Errorf("error finding Connect Queue Quick Connect ID for Queue (%s): %w", queueID, err))
}

d.Set("quick_connect_ids", flex.FlattenStringSet(quickConnectIds))
d.Set("quick_connect_ids_associated", flex.FlattenStringSet(quickConnectIds))

tags := KeyValueTags(resp.Queue.Tags).IgnoreAWS().IgnoreConfig(ignoreTagsConfig)

//lintignore:AWSR002
Expand All @@ -223,12 +239,13 @@ func resourceQueueUpdate(ctx context.Context, d *schema.ResourceData, meta inter
return diag.FromErr(err)
}

// Queue has 5 update APIs
// Queue has 6 update APIs
// UpdateQueueHoursOfOperationWithContext: Updates the hours_of_operation_id of a queue.
// UpdateQueueMaxContactsWithContext: Updates the max_contacts of a queue.
// UpdateQueueNameWithContext: Updates the name and description of a queue.
// UpdateQueueOutboundCallerConfigWithContext: Updates the outbound_caller_config of a queue.
// UpdateQueueStatusWithContext: Updates the status of a queue. Valid Values: ENABLED | DISABLED
// AssociateQueueQuickConnectsWithContext: Associates a set of quick connects with a queue. There is also DisassociateQueueQuickConnectsWithContext

// updates to hours_of_operation_id
if d.HasChange("hours_of_operation_id") {
Expand Down Expand Up @@ -301,6 +318,35 @@ 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)
if err != nil {
return diag.FromErr(fmt.Errorf("[ERROR] Error updating Queues Quick Connect IDs, specifically disassociating quick connects from 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 err != nil {
return diag.FromErr(fmt.Errorf("[ERROR] Error updating Queues Quick Connect IDs, specifically associating quick connects to queue (%s): %w", d.Id(), err))
}
}
}

// updates to tags
if d.HasChange("tags_all") {
o, n := d.GetChange("tags_all")
Expand Down Expand Up @@ -363,6 +409,38 @@ func flattenOutboundCallerConfig(outboundCallerConfig *connect.OutboundCallerCon
return []interface{}{values}
}

func getConnectQueueQuickConnectIds(ctx context.Context, conn *connect.Connect, instanceID, queueID string) ([]*string, error) {
var result []*string

input := &connect.ListQueueQuickConnectsInput{
InstanceId: aws.String(instanceID),
MaxResults: aws.Int64(ListQueueQuickConnectsMaxResults),
QueueId: aws.String(queueID),
}

err := conn.ListQueueQuickConnectsPagesWithContext(ctx, input, func(page *connect.ListQueueQuickConnectsOutput, lastPage bool) bool {
if page == nil {
return !lastPage
}

for _, qc := range page.QuickConnectSummaryList {
if qc == nil {
continue
}

result = append(result, qc.Id)
}

return !lastPage
})

if err != nil {
return nil, err
}

return result, nil
}

func QueueParseID(id string) (string, string, error) {
parts := strings.SplitN(id, ":", 2)

Expand Down
Loading