Skip to content

Commit

Permalink
New resource: zoom_phone_call_queue_policy_voice_mail
Browse files Browse the repository at this point in the history
Signed-off-by: krrrr38 <k.kaizu38@gmail.com>
  • Loading branch information
krrrr38 committed Oct 17, 2024
1 parent 03278ab commit 27f7781
Show file tree
Hide file tree
Showing 10 changed files with 693 additions and 0 deletions.
71 changes: 71 additions & 0 deletions docs/resources/phone_call_queue_policy_voice_mail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "zoom_phone_call_queue_policy_voice_mail Resource - zoom"
subcategory: ""
description: |-
The policy sub-setting for a specific call queue according to the voice_mail.
API Permissions
The following API permissions are required in order to use this resource.
This resource requires the phone:read:call_queue:admin, phone:write:call_queue_policy:admin, phone:update:call_queue_policy:admin, phone:delete:call_queue_policy:admin.
---

# zoom_phone_call_queue_policy_voice_mail (Resource)

The policy sub-setting for a specific call queue according to the voice_mail.

## API Permissions
The following API permissions are required in order to use this resource.
This resource requires the `phone:read:call_queue:admin`, `phone:write:call_queue_policy:admin`, `phone:update:call_queue_policy:admin`, `phone:delete:call_queue_policy:admin`.

## Example Usage

```terraform
resource "zoom_phone_call_queue" "example" {
name = "terraform-example"
extension_number = "1234"
}
resource "zoom_phone_call_queue_policy_voice_mail" "example" {
call_queue_id = zoom_phone_call_queue.example.id
access_members = [
{
access_user_id = "LLgNJuS-Q6aYBcsv2wJnug", # Zoom User Id (not phone user id)
allow_download = true
allow_delete = false
allow_sharing = true
},
]
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `access_members` (Attributes Set) The shared voicemail access member list. (see [below for nested schema](#nestedatt--access_members))
- `call_queue_id` (String) Unique identifier of the Call Queue.

<a id="nestedatt--access_members"></a>
### Nested Schema for `access_members`

Required:

- `access_user_id` (String) The Zoom user ID or email to share or update the access permissions with.
- `allow_delete` (Boolean) Specifies whether the member has delete permissions. The default is **false**.
- `allow_download` (Boolean) Specifies whether the member has download permissions. The default is **false**.
- `allow_sharing` (Boolean) Specifies whether the member has the permission to share. The default is **false**.

Read-Only:

- `shared_id` (String) The number is limited to the minimum value of 10 or the number of allowed access members account setting.

## Import

Import is supported using the following syntax:

```shell
# ${call_queue_id}
terraform import zoom_phone_call_queue_policy_voice_mail.example wGJDBcnJQC6tV86BbtlXXX
```

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# ${call_queue_id}
terraform import zoom_phone_call_queue_policy_voice_mail.example wGJDBcnJQC6tV86BbtlXXX
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
terraform {
required_providers {
zoom = {
source = "folio-sec/zoom"
version = "~> 0.0.0"
}
}
}

provider "zoom" {
account_id = var.zoom_account_id
client_id = var.zoom_client_id
client_secret = var.zoom_client_secret
}

variable "zoom_account_id" {}

variable "zoom_client_id" {}

variable "zoom_client_secret" {
sensitive = true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
resource "zoom_phone_call_queue" "example" {
name = "terraform-example"
extension_number = "1234"
}

resource "zoom_phone_call_queue_policy_voice_mail" "example" {
call_queue_id = zoom_phone_call_queue.example.id

access_members = [
{
access_user_id = "LLgNJuS-Q6aYBcsv2wJnug", # Zoom User Id (not phone user id)
allow_download = true
allow_delete = false
allow_sharing = true
},
]
}
2 changes: 2 additions & 0 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/folio-sec/terraform-provider-zoom/internal/services/phone/callqueue"
"github.com/folio-sec/terraform-provider-zoom/internal/services/phone/callqueuemember"
"github.com/folio-sec/terraform-provider-zoom/internal/services/phone/callqueuephonenumber"
"github.com/folio-sec/terraform-provider-zoom/internal/services/phone/callqueuepolicy"
"github.com/folio-sec/terraform-provider-zoom/internal/services/phone/externalcontact"
"github.com/folio-sec/terraform-provider-zoom/internal/services/phone/phonenumbers"
"github.com/folio-sec/terraform-provider-zoom/internal/services/phone/sharedlinegroup"
Expand Down Expand Up @@ -217,6 +218,7 @@ func (p *zoomProvider) Resources(_ context.Context) []func() resource.Resource {
callqueue.NewPhoneCallQueueResource,
callqueuemember.NewPhoneCallQueueMembersResource,
callqueuephonenumber.NewPhoneCallQueuePhoneNumbersResource,
callqueuepolicy.NewPhoneCallQueuePolicyVoiceMailResource,
externalcontact.NewPhoneExternalContactResource,
sharedlinegroupgroup.NewPhoneSharedLineGroupResource,
sharedlinegroupgroupmembers.NewPhoneSharedLineGroupMembersResource,
Expand Down
131 changes: 131 additions & 0 deletions internal/services/phone/callqueuepolicy/call_queue_policy_crud.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
package callqueuepolicy

import (
"context"
"errors"
"fmt"
"github.com/folio-sec/terraform-provider-zoom/generated/api/zoomphone"
"github.com/folio-sec/terraform-provider-zoom/internal/util"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/samber/lo"
)

func newCrud(client *zoomphone.Client) *crud {
return &crud{
client: client,
}
}

type crud struct {
client *zoomphone.Client
}

func (c *crud) read(ctx context.Context, callQueueID types.String) (*readDto, error) {
detail, err := c.client.GetACallQueue(ctx, zoomphone.GetACallQueueParams{
CallQueueId: callQueueID.ValueString(),
})
if err != nil {
var status *zoomphone.ErrorResponseStatusCode
if errors.As(err, &status) {
if status.StatusCode == 400 {
return nil, nil // already deleted
}
}
return nil, fmt.Errorf("unable to read phone call queue policy: %w", err)
}

var policyVoiceMailMembers []*readDtoPolicyVoiceMailMember
if detail.Policy.IsSet() {
policyVoiceMailMembers = lo.Map(detail.Policy.Value.GetVoicemailAccessMembers(), func(item zoomphone.GetACallQueueOKPolicyVoicemailAccessMembersItem, index int) *readDtoPolicyVoiceMailMember {
return &readDtoPolicyVoiceMailMember{
accessUserID: util.FromOptString(item.AccessUserID),
allowDownload: util.FromOptBool(item.AllowDownload),
allowDelete: util.FromOptBool(item.AllowDelete),
allowSharing: util.FromOptBool(item.AllowSharing),
sharedID: util.FromOptString(item.SharedID),
}
})
}
return &readDto{
callQueueID: callQueueID,
policyVoiceMailMembers: policyVoiceMailMembers,
}, nil
}

func (c *crud) add(ctx context.Context, dto *addDto) error {
var voicemailAccessMembers []zoomphone.AddCQPolicySubSettingReqVoicemailAccessMembersItem
if dto.voicemailAccessMembers != nil {
voicemailAccessMembers = lo.Map(dto.voicemailAccessMembers, func(item *addDtoVoicemailAccessMember, index int) zoomphone.AddCQPolicySubSettingReqVoicemailAccessMembersItem {
return zoomphone.AddCQPolicySubSettingReqVoicemailAccessMembersItem{
AccessUserID: util.ToPhoneOptString(item.accessUserID),
AllowDownload: util.ToPhoneOptBool(item.allowDownload),
AllowDelete: util.ToPhoneOptBool(item.allowDelete),
AllowSharing: util.ToPhoneOptBool(item.allowSharing),
}
})
}
_, err := c.client.AddCQPolicySubSetting(ctx, zoomphone.OptAddCQPolicySubSettingReq{
Value: zoomphone.AddCQPolicySubSettingReq{
VoicemailAccessMembers: voicemailAccessMembers,
},
Set: true,
}, zoomphone.AddCQPolicySubSettingParams{
CallQueueId: dto.callQueueID.ValueString(),
PolicyType: dto.policyType.String(),
})
if err != nil {
return fmt.Errorf("error creating phone call queue policy: %v", err)
}
return nil
}

func (c *crud) update(ctx context.Context, dto *updateDto) error {
var voicemailAccessMembers []zoomphone.UpdateCQPolicySubSettingReqVoicemailAccessMembersItem
if dto.voicemailAccessMembers != nil {
voicemailAccessMembers = lo.Map(dto.voicemailAccessMembers, func(item *updateDtoVoicemailAccessMember, index int) zoomphone.UpdateCQPolicySubSettingReqVoicemailAccessMembersItem {
return zoomphone.UpdateCQPolicySubSettingReqVoicemailAccessMembersItem{
AccessUserID: util.ToPhoneOptString(item.accessUserID),
AllowDownload: util.ToPhoneOptBool(item.allowDownload),
AllowDelete: util.ToPhoneOptBool(item.allowDelete),
AllowSharing: util.ToPhoneOptBool(item.allowSharing),
SharedID: util.ToPhoneOptString(item.sharedID),
}
})
}
err := c.client.UpdateCQPolicySubSetting(ctx, zoomphone.OptUpdateCQPolicySubSettingReq{
Value: zoomphone.UpdateCQPolicySubSettingReq{
VoicemailAccessMembers: voicemailAccessMembers,
},
Set: true,
}, zoomphone.UpdateCQPolicySubSettingParams{
CallQueueId: dto.callQueueID.ValueString(),
PolicyType: dto.policyType.String(),
})
if err != nil {
return fmt.Errorf("error updating phone call queue policy: %v", err)
}
return nil
}

func (c *crud) remove(ctx context.Context, dto *removeDto) error {
// maxItems: 20
for _, chunk := range lo.Chunk(dto.sharedIDs, 20) {
err := c.client.RemoveCQPolicySubSetting(ctx, zoomphone.RemoveCQPolicySubSettingParams{
CallQueueId: dto.callQueueID.ValueString(),
PolicyType: dto.policyType.String(),
SharedIds: lo.Map(chunk, func(item types.String, index int) string {
return item.ValueString()
}),
})
if err != nil {
var status *zoomphone.ErrorResponseStatusCode
if errors.As(err, &status) {
if status.StatusCode == 400 && status.Response.Code.Value == 404 {
return nil
}
}
return fmt.Errorf("error removing phone call queue policy: %v", err)
}
}
return nil
}
66 changes: 66 additions & 0 deletions internal/services/phone/callqueuepolicy/call_queue_policy_dto.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package callqueuepolicy

import (
"github.com/hashicorp/terraform-plugin-framework/types"
)

type PolicyType int

const (
VoiceMail PolicyType = iota
)

func (pt PolicyType) String() string {
switch pt {
case VoiceMail:
return "voice_mail"
default:
return ""
}
}

type readDto struct {
callQueueID types.String
policyVoiceMailMembers []*readDtoPolicyVoiceMailMember
}

type readDtoPolicyVoiceMailMember struct {
accessUserID types.String
allowDownload types.Bool
allowDelete types.Bool
allowSharing types.Bool
sharedID types.String
}

type addDto struct {
callQueueID types.String
policyType PolicyType
voicemailAccessMembers []*addDtoVoicemailAccessMember
}

type addDtoVoicemailAccessMember struct {
accessUserID types.String
allowDownload types.Bool
allowDelete types.Bool
allowSharing types.Bool
}

type updateDto struct {
callQueueID types.String
policyType PolicyType
voicemailAccessMembers []*updateDtoVoicemailAccessMember
}

type updateDtoVoicemailAccessMember struct {
accessUserID types.String
allowDownload types.Bool
allowDelete types.Bool
allowSharing types.Bool
sharedID types.String
}

type removeDto struct {
callQueueID types.String
policyType PolicyType
sharedIDs []types.String
}
Loading

0 comments on commit 27f7781

Please sign in to comment.