-
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_external_contact (#41)
Signed-off-by: krrrr38 <k.kaizu38@gmail.com>
- Loading branch information
Showing
12 changed files
with
616 additions
and
4 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,70 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "zoom_phone_external_contact Resource - zoom" | ||
subcategory: "" | ||
description: |- | ||
External contact's information. | ||
API Permissions | ||
The following API permissions are required in order to use this resource. | ||
This resource requires the phone:read:external_contact:admin, phone:write:external_contact:admin, phone:update:external_contact:admin, phone:delete:external_contact:admin. | ||
--- | ||
|
||
# zoom_phone_external_contact (Resource) | ||
|
||
External contact's information. | ||
|
||
## API Permissions | ||
The following API permissions are required in order to use this resource. | ||
This resource requires the `phone:read:external_contact:admin`, `phone:write:external_contact:admin`, `phone:update:external_contact:admin`, `phone:delete:external_contact:admin`. | ||
|
||
## Example Usage | ||
|
||
```terraform | ||
resource "zoom_phone_external_contact" "example" { | ||
id = "4gAYcVCwTUGGDpYWdFpXxx" | ||
name = "Example" | ||
description = "Description" | ||
email = "example@example.com" | ||
phone_numbers = [ | ||
"+0123456789", | ||
] | ||
auto_call_recorded = true | ||
} | ||
resource "zoom_phone_external_contact" "other" { | ||
name = "Other" | ||
phone_numbers = [ | ||
"+0123456789", | ||
] | ||
} | ||
``` | ||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `name` (String) The external contact's username or extension display name. | ||
- `phone_numbers` (Set of String) The external contact's phone numbers. This value must be in [E.164](https://en.wikipedia.org/wiki/E.164) format. If you do not provide an extension number, you must provide this value. | ||
|
||
### Optional | ||
|
||
- `auto_call_recorded` (Boolean) Whether to allow the automatic call recording. | ||
- `description` (String) The external contact's description. | ||
- `email` (String) The external contact's email address. | ||
- `extension_number` (String) The external contact's extension number. | ||
- `id` (String) The customer-configured external contact ID. It is recommended that you use a primary key from the original phone system. If you do not use this parameter, the API automatically generates an `external_contact_id`. | ||
- `routing_path` (String) The external contact's SIP group, to define the call routing path. This is for customers that use SIP trunking. | ||
|
||
### Read-Only | ||
|
||
- `external_contact_id` (String) The Zoom-generated external contact ID. | ||
|
||
## Import | ||
|
||
Import is supported using the following syntax: | ||
|
||
```shell | ||
# ${external_contact_id} | ||
terraform import zoom_phone_external_contact.example lSq8jyDORe6tmbaUkOVhXx | ||
``` |
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 @@ | ||
# ${external_contact_id} | ||
terraform import zoom_phone_external_contact.example lSq8jyDORe6tmbaUkOVhXx |
22 changes: 22 additions & 0 deletions
22
examples/resources/zoom_phone_external_contact/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_external_contact/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_external_contact" "example" { | ||
id = "4gAYcVCwTUGGDpYWdFpXxx" | ||
name = "Example" | ||
description = "Description" | ||
email = "example@example.com" | ||
phone_numbers = [ | ||
"+0123456789", | ||
] | ||
auto_call_recorded = true | ||
} | ||
|
||
resource "zoom_phone_external_contact" "other" { | ||
name = "Other" | ||
phone_numbers = [ | ||
"+0123456789", | ||
] | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
118 changes: 118 additions & 0 deletions
118
internal/services/phone/externalcontact/external_contact_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,118 @@ | ||
package externalcontact | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
"github.com/samber/lo" | ||
|
||
"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" | ||
) | ||
|
||
func newCrud(client *zoomphone.Client) *crud { | ||
return &crud{ | ||
client: client, | ||
} | ||
} | ||
|
||
type crud struct { | ||
client *zoomphone.Client | ||
} | ||
|
||
func (c *crud) read(ctx context.Context, externalContactID types.String) (*readDto, error) { | ||
detail, err := c.client.GetAExternalContact(ctx, zoomphone.GetAExternalContactParams{ | ||
ExternalContactId: externalContactID.ValueString(), | ||
}) | ||
if err != nil { | ||
var status *zoomphone.ErrorResponseStatusCode | ||
if errors.As(err, &status) { | ||
if status.StatusCode == 400 && status.Response.Code.Value == 300 { | ||
return nil, nil // already deleted | ||
} | ||
} | ||
return nil, fmt.Errorf("unable to read phone external contact: %v", err) | ||
} | ||
|
||
return &readDto{ | ||
description: util.FromOptString(detail.Description), | ||
email: util.FromOptString(detail.Email), | ||
extensionNumber: util.FromOptString(detail.ExtensionNumber), | ||
externalContactID: util.FromOptString(detail.ExternalContactID), | ||
id: util.FromOptString(detail.ID), | ||
name: util.FromOptString(detail.Name), | ||
phoneNumbers: lo.Map(detail.PhoneNumbers, func(item string, index int) types.String { | ||
return types.StringValue(item) | ||
}), | ||
routingPath: util.FromOptString(detail.RoutingPath), | ||
autoCallRecorded: util.FromOptBool(detail.AutoCallRecorded), | ||
}, nil | ||
} | ||
|
||
func (c *crud) create(ctx context.Context, dto *createDto) (*createdDto, error) { | ||
res, err := c.client.AddExternalContact(ctx, zoomphone.OptAddExternalContactReq{ | ||
Value: zoomphone.AddExternalContactReq{ | ||
Description: util.ToPhoneOptString(dto.description), | ||
Email: util.ToPhoneOptString(dto.email), | ||
ExtensionNumber: util.ToPhoneOptString(dto.extensionNumber), | ||
ID: util.ToPhoneOptString(dto.id), | ||
Name: dto.name.ValueString(), | ||
PhoneNumbers: lo.Map(dto.phoneNumbers, func(item types.String, index int) string { | ||
return item.ValueString() | ||
}), | ||
RoutingPath: util.ToPhoneOptString(dto.routingPath), | ||
AutoCallRecorded: util.ToPhoneOptBool(dto.autoCallRecorded), | ||
}, | ||
Set: true, | ||
}) | ||
if err != nil { | ||
return nil, fmt.Errorf("error creating phone external contact: %v", err) | ||
} | ||
|
||
return &createdDto{ | ||
externalContactID: util.FromOptString(res.ExternalContactID), | ||
}, nil | ||
} | ||
|
||
func (c *crud) update(ctx context.Context, dto *updateDto) error { | ||
err := c.client.UpdateExternalContact(ctx, zoomphone.OptUpdateExternalContactReq{ | ||
Value: zoomphone.UpdateExternalContactReq{ | ||
Description: util.ToPhoneOptString(dto.description), | ||
Email: util.ToPhoneOptString(dto.email), | ||
ExtensionNumber: util.ToPhoneOptString(dto.extensionNumber), | ||
ID: util.ToPhoneOptString(dto.id), | ||
Name: util.ToPhoneOptString(dto.name), | ||
PhoneNumbers: lo.Map(dto.phoneNumbers, func(item types.String, index int) string { | ||
return item.ValueString() | ||
}), | ||
RoutingPath: util.ToPhoneOptString(dto.routingPath), | ||
AutoCallRecorded: util.ToPhoneOptBool(dto.autoCallRecorded), | ||
}, | ||
Set: true, | ||
}, zoomphone.UpdateExternalContactParams{ | ||
ExternalContactId: dto.externalContactID.ValueString(), | ||
}) | ||
if err != nil { | ||
return fmt.Errorf("error updating phone external contact: %v", err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (c *crud) delete(ctx context.Context, externalContactId types.String) error { | ||
err := c.client.DeleteAExternalContact(ctx, zoomphone.DeleteAExternalContactParams{ | ||
ExternalContactId: externalContactId.ValueString(), | ||
}) | ||
if err != nil { | ||
var status *zoomphone.ErrorResponseStatusCode | ||
if errors.As(err, &status) { | ||
if status.StatusCode == 400 && status.Response.Code.Value == 300 { | ||
return nil | ||
} | ||
} | ||
return fmt.Errorf("error deleting phone external contact: %v", err) | ||
} | ||
|
||
return nil | ||
} |
43 changes: 43 additions & 0 deletions
43
internal/services/phone/externalcontact/external_contact_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,43 @@ | ||
package externalcontact | ||
|
||
import "github.com/hashicorp/terraform-plugin-framework/types" | ||
|
||
type readDto struct { | ||
description types.String | ||
email types.String | ||
extensionNumber types.String | ||
externalContactID types.String | ||
id types.String | ||
name types.String | ||
phoneNumbers []types.String | ||
routingPath types.String | ||
autoCallRecorded types.Bool | ||
} | ||
|
||
type createDto struct { | ||
description types.String | ||
email types.String | ||
extensionNumber types.String | ||
externalContactID types.String | ||
id types.String | ||
name types.String | ||
phoneNumbers []types.String | ||
routingPath types.String | ||
autoCallRecorded types.Bool | ||
} | ||
|
||
type createdDto struct { | ||
externalContactID types.String | ||
} | ||
|
||
type updateDto struct { | ||
externalContactID types.String | ||
description types.String | ||
email types.String | ||
extensionNumber types.String | ||
id types.String | ||
name types.String | ||
phoneNumbers []types.String | ||
routingPath types.String | ||
autoCallRecorded types.Bool | ||
} |
Oops, something went wrong.