-
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_user_calling_plans (#31)
Signed-off-by: Tadayuki Onishi <tonishi@folio-sec.com> Co-authored-by: Tadayuki Onishi <tonishi@folio-sec.com>
- Loading branch information
1 parent
030979c
commit 5f032ca
Showing
11 changed files
with
683 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "zoom_phone_user_calling_plans Resource - zoom" | ||
subcategory: "" | ||
description: |- | ||
Assigns calling plans to a Zoom Phone user. | ||
API Permissions | ||
The following API permissions are required in order to use this resource. | ||
This resource requires the phone:read:user:admin, phone:write:calling_plan:admin, phone:delete:users_calling_plan:admin. | ||
--- | ||
|
||
# zoom_phone_user_calling_plans (Resource) | ||
|
||
Assigns calling plans to a Zoom Phone user. | ||
|
||
## API Permissions | ||
|
||
The following API permissions are required in order to use this resource. | ||
This resource requires the `phone:read:user:admin`, `phone:write:calling_plan:admin`, `phone:delete:users_calling_plan:admin`. | ||
|
||
## Example Usage | ||
|
||
```terraform | ||
resource "zoom_phone_user" "example" { | ||
user_id = "AAggbuS-Q6aXXcsv2wnug" | ||
extension_number = 101 | ||
} | ||
resource "zoom_phone_user_calling_plans" "example" { | ||
user_id = zoom_phone_user.example.user_id | ||
calling_plans = [ | ||
{ | ||
type = 207 | ||
}, | ||
] | ||
} | ||
``` | ||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `calling_plans` (Attributes Set) Use this attribute to configure settings for the calling plan of the user. (see [below for nested schema](#nestedatt--calling_plans)) | ||
- `user_id` (String) The ID of the Zoom user. | ||
|
||
<a id="nestedatt--calling_plans"></a> | ||
### Nested Schema for `calling_plans` | ||
|
||
Required: | ||
|
||
- `type` (Number) The [type](https://marketplace.zoom.us/docs/api-reference/other-references/plans#zoom-phone-calling-plans) of calling plan. Allowed: `1`, `3`, `4`, `5`, `6`, `100`, `101`, `102`, `103`, `104`, `107`, `200`, `201`, `202`, `203`, `204`, `207`, `300`, `301`, `302`, `303`, `304`, `307`, `400`, `401`, `402`, `403`, `404`, `600`, `1000`, `1001`, `2000`, `3000`, `3010`, `3040`, `3098`, `3099`, `4000`, `4010`, `5000`, `30000`, `30001`, `30002`, `30003`, `30004`, `30007`, `31000`, `31001`, `31002`, `31003`, `31004`, `31005`, `31006`, `31007`, `40200`, `40201`, `40202`, `40207`, `41000`, `43000`, `50200`, `50201`, `50202`, `50207`, `51000`, `53000`, `60200`, `60201`, `60202`, `60207`, `61000`, `63000`, `70200`, `70201`, `70202`, `70207`, `71000` | ||
- `1`: NO_FEATURE_PACKAGE | ||
- `3`: INTERNATIONAL_TOLL_NUMBER | ||
- `4`: INTERNATIONAL_TOLL_FREE_NUMBER | ||
- `5`: BYOC_NUMBER | ||
- `6`: BETA_NUMBER | ||
- `100`: METERED_PLAN_US_CA | ||
- `101`: METERED_PLAN_AU_NZ | ||
- `102`: METERED_PLAN_GB_IE | ||
- `103`: METERED_EURA | ||
- `104`: METERED_EURB | ||
- `107`: METERED_JP | ||
- `200`: UNLIMITED_PLAN_US_CA | ||
- `201`: UNLIMITED_PLAN_AU_NZ | ||
- `202`: UNLIMITED_PLAN_GB_IE | ||
- `203`: UNLIMITED_EURA | ||
- `204`: UNLIMITED_EURB | ||
- `207`: UNLIMITED_JP | ||
- `300`: US_CA_NUMBER | ||
- `301`: AU_NZ_NUMBER | ||
- `302`: GB_IE_NUMBER | ||
- `303`: EURA_NUMBER | ||
- `304`: EURB_NUMBER | ||
- `307`: JP_NUMBER | ||
- `400`: US_CA_TOLLFREE_NUMBER | ||
- `401`: AU_TOLLFREE_NUMBER | ||
- `402`: GB_IE_TOLLFREE_NUMBER | ||
- `403`: NZ_TOLLFREE_NUMBER | ||
- `404`: GLOBAL_TOLLFREE_NUMBER | ||
- `600`: BETA | ||
- `1000`: UNLIMITED_DOMESTIC_SELECT | ||
- `1001`: METERED_GLOBAL_SELECT | ||
- `2000`: UNLIMITED_DOMESTIC_SELECT_NUMBER | ||
- `3000`: ZP_PRO | ||
- `3010`: BASIC | ||
- `3040`: ZP_COMMON_AREA | ||
- `3098`: RESERVED_PLAN | ||
- `3099`: BASIC_MIGRATED | ||
- `4000`: INTERNATIONAL_SELECT_ADDON | ||
- `4010`: ZP_PREMIUM_ADDON | ||
- `5000`: PREMIUM_NUMBER | ||
- `30000`: METERED_US_CA_NUMBER_INCLUDED | ||
- `30001`: METERED_AU_NZ_NUMBER_INCLUDED | ||
- `30002`: METERED_GB_IE_NUMBER_INCLUDED | ||
- `30003`: METERED_EURA_NUMBER_INCLUDED | ||
- `30004`: METERED_EURB_NUMBER_INCLUDED | ||
- `30007`: METERED_JP_NUMBER_INCLUDED | ||
- `31000`: UNLIMITED_US_CA_NUMBER_INCLUDED | ||
- `31001`: UNLIMITED_AU_NZ_NUMBER_INCLUDED | ||
- `31002`: UNLIMITED_GB_IE_NUMBER_INCLUDED | ||
- `31003`: UNLIMITED_EURA_NUMBER_INCLUDED | ||
- `31004`: UNLIMITED_EURB_NUMBER_INCLUDED | ||
- `31005`: UNLIMITED_DOMESTIC_SELECT_NUMBER_INCLUDED | ||
- `31006`: METERED_GLOBAL_SELECT_NUMBER_INCLUDED | ||
- `31007`: UNLIMITED_JP_NUMBER_INCLUDED | ||
- `40200`: MEETINGS_PRO_UNLIMITED_US_CA | ||
- `40201`: MEETINGS_PRO_UNLIMITED_AU_NZ | ||
- `40202`: MEETINGS_PRO_UNLIMITED_GB_IE | ||
- `40207`: MEETINGS_PRO_UNLIMITED_JP | ||
- `41000`: MEETINGS_PRO_GLOBAL_SELECT | ||
- `43000`: MEETINGS_PRO_PN_PRO | ||
- `50200`: MEETINGS_BUS_UNLIMITED_US_CA | ||
- `50201`: MEETINGS_BUS_UNLIMITED_AU_NZ | ||
- `50202`: MEETINGS_BUS_UNLIMITED_GB_IE | ||
- `50207`: MEETINGS_BUS_UNLIMITED_JP | ||
- `51000`: MEETINGS_BUS_GLOBAL_SELECT | ||
- `53000`: MEETINGS_BUS_PN_PRO | ||
- `60200`: MEETINGS_ENT_UNLIMITED_US_CA | ||
- `60201`: MEETINGS_ENT_UNLIMITED_AU_NZ | ||
- `60202`: MEETINGS_ENT_UNLIMITED_GB_IE | ||
- `60207`: MEETINGS_ENT_UNLIMITED_JP | ||
- `61000`: MEETINGS_ENT_GLOBAL_SELECT | ||
- `63000`: MEETINGS_ENT_PN_PRO | ||
- `70200`: MEETINGS_US_CA_NUMBER_INCLUDED | ||
- `70201`: MEETINGS_AU_NZ_NUMBER_INCLUDED | ||
- `70202`: MEETINGS_GB_IE_NUMBER_INCLUDED | ||
- `70207`: MEETINGS_JP_NUMBER_INCLUDED | ||
- `71000`: MEETINGS_GLOBAL_SELECT_NUMBER_INCLUDED | ||
|
||
Optional: | ||
|
||
- `billing_account_id` (String) The billing account ID. If the user is located in India, the field is required. | ||
|
||
Read-Only: | ||
|
||
- `name` (String) The name of the calling plan. | ||
|
||
## Import | ||
|
||
Import is supported using the following syntax: | ||
|
||
```shell | ||
# ${user_id} | ||
terraform import zoom_phone_user_calling_plans.example AAggbuS-Q6aXXcsv2wnug | ||
``` |
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 @@ | ||
# ${user_id} | ||
terraform import zoom_phone_user_calling_plans.example AAggbuS-Q6aXXcsv2wnug |
21 changes: 21 additions & 0 deletions
21
examples/resources/zoom_phone_user_calling_plans/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,21 @@ | ||
terraform { | ||
required_providers { | ||
zoom = { | ||
source = "registry.terraform.io/folio-sec/zoom" | ||
} | ||
} | ||
} | ||
|
||
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 | ||
} |
13 changes: 13 additions & 0 deletions
13
examples/resources/zoom_phone_user_calling_plans/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,13 @@ | ||
resource "zoom_phone_user" "example" { | ||
user_id = "AAggbuS-Q6aXXcsv2wnug" | ||
extension_number = 101 | ||
} | ||
|
||
resource "zoom_phone_user_calling_plans" "example" { | ||
user_id = zoom_phone_user.example.user_id | ||
calling_plans = [ | ||
{ | ||
type = 207 | ||
}, | ||
] | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
88 changes: 88 additions & 0 deletions
88
internal/services/phone/usercallingplans/user_calling_plans_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,88 @@ | ||
package usercallingplans | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
"strconv" | ||
|
||
"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" | ||
lop "github.com/samber/lo/parallel" | ||
) | ||
|
||
func newCrud(client *zoomphone.Client) *crud { | ||
return &crud{ | ||
client: client, | ||
} | ||
} | ||
|
||
type crud struct { | ||
client *zoomphone.Client | ||
} | ||
|
||
func (c *crud) read(ctx context.Context, userID types.String) (*readDto, error) { | ||
ret, err := c.client.PhoneUser(ctx, zoomphone.PhoneUserParams{ | ||
UserId: userID.ValueString(), | ||
}) | ||
if err != nil { | ||
return nil, fmt.Errorf("unable to read phone user: %v", err) | ||
} | ||
|
||
return &readDto{ | ||
callingPlans: lo.Map(ret.CallingPlans, func(v zoomphone.PhoneUserOKCallingPlansItem, _ int) readDtoCallingPlan { | ||
return readDtoCallingPlan{ | ||
callingPlanType: util.FromOptInt(v.Type), | ||
callingPlanName: util.FromOptString(v.Name), | ||
billingAccountID: util.FromOptString(v.BillingAccountID), | ||
} | ||
}), | ||
}, nil | ||
} | ||
|
||
func (c *crud) create(ctx context.Context, dto createDto) (*createdDto, error) { | ||
_, err := c.client.AssignCallingPlan(ctx, zoomphone.NewOptAssignCallingPlanReq(zoomphone.AssignCallingPlanReq{ | ||
CallingPlans: lo.Map(dto.callingPlans, func(v createDtoCallingPlan, _ int) zoomphone.AssignCallingPlanReqCallingPlansItem { | ||
return zoomphone.AssignCallingPlanReqCallingPlansItem{ | ||
Type: util.ToPhoneOptInt(v.callingPlanType), | ||
BillingAccountID: util.ToPhoneOptString(v.billingAccountID), | ||
} | ||
}), | ||
}), zoomphone.AssignCallingPlanParams{ | ||
UserId: dto.userID.ValueString(), | ||
}) | ||
if err != nil { | ||
return nil, fmt.Errorf("unable to create phone user calling plan: %v", err) | ||
} | ||
return &createdDto{}, nil | ||
} | ||
|
||
func (c *crud) delete(ctx context.Context, dto deleteDto) error { | ||
errs := lo.Compact(lop.Map(dto.callingPlans, func(v deleteDtoCallingPlan, _ int) error { | ||
err := c.client.UnassignCallingPlan(ctx, zoomphone.UnassignCallingPlanParams{ | ||
UserId: dto.userID.ValueString(), | ||
PlanType: strconv.Itoa(int(v.callingPlanType.ValueInt32())), | ||
BillingAccountID: util.ToPhoneOptString(v.billingAccountID), | ||
}) | ||
|
||
if err != nil { | ||
var status *zoomphone.ErrorResponseStatusCode | ||
if errors.As(err, &status) { | ||
if status.StatusCode == 404 { | ||
return nil // already deleted | ||
} | ||
} | ||
return fmt.Errorf("unable to delete phone user calling plan: %v", err) | ||
} | ||
|
||
return nil | ||
})) | ||
|
||
if len(errs) > 0 { | ||
return errors.Join(errs...) | ||
} | ||
|
||
return nil | ||
} |
37 changes: 37 additions & 0 deletions
37
internal/services/phone/usercallingplans/user_calling_plans_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,37 @@ | ||
package usercallingplans | ||
|
||
import ( | ||
"github.com/hashicorp/terraform-plugin-framework/types" | ||
) | ||
|
||
type readDto struct { | ||
callingPlans []readDtoCallingPlan | ||
} | ||
|
||
type readDtoCallingPlan struct { | ||
callingPlanType types.Int32 | ||
callingPlanName types.String | ||
billingAccountID types.String | ||
} | ||
|
||
type createDto struct { | ||
userID types.String | ||
callingPlans []createDtoCallingPlan | ||
} | ||
|
||
type createDtoCallingPlan struct { | ||
callingPlanType types.Int32 | ||
billingAccountID types.String | ||
} | ||
|
||
type createdDto struct{} | ||
|
||
type deleteDto struct { | ||
userID types.String | ||
callingPlans []deleteDtoCallingPlan | ||
} | ||
|
||
type deleteDtoCallingPlan struct { | ||
callingPlanType types.Int32 | ||
billingAccountID types.String | ||
} |
Oops, something went wrong.