-
Notifications
You must be signed in to change notification settings - Fork 3
/
resource_taskrouter_queue_funcs.go
90 lines (63 loc) · 2.04 KB
/
resource_taskrouter_queue_funcs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package main
import (
"net/url"
"golang.org/x/net/context"
"github.com/hashicorp/terraform/helper/schema"
)
func taskRouterQueueCreate(d *schema.ResourceData, meta interface{}) error {
m := meta.(*twilioMeta)
data := url.Values{}
data.Set("FriendlyName", d.Get("friendly_name").(string))
data.Set("ReservationActivitySid", d.Get("reservation_activity_sid").(string))
data.Set("AssignmentActivitySid", d.Get("assignment_activity_sid").(string))
data.Set("TargetWorkers", d.Get("target_workers").(string))
taskQueue, err := m.Client.TaskRouter.Workspace(m.WorkspaceSid).Queues.Create(context.Background(), data)
if err != nil {
return err
}
d.SetId(taskQueue.Sid)
return taskRouterQueueUpdate(d, meta)
}
func taskRouterQueueUpdate(d *schema.ResourceData, meta interface{}) error {
m := meta.(*twilioMeta)
data := url.Values{}
if d.HasChange("friendly_name") {
data.Set("FriendlyName", d.Get("friendly_name").(string))
}
if d.HasChange("reservation_activity_sid") {
data.Set("ReservationActivitySid", d.Get("reservation_activity_sid").(string))
}
if d.HasChange("assignment_activity_sid") {
data.Set("AssignmentActivitySid", d.Get("assignment_activity_sid").(string))
}
if d.HasChange("target_workers") {
data.Set("TargetWorkers", d.Get("target_workers").(string))
}
_, err := m.Client.TaskRouter.Workspace(m.WorkspaceSid).Queues.Update(context.Background(), d.Id(), data)
if err != nil {
return err
}
return taskRouterQueueRead(d, meta)
}
func taskRouterQueueRead(d *schema.ResourceData, meta interface{}) error {
m := meta.(*twilioMeta)
taskQueue, err := m.Client.TaskRouter.Workspace(m.WorkspaceSid).Queues.Get(context.Background(), d.Id())
if err != nil {
return err
}
if taskQueue == nil {
d.SetId("")
return err
}
d.SetId(taskQueue.Sid)
return nil
}
func taskRouterQueueDelete(d *schema.ResourceData, meta interface{}) error {
m := meta.(*twilioMeta)
err := m.Client.TaskRouter.Workspace(m.WorkspaceSid).Queues.Delete(context.Background(), d.Id())
if err != nil {
return err
}
d.SetId("")
return nil
}