-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New resource: zoom_phone_call_queue_policy_voice_mail (#54)
Signed-off-by: krrrr38 <[email protected]>
- Loading branch information
Showing
9 changed files
with
669 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
2 changes: 2 additions & 0 deletions
2
examples/resources/zoom_phone_call_queue_policy_voice_mail/import.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
22 changes: 22 additions & 0 deletions
22
examples/resources/zoom_phone_call_queue_policy_voice_mail/provider.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
17 changes: 17 additions & 0 deletions
17
examples/resources/zoom_phone_call_queue_policy_voice_mail/resource.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}, | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
131 changes: 131 additions & 0 deletions
131
internal/services/phone/callqueuepolicy/call_queue_policy_crud.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
66
internal/services/phone/callqueuepolicy/call_queue_policy_dto.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.