Skip to content

Commit

Permalink
Fixes DEVTOOLING-851 and DEVTOOLING-848 for genesyscloud_telephony_pr…
Browse files Browse the repository at this point in the history
…oviders_edges_site_outbound_route (#1261)

* Adds a data resource for genesyscloud_telephony_providers_edges_site_outbound_route and unit tests

* Add required permissions to PR Labeler (see https://github.com/TimonVS/pr-labeler-action?tab=readme-ov-file#usage )

* Refactor the telephony_providers_edges_site_outbound_route resource to require individual instances of the resource per route. Adds a data resource too. Updates the docs

* Add handling for including site_id attribute on data resource

* Feature toggle check recommendation as per PR comment

* Fix caching issue

* Fix issue from PR comment: remove item from cache after deleting
  • Loading branch information
bbbco authored Sep 30, 2024
1 parent 86257a1 commit 3e4976f
Show file tree
Hide file tree
Showing 14 changed files with 771 additions and 441 deletions.
29 changes: 29 additions & 0 deletions docs/data-sources/telephony_providers_edges_site_outbound_route.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "genesyscloud_telephony_providers_edges_site_outbound_route Data Source - terraform-provider-genesyscloud"
subcategory: ""
description: |-
Data source for Genesys Cloud Site Outbound Routes. Select a Site Outbound Route by name.
---

# genesyscloud_telephony_providers_edges_site_outbound_route (Data Source)

Data source for Genesys Cloud Site Outbound Routes. Select a Site Outbound Route by name.



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

### Required

- `name` (String) Outbound Route name.

### Optional

- `site_id` (String) Site Id

### Read-Only

- `id` (String) The ID of this resource.
- `route_id` (String) Route Id
78 changes: 42 additions & 36 deletions docs/resources/telephony_providers_edges_site_outbound_route.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,43 @@ Outbound Routes for a Genesys Cloud Site
## API Usage
The following Genesys Cloud APIs are used by this resource. Ensure your OAuth Client has been granted the necessary scopes and permissions to perform these operations:

* [GET /api/v2/telephony/providers/edges/sites](https://developer.genesys.cloud/api/rest/v2/telephonyprovidersedge/#get-api-v2-telephony-providers-edges-sites)
* [GET /api/v2/telephony/providers/edges/sites/{siteId}/outboundroutes](https://developer.genesys.cloud/api/rest/v2/telephonyprovidersedge/#get-api-v2-telephony-providers-edges-sites--siteId--outboundroutes)
* [POST /api/v2/telephony/providers/edges/sites/{siteId}/outboundroutes](https://developer.genesys.cloud/api/rest/v2/telephonyprovidersedge/#post-api-v2-telephony-providers-edges-sites--siteId--outboundroutes)
* [DELETE /api/v2/telephony/providers/edges/sites/{siteId}/outboundroutes/{outboundRouteId}](https://developer.genesys.cloud/api/rest/v2/telephonyprovidersedge/#delete-api-v2-telephony-providers-edges-sites--siteId--outboundroutes--outboundRouteId-)
* [PUT /api/v2/telephony/providers/edges/sites/{siteId}/outboundroutes/{outboundRouteId}](https://developer.genesys.cloud/api/rest/v2/telephonyprovidersedge/#put-api-v2-telephony-providers-edges-sites--siteId--outboundroutes--outboundRouteId-)
- [GET /api/v2/telephony/providers/edges/sites](https://developer.genesys.cloud/api/rest/v2/telephonyprovidersedge/#get-api-v2-telephony-providers-edges-sites)
- [GET /api/v2/telephony/providers/edges/sites/{siteId}/outboundroutes](https://developer.genesys.cloud/api/rest/v2/telephonyprovidersedge/#get-api-v2-telephony-providers-edges-sites--siteId--outboundroutes)
- [POST /api/v2/telephony/providers/edges/sites/{siteId}/outboundroutes](https://developer.genesys.cloud/api/rest/v2/telephonyprovidersedge/#post-api-v2-telephony-providers-edges-sites--siteId--outboundroutes)
- [DELETE /api/v2/telephony/providers/edges/sites/{siteId}/outboundroutes/{outboundRouteId}](https://developer.genesys.cloud/api/rest/v2/telephonyprovidersedge/#delete-api-v2-telephony-providers-edges-sites--siteId--outboundroutes--outboundRouteId-)
- [PUT /api/v2/telephony/providers/edges/sites/{siteId}/outboundroutes/{outboundRouteId}](https://developer.genesys.cloud/api/rest/v2/telephonyprovidersedge/#put-api-v2-telephony-providers-edges-sites--siteId--outboundroutes--outboundRouteId-)

#### Compatibility Note

In versions 1.39.0 to 1.48.0 of the provider, this resource was constructed with a different structure. The current version introduces structural changes that are not backwards compatible with those earlier versions.

These changes are currently controlled by a feature flag and are not yet the default behavior. This allows for a phased implementation and thorough testing of this resource before full release.

If you're upgrading from an earlier version, please be aware of these structural changes and consult these examples on how to migrate your configuration.


## Example Usage

```terraform
// To enable this resource, set ENABLE_STANDALONE_OUTBOUND_ROUTES as an environment variable
resource "genesyscloud_telephony_providers_edges_site_outbound_routes" "site1-routes" {
site_id = genesyscloud_telephony_providers_edges_site.site1.id
outbound_routes {
name = "outboundRoute 1"
description = "outboundRoute description"
classification_types = ["International", "National"]
external_trunk_base_ids = [genesyscloud_telephony_providers_edges_trunkbasesettings.trunk-base-settings1.id]
distribution = "RANDOM"
enabled = false
}
outbound_routes {
name = "outboundRoute 2"
description = "outboundRoute description"
classification_types = ["Network"]
external_trunk_base_ids = [genesyscloud_telephony_providers_edges_trunkbasesettings.trunk-base-settings2.id]
distribution = "SEQUENTIAL"
enabled = true
}
resource "genesyscloud_telephony_providers_edges_site_outbound_routes" "site1-route1" {
site_id = genesyscloud_telephony_providers_edges_site.site1.id
name = "outboundRoute 1"
description = "outboundRoute description"
classification_types = ["International", "National"]
external_trunk_base_ids = [genesyscloud_telephony_providers_edges_trunkbasesettings.trunk-base-settings1.id]
distribution = "RANDOM"
enabled = false
}
resource "genesyscloud_telephony_providers_edges_site_outbound_routes" "site1-route2" {
site_id = genesyscloud_telephony_providers_edges_site.site1.id
name = "outboundRoute 2"
description = "outboundRoute description"
classification_types = ["Network"]
external_trunk_base_ids = [genesyscloud_telephony_providers_edges_trunkbasesettings.trunk-base-settings2.id]
distribution = "SEQUENTIAL"
enabled = true
}
```

Expand All @@ -47,22 +56,19 @@ resource "genesyscloud_telephony_providers_edges_site_outbound_routes" "site1-ro

### Required

- `outbound_routes` (Set of Object) Outbound Routes for the site. The default outbound route for the site will be deleted if routes are specified (see [below for nested schema](#nestedatt--outbound_routes))
- `classification_types` (List of String) Used to classify this outbound route.
- `name` (String) The name of the entity.
- `site_id` (String) The Id of the site to which the outbound routes belong.

### Read-Only

- `id` (String) The ID of this resource.
### Optional

<a id="nestedatt--outbound_routes"></a>
### Nested Schema for `outbound_routes`
- `description` (String) The resource's description.
- `distribution` (String) Valid values: SEQUENTIAL, RANDOM. Defaults to `SEQUENTIAL`.
- `enabled` (Boolean) Enable or disable the outbound route Defaults to `false`.
- `external_trunk_base_ids` (List of String) Trunk base settings of trunkType "EXTERNAL". This base must also be set on an edge logical interface for correct routing. The order of the IDs determines the distribution if "distribution" is set to "SEQUENTIAL"

Required:
### Read-Only

- `classification_types` (List of String)
- `description` (String)
- `distribution` (String)
- `enabled` (Boolean)
- `external_trunk_base_ids` (List of String)
- `name` (String)
- `id` (String) The ID of this resource.
- `route_id` (String) The Id of the outbound route. This is distinct from the "id" field. The "id" field is a combination of the site_id and route_id

Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
* [GET /api/v2/telephony/providers/edges/sites](https://developer.genesys.cloud/api/rest/v2/telephonyprovidersedge/#get-api-v2-telephony-providers-edges-sites)
* [GET /api/v2/telephony/providers/edges/sites/{siteId}/outboundroutes](https://developer.genesys.cloud/api/rest/v2/telephonyprovidersedge/#get-api-v2-telephony-providers-edges-sites--siteId--outboundroutes)
* [POST /api/v2/telephony/providers/edges/sites/{siteId}/outboundroutes](https://developer.genesys.cloud/api/rest/v2/telephonyprovidersedge/#post-api-v2-telephony-providers-edges-sites--siteId--outboundroutes)
* [DELETE /api/v2/telephony/providers/edges/sites/{siteId}/outboundroutes/{outboundRouteId}](https://developer.genesys.cloud/api/rest/v2/telephonyprovidersedge/#delete-api-v2-telephony-providers-edges-sites--siteId--outboundroutes--outboundRouteId-)
* [PUT /api/v2/telephony/providers/edges/sites/{siteId}/outboundroutes/{outboundRouteId}](https://developer.genesys.cloud/api/rest/v2/telephonyprovidersedge/#put-api-v2-telephony-providers-edges-sites--siteId--outboundroutes--outboundRouteId-)
- [GET /api/v2/telephony/providers/edges/sites](https://developer.genesys.cloud/api/rest/v2/telephonyprovidersedge/#get-api-v2-telephony-providers-edges-sites)
- [GET /api/v2/telephony/providers/edges/sites/{siteId}/outboundroutes](https://developer.genesys.cloud/api/rest/v2/telephonyprovidersedge/#get-api-v2-telephony-providers-edges-sites--siteId--outboundroutes)
- [POST /api/v2/telephony/providers/edges/sites/{siteId}/outboundroutes](https://developer.genesys.cloud/api/rest/v2/telephonyprovidersedge/#post-api-v2-telephony-providers-edges-sites--siteId--outboundroutes)
- [DELETE /api/v2/telephony/providers/edges/sites/{siteId}/outboundroutes/{outboundRouteId}](https://developer.genesys.cloud/api/rest/v2/telephonyprovidersedge/#delete-api-v2-telephony-providers-edges-sites--siteId--outboundroutes--outboundRouteId-)
- [PUT /api/v2/telephony/providers/edges/sites/{siteId}/outboundroutes/{outboundRouteId}](https://developer.genesys.cloud/api/rest/v2/telephonyprovidersedge/#put-api-v2-telephony-providers-edges-sites--siteId--outboundroutes--outboundRouteId-)

#### Compatibility Note

In versions 1.39.0 to 1.48.0 of the provider, this resource was constructed with a different structure. The current version introduces structural changes that are not backwards compatible with those earlier versions.

These changes are currently controlled by a feature flag and are not yet the default behavior. This allows for a phased implementation and thorough testing of this resource before full release.

If you're upgrading from an earlier version, please be aware of these structural changes and consult these examples on how to migrate your configuration.
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
// To enable this resource, set ENABLE_STANDALONE_OUTBOUND_ROUTES as an environment variable
resource "genesyscloud_telephony_providers_edges_site_outbound_routes" "site1-routes" {
site_id = genesyscloud_telephony_providers_edges_site.site1.id
outbound_routes {
name = "outboundRoute 1"
description = "outboundRoute description"
classification_types = ["International", "National"]
external_trunk_base_ids = [genesyscloud_telephony_providers_edges_trunkbasesettings.trunk-base-settings1.id]
distribution = "RANDOM"
enabled = false
}
outbound_routes {
name = "outboundRoute 2"
description = "outboundRoute description"
classification_types = ["Network"]
external_trunk_base_ids = [genesyscloud_telephony_providers_edges_trunkbasesettings.trunk-base-settings2.id]
distribution = "SEQUENTIAL"
enabled = true
}
}
resource "genesyscloud_telephony_providers_edges_site_outbound_routes" "site1-route1" {
site_id = genesyscloud_telephony_providers_edges_site.site1.id
name = "outboundRoute 1"
description = "outboundRoute description"
classification_types = ["International", "National"]
external_trunk_base_ids = [genesyscloud_telephony_providers_edges_trunkbasesettings.trunk-base-settings1.id]
distribution = "RANDOM"
enabled = false
}

resource "genesyscloud_telephony_providers_edges_site_outbound_routes" "site1-route2" {
site_id = genesyscloud_telephony_providers_edges_site.site1.id
name = "outboundRoute 2"
description = "outboundRoute description"
classification_types = ["Network"]
external_trunk_base_ids = [genesyscloud_telephony_providers_edges_trunkbasesettings.trunk-base-settings2.id]
distribution = "SEQUENTIAL"
enabled = true
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func dataSourceSiteRead(ctx context.Context, d *schema.ResourceData, m interface
name := d.Get("name").(string)

return util.WithRetries(ctx, 15*time.Second, func() *retry.RetryError {
siteId, retryable, resp, err := sp.getSiteIdByName(ctx, name)
siteId, retryable, resp, err := sp.GetSiteIdByName(ctx, name)
if err != nil {
if retryable {
return retry.RetryableError(util.BuildWithRetriesApiDiagnosticError(resourceName, fmt.Sprintf("failed to get site %s", name), resp))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func (p *SiteProxy) getSiteById(ctx context.Context, siteId string) (site *platf
}

// getSiteIdByNameFunc returns a single Genesys Cloud Site by Name
func (p *SiteProxy) getSiteIdByName(ctx context.Context, siteName string) (siteId string, retryable bool, resp *platformclientv2.APIResponse, err error) {
func (p *SiteProxy) GetSiteIdByName(ctx context.Context, siteName string) (siteId string, retryable bool, resp *platformclientv2.APIResponse, err error) {
return p.getSiteIdByNameAttr(ctx, p, siteName)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package telephony_providers_edges_site_outbound_route

import (
"context"
"fmt"
"terraform-provider-genesyscloud/genesyscloud/provider"
"terraform-provider-genesyscloud/genesyscloud/util"
featureToggles "terraform-provider-genesyscloud/genesyscloud/util/feature_toggles"
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func dataSourceSiteOutboundRouteRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
if exists := featureToggles.OutboundRoutesToggleExists(); !exists {
return util.BuildDiagnosticError(resourceName, fmt.Sprintf("Environment variable %s not set", featureToggles.OutboundRoutesToggleName()), fmt.Errorf("environment variable %s not set", featureToggles.OutboundRoutesToggleName()))
}
sdkConfig := m.(*provider.ProviderMeta).ClientConfig
proxy := getSiteOutboundRouteProxy(sdkConfig)

name := d.Get("name").(string)
siteId := d.Get("site_id").(string)

return util.WithRetries(ctx, 15*time.Second, func() *retry.RetryError {
siteId, routeId, retryable, resp, err := proxy.getSiteOutboundRouteByName(ctx, name, siteId)
if err != nil {
if retryable {
return retry.RetryableError(util.BuildWithRetriesApiDiagnosticError(resourceName, fmt.Sprintf("failed to get outbound route %s", name), resp))
}

return retry.NonRetryableError(util.BuildWithRetriesApiDiagnosticError(resourceName, fmt.Sprintf("error requesting outbound route %s | error: %s", name, err), resp))
}

outboundRouteId := buildSiteAndOutboundRouteId(siteId, routeId)

d.SetId(outboundRouteId)
d.Set("site_id", siteId)
d.Set("route_id", routeId)
return nil
})
}
Loading

0 comments on commit 3e4976f

Please sign in to comment.