From c4182e32bacaf4dd0679c41f2df56886bafced16 Mon Sep 17 00:00:00 2001 From: shrutisuryawanshigenesys Date: Mon, 29 Jul 2024 11:42:27 -0400 Subject: [PATCH] feat/Devtooling 712 resource for supported content (#1159) * resource and test cases added for supported content * updated resource testcase and added datasource testcase * updated docs * added example folder * added example folder * updated docs * updated testcase for datasource * resolved comments * updated docs * changed resource name * changed resource file names * changed resource file names * comments resolved * updatd docs * cache added for data source * resolved merge conflict * comments resolved * updated docs * comments resolved --- ...onversations_messaging_supportedcontent.md | 30 +++ ...onversations_messaging_supportedcontent.md | 84 +++++++++ .../data-source.tf | 3 + .../apis.md | 6 + .../resource.tf | 13 ++ ...onversations_messaging_supportedcontent.go | 108 +++++++++++ ...sations_messaging_supportedcontent_test.go | 65 +++++++ ...ns_messaging_supportedcontent_init_test.go | 60 ++++++ ...ations_messaging_supportedcontent_proxy.go | 177 ++++++++++++++++++ ...onversations_messaging_supportedcontent.go | 127 +++++++++++++ ...tions_messaging_supportedcontent_schema.go | 124 ++++++++++++ ...sations_messaging_supportedcontent_test.go | 134 +++++++++++++ ...ations_messaging_supportedcontent_utils.go | 117 ++++++++++++ .../tfexporter/tf_exporter_resource_test.go | 6 + main.go | 10 +- 15 files changed, 1060 insertions(+), 4 deletions(-) create mode 100644 docs/data-sources/conversations_messaging_supportedcontent.md create mode 100644 docs/resources/conversations_messaging_supportedcontent.md create mode 100644 examples/data-sources/genesyscloud_conversations_messaging_supportedcontent/data-source.tf create mode 100644 examples/resources/genesyscloud_conversations_messaging_supportedcontent/apis.md create mode 100644 examples/resources/genesyscloud_conversations_messaging_supportedcontent/resource.tf create mode 100644 genesyscloud/conversations_messaging_supportedcontent/data_source_genesyscloud_conversations_messaging_supportedcontent.go create mode 100644 genesyscloud/conversations_messaging_supportedcontent/data_source_genesyscloud_conversations_messaging_supportedcontent_test.go create mode 100644 genesyscloud/conversations_messaging_supportedcontent/genesyscloud_conversations_messaging_supportedcontent_init_test.go create mode 100644 genesyscloud/conversations_messaging_supportedcontent/genesyscloud_conversations_messaging_supportedcontent_proxy.go create mode 100644 genesyscloud/conversations_messaging_supportedcontent/resource_genesyscloud_conversations_messaging_supportedcontent.go create mode 100644 genesyscloud/conversations_messaging_supportedcontent/resource_genesyscloud_conversations_messaging_supportedcontent_schema.go create mode 100644 genesyscloud/conversations_messaging_supportedcontent/resource_genesyscloud_conversations_messaging_supportedcontent_test.go create mode 100644 genesyscloud/conversations_messaging_supportedcontent/resource_genesyscloud_conversations_messaging_supportedcontent_utils.go diff --git a/docs/data-sources/conversations_messaging_supportedcontent.md b/docs/data-sources/conversations_messaging_supportedcontent.md new file mode 100644 index 000000000..527449294 --- /dev/null +++ b/docs/data-sources/conversations_messaging_supportedcontent.md @@ -0,0 +1,30 @@ +--- +# generated by https://github.com/hashicorp/terraform-plugin-docs +page_title: "genesyscloud_conversations_messaging_supportedcontent Data Source - terraform-provider-genesyscloud" +subcategory: "" +description: |- + Genesys Cloud supported content data source. Select an supported content by name +--- + +# genesyscloud_conversations_messaging_supportedcontent (Data Source) + +Genesys Cloud supported content data source. Select an supported content by name + +## Example Usage + +```terraform +data "genesyscloud_conversations_messaging_supportedcontent" "supported_content" { + name = "Test Supported Content" +} +``` + + +## Schema + +### Required + +- `name` (String) supported content name + +### Read-Only + +- `id` (String) The ID of this resource. diff --git a/docs/resources/conversations_messaging_supportedcontent.md b/docs/resources/conversations_messaging_supportedcontent.md new file mode 100644 index 000000000..19532b950 --- /dev/null +++ b/docs/resources/conversations_messaging_supportedcontent.md @@ -0,0 +1,84 @@ +--- +page_title: "genesyscloud_conversations_messaging_supportedcontent Resource - terraform-provider-genesyscloud" +subcategory: "" +description: |- + Genesys Cloud supported content +--- +# genesyscloud_conversations_messaging_supportedcontent (Resource) + +Genesys Cloud supported content + +## 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: + +* [POST /api/v2/conversations/messaging/supportedcontent](https://developer.genesys.cloud/devapps/api-explorer#post-api-v2-conversations-messaging-supportedcontent) +* [GET /api/v2/conversations/messaging/supportedcontent/{supportedContentId}](https://developer.genesys.cloud/devapps/api-explorer#get-api-v2-conversations-messaging-supportedcontent--supportedContentId-) +* [PATCH /api/v2/conversations/messaging/supportedcontent/{supportedContentId}](https://developer.genesys.cloud/devapps/api-explorer#patch-api-v2-conversations-messaging-supportedcontent--supportedContentId-) +* [DELETE /api/v2/conversations/messaging/supportedcontent/{supportedContentId}](https://developer.genesys.cloud/devapps/api-explorer#delete-api-v2-conversations-messaging-supportedcontent--supportedContentId-) +* [GET /api/v2/conversations/messaging/supportedcontent](https://developer.genesys.cloud/devapps/api-explorer#get-api-v2-conversations-messaging-supportedcontent) + + + +## Example Usage + +```terraform +resource "genesyscloud_conversations_messaging_supportedcontent" "supported_content" { + name = "test supported_content" + media_types { + allow { + inbound { + type = "image/*" + } + outbound { + type = "video/mpeg" + } + } + } +} +``` + + +## Schema + +### Required + +- `name` (String) The name of the supported content profile + +### Optional + +- `media_types` (Block List, Max: 1) Defines the allowable media that may be accepted for an inbound message or to be sent in an outbound message. (see [below for nested schema](#nestedblock--media_types)) + +### Read-Only + +- `id` (String) The ID of this resource. + + +### Nested Schema for `media_types` + +Optional: + +- `allow` (Block List, Max: 1) Specify allowed media types for inbound and outbound messages. If this field is empty, all inbound and outbound media will be blocked. (see [below for nested schema](#nestedblock--media_types--allow)) + + +### Nested Schema for `media_types.allow` + +Optional: + +- `inbound` (Block List) List of media types allowed for inbound messages from customers. If inbound messages from a customer contain media that is not in this list, the media will be dropped from the outbound message. (see [below for nested schema](#nestedblock--media_types--allow--inbound)) +- `outbound` (Block List) List of media types allowed for outbound messages to customers. If an outbound message is sent that contains media that is not in this list, the message will not be sent. (see [below for nested schema](#nestedblock--media_types--allow--outbound)) + + +### Nested Schema for `media_types.allow.inbound` + +Optional: + +- `type` (String) The media type string as defined by RFC 2046. You can define specific types such as 'image/jpeg', 'video/mpeg', or specify wild cards for a range of types, 'image/*', or all types '*/*'. See https://www.iana.org/assignments/media-types/media-types.xhtml for a list of registered media types. + + + +### Nested Schema for `media_types.allow.outbound` + +Optional: + +- `type` (String) The media type string as defined by RFC 2046. You can define specific types such as 'image/jpeg', 'video/mpeg', or specify wild cards for a range of types, 'image/*', or all types '*/*'. See https://www.iana.org/assignments/media-types/media-types.xhtml for a list of registered media types. + diff --git a/examples/data-sources/genesyscloud_conversations_messaging_supportedcontent/data-source.tf b/examples/data-sources/genesyscloud_conversations_messaging_supportedcontent/data-source.tf new file mode 100644 index 000000000..4acdff150 --- /dev/null +++ b/examples/data-sources/genesyscloud_conversations_messaging_supportedcontent/data-source.tf @@ -0,0 +1,3 @@ +data "genesyscloud_conversations_messaging_supportedcontent" "supported_content" { + name = "Test Supported Content" +} \ No newline at end of file diff --git a/examples/resources/genesyscloud_conversations_messaging_supportedcontent/apis.md b/examples/resources/genesyscloud_conversations_messaging_supportedcontent/apis.md new file mode 100644 index 000000000..eb98a2fda --- /dev/null +++ b/examples/resources/genesyscloud_conversations_messaging_supportedcontent/apis.md @@ -0,0 +1,6 @@ +* [POST /api/v2/conversations/messaging/supportedcontent](https://developer.genesys.cloud/devapps/api-explorer#post-api-v2-conversations-messaging-supportedcontent) +* [GET /api/v2/conversations/messaging/supportedcontent/{supportedContentId}](https://developer.genesys.cloud/devapps/api-explorer#get-api-v2-conversations-messaging-supportedcontent--supportedContentId-) +* [PATCH /api/v2/conversations/messaging/supportedcontent/{supportedContentId}](https://developer.genesys.cloud/devapps/api-explorer#patch-api-v2-conversations-messaging-supportedcontent--supportedContentId-) +* [DELETE /api/v2/conversations/messaging/supportedcontent/{supportedContentId}](https://developer.genesys.cloud/devapps/api-explorer#delete-api-v2-conversations-messaging-supportedcontent--supportedContentId-) +* [GET /api/v2/conversations/messaging/supportedcontent](https://developer.genesys.cloud/devapps/api-explorer#get-api-v2-conversations-messaging-supportedcontent) + diff --git a/examples/resources/genesyscloud_conversations_messaging_supportedcontent/resource.tf b/examples/resources/genesyscloud_conversations_messaging_supportedcontent/resource.tf new file mode 100644 index 000000000..2f0c04fe0 --- /dev/null +++ b/examples/resources/genesyscloud_conversations_messaging_supportedcontent/resource.tf @@ -0,0 +1,13 @@ +resource "genesyscloud_conversations_messaging_supportedcontent" "supported_content" { + name = "test supported_content" + media_types { + allow { + inbound { + type = "image/*" + } + outbound { + type = "video/mpeg" + } + } + } +} \ No newline at end of file diff --git a/genesyscloud/conversations_messaging_supportedcontent/data_source_genesyscloud_conversations_messaging_supportedcontent.go b/genesyscloud/conversations_messaging_supportedcontent/data_source_genesyscloud_conversations_messaging_supportedcontent.go new file mode 100644 index 000000000..7716d0663 --- /dev/null +++ b/genesyscloud/conversations_messaging_supportedcontent/data_source_genesyscloud_conversations_messaging_supportedcontent.go @@ -0,0 +1,108 @@ +package conversations_messaging_supportedcontent + +import ( + "context" + "fmt" + "log" + "time" + + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/mypurecloud/platform-client-sdk-go/v133/platformclientv2" + + "terraform-provider-genesyscloud/genesyscloud/provider" + rc "terraform-provider-genesyscloud/genesyscloud/resource_cache" + "terraform-provider-genesyscloud/genesyscloud/util" +) + +/* + The data_source_genesyscloud_conversations_messaging_supportedcontent.go contains the data source implementation + for the resource. +*/ + +// dataSourceSupportedContentRead retrieves by name the id in question +func dataSourceSupportedContentRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + sdkConfig := meta.(*provider.ProviderMeta).ClientConfig + + key := "" + + key = d.Get("name").(string) + + if dataSourceSupportedContentCache == nil { + dataSourceSupportedContentCache = rc.NewDataSourceCache(sdkConfig, hydrateSupportedContentCacheFn, getSupportedContentIdByName) + } + + contentId, err := rc.RetrieveId(dataSourceSupportedContentCache, resourceName, key, ctx) + if err != nil { + return err + } + + d.SetId(contentId) + return nil +} + +var ( + dataSourceSupportedContentCache *rc.DataSourceCache +) + +func hydrateSupportedContentCacheFn(c *rc.DataSourceCache) error { + log.Printf("hydrating cache for data source " + resourceName) + supportContentApi := platformclientv2.NewConversationsApiWithConfig(c.ClientConfig) + + const pageSize = 100 + + supportedContents, _, err := supportContentApi.GetConversationsMessagingSupportedcontent(pageSize, 1) + if err != nil { + return fmt.Errorf("Failed to get supported content: %v", err) + } + if supportedContents.Entities == nil || len(*supportedContents.Entities) == 0 { + return nil + } + + for _, supportedContent := range *supportedContents.Entities { + c.Cache[*supportedContent.Name] = *supportedContent.Id + } + + for pageNum := 2; pageNum <= *supportedContents.PageCount; pageNum++ { + supportedContents, _, err := supportContentApi.GetConversationsMessagingSupportedcontent(pageSize, pageNum) + + log.Printf("hydrating cache for data source genesyscloud_conversations_messaging_supportedcontent with page number: %v", pageNum) + if err != nil { + return fmt.Errorf("Failed to get supported content: %v", err) + } + + if supportedContents.Entities == nil || len(*supportedContents.Entities) == 0 { + break + } + + // Add ids to cache + for _, supportedContent := range *supportedContents.Entities { + c.Cache[*supportedContent.Name] = *supportedContent.Id + } + } + log.Printf("cache hydration completed for data source " + resourceName) + + return nil +} + +func getSupportedContentIdByName(c *rc.DataSourceCache, searchName string, ctx context.Context) (string, diag.Diagnostics) { + proxy := getSupportedContentProxy(c.ClientConfig) + contentId := "" + diag := util.WithRetries(ctx, 15*time.Second, func() *retry.RetryError { + supportedContentId, retryable, resp, err := proxy.getSupportedContentIdByName(ctx, searchName) + + if err != nil && !retryable { + retry.NonRetryableError(util.BuildWithRetriesApiDiagnosticError(resourceName, fmt.Sprintf("Error searching supported content %s: %s", searchName, err), resp)) + } + + if retryable { + retry.RetryableError(util.BuildWithRetriesApiDiagnosticError(resourceName, fmt.Sprintf("No supported content found with name %s", searchName), resp)) + } + + contentId = supportedContentId + return nil + }) + + return contentId, diag +} diff --git a/genesyscloud/conversations_messaging_supportedcontent/data_source_genesyscloud_conversations_messaging_supportedcontent_test.go b/genesyscloud/conversations_messaging_supportedcontent/data_source_genesyscloud_conversations_messaging_supportedcontent_test.go new file mode 100644 index 000000000..0ead65df2 --- /dev/null +++ b/genesyscloud/conversations_messaging_supportedcontent/data_source_genesyscloud_conversations_messaging_supportedcontent_test.go @@ -0,0 +1,65 @@ +package conversations_messaging_supportedcontent + +import ( + "fmt" + "testing" + + "terraform-provider-genesyscloud/genesyscloud/provider" + "terraform-provider-genesyscloud/genesyscloud/util" + + "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +/* +Test Class for the supported content Data Source +*/ + +func TestAccDataSourceSupportedContent(t *testing.T) { + t.Parallel() + var ( + resourceId = "testSupportedContent" + dataSourceId = "testSupportedContent_data" + name = "Terraform Supported Content - " + uuid.NewString() + inboundType = "*/*" + outboundType = "image/*" + ) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { util.TestAccPreCheck(t) }, + ProviderFactories: provider.GetProviderFactories(providerResources, providerDataSources), + Steps: []resource.TestStep{ + { + Config: GenerateSupportedContentResource( + resourceName, + resourceId, + name, + GenerateInboundTypeBlock(inboundType), + GenerateOutboundTypeBlock(outboundType), + ) + + GenerateDataSourceForSupportedContent( + resourceName, + dataSourceId, + name, + "genesyscloud_conversations_messaging_supportedcontent."+resourceId), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrPair("data.genesyscloud_conversations_messaging_supportedcontent."+dataSourceId, "id", "genesyscloud_conversations_messaging_supportedcontent."+resourceId, "id"), + ), + }, + }, + }) +} + +func GenerateDataSourceForSupportedContent( + resourceName string, + resourceId string, + name string, + dependsOn string, +) string { + return fmt.Sprintf(` + data "%s" "%s" { + name = "%s" + depends_on = [%s] + } + `, resourceName, resourceId, name, dependsOn) +} diff --git a/genesyscloud/conversations_messaging_supportedcontent/genesyscloud_conversations_messaging_supportedcontent_init_test.go b/genesyscloud/conversations_messaging_supportedcontent/genesyscloud_conversations_messaging_supportedcontent_init_test.go new file mode 100644 index 000000000..4f2381238 --- /dev/null +++ b/genesyscloud/conversations_messaging_supportedcontent/genesyscloud_conversations_messaging_supportedcontent_init_test.go @@ -0,0 +1,60 @@ +package conversations_messaging_supportedcontent + +import ( + "sync" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +/* + The genesyscloud_conversations_messaging_supportedcontent_init_test.go file is used to initialize the data sources and resources + used in testing the supported_content resource. +*/ + +// providerDataSources holds a map of all registered datasources +var providerDataSources map[string]*schema.Resource + +// providerResources holds a map of all registered resources +var providerResources map[string]*schema.Resource + +type registerTestInstance struct { + resourceMapMutex sync.RWMutex + datasourceMapMutex sync.RWMutex +} + +// registerTestResources registers all resources used in the tests +func (r *registerTestInstance) registerTestResources() { + r.resourceMapMutex.Lock() + defer r.resourceMapMutex.Unlock() + + providerResources[resourceName] = ResourceSupportedContent() +} + +// registerTestDataSources registers all data sources used in the tests. +func (r *registerTestInstance) registerTestDataSources() { + r.datasourceMapMutex.Lock() + defer r.datasourceMapMutex.Unlock() + + providerDataSources[resourceName] = DataSourceSupportedContent() +} + +// initTestResources initializes all test resources and data sources. +func initTestResources() { + providerDataSources = make(map[string]*schema.Resource) + providerResources = make(map[string]*schema.Resource) + + regInstance := ®isterTestInstance{} + + regInstance.registerTestResources() + regInstance.registerTestDataSources() +} + +// TestMain is a "setup" function called by the testing framework when run the test +func TestMain(m *testing.M) { + // Run setup function before starting the test suite for the supported_content package + initTestResources() + + // Run the test suite for the supported_content package + m.Run() +} diff --git a/genesyscloud/conversations_messaging_supportedcontent/genesyscloud_conversations_messaging_supportedcontent_proxy.go b/genesyscloud/conversations_messaging_supportedcontent/genesyscloud_conversations_messaging_supportedcontent_proxy.go new file mode 100644 index 000000000..ed90a54fa --- /dev/null +++ b/genesyscloud/conversations_messaging_supportedcontent/genesyscloud_conversations_messaging_supportedcontent_proxy.go @@ -0,0 +1,177 @@ +package conversations_messaging_supportedcontent + +import ( + "context" + "fmt" + "log" + rc "terraform-provider-genesyscloud/genesyscloud/resource_cache" + + "github.com/mypurecloud/platform-client-sdk-go/v133/platformclientv2" +) + +/* +The genesyscloud_conversations_messaging_supportedcontent_proxy.go file contains the proxy structures and methods that interact +with the Genesys Cloud SDK. We use composition here for each function on the proxy so individual functions can be stubbed +out during testing. +*/ + +// internalProxy holds a proxy instance that can be used throughout the package +var internalProxy *supportedContentProxy + +// Type definitions for each func on our proxy so we can easily mock them out later +type createSupportedContentFunc func(ctx context.Context, p *supportedContentProxy, supportedContent *platformclientv2.Supportedcontent) (*platformclientv2.Supportedcontent, *platformclientv2.APIResponse, error) +type getAllSupportedContentFunc func(ctx context.Context, p *supportedContentProxy) (*[]platformclientv2.Supportedcontent, *platformclientv2.APIResponse, error) +type getSupportedContentIdByNameFunc func(ctx context.Context, p *supportedContentProxy, name string) (id string, retryable bool, response *platformclientv2.APIResponse, err error) +type getSupportedContentByIdFunc func(ctx context.Context, p *supportedContentProxy, id string) (supportedContent *platformclientv2.Supportedcontent, response *platformclientv2.APIResponse, err error) +type updateSupportedContentFunc func(ctx context.Context, p *supportedContentProxy, id string, supportedContent *platformclientv2.Supportedcontent) (*platformclientv2.Supportedcontent, *platformclientv2.APIResponse, error) +type deleteSupportedContentFunc func(ctx context.Context, p *supportedContentProxy, id string) (response *platformclientv2.APIResponse, err error) + +// supportedContentProxy contains all of the methods that call genesys cloud APIs. +type supportedContentProxy struct { + clientConfig *platformclientv2.Configuration + conversationsApi *platformclientv2.ConversationsApi + createSupportedContentAttr createSupportedContentFunc + getAllSupportedContentAttr getAllSupportedContentFunc + getSupportedContentIdByNameAttr getSupportedContentIdByNameFunc + getSupportedContentByIdAttr getSupportedContentByIdFunc + updateSupportedContentAttr updateSupportedContentFunc + deleteSupportedContentAttr deleteSupportedContentFunc + supportedContentCache rc.CacheInterface[platformclientv2.Supportedcontent] +} + +// newSupportedContentProxy initializes the supported content proxy with all of the data needed to communicate with Genesys Cloud +func newSupportedContentProxy(clientConfig *platformclientv2.Configuration) *supportedContentProxy { + api := platformclientv2.NewConversationsApiWithConfig(clientConfig) + supportedContentCache := rc.NewResourceCache[platformclientv2.Supportedcontent]() + return &supportedContentProxy{ + clientConfig: clientConfig, + conversationsApi: api, + createSupportedContentAttr: createSupportedContentFn, + getAllSupportedContentAttr: getAllSupportedContentFn, + getSupportedContentIdByNameAttr: getSupportedContentIdByNameFn, + getSupportedContentByIdAttr: getSupportedContentByIdFn, + updateSupportedContentAttr: updateSupportedContentFn, + deleteSupportedContentAttr: deleteSupportedContentFn, + supportedContentCache: supportedContentCache, + } +} + +// getSupportedContentProxy acts as a singleton to for the internalProxy. It also ensures +// that we can still proxy our tests by directly setting internalProxy package variable +func getSupportedContentProxy(clientConfig *platformclientv2.Configuration) *supportedContentProxy { + if internalProxy == nil { + internalProxy = newSupportedContentProxy(clientConfig) + } + + return internalProxy +} + +// createSupportedContent creates a Genesys Cloud supported content +func (p *supportedContentProxy) createSupportedContent(ctx context.Context, supportedContent *platformclientv2.Supportedcontent) (*platformclientv2.Supportedcontent, *platformclientv2.APIResponse, error) { + return p.createSupportedContentAttr(ctx, p, supportedContent) +} + +// getSupportedContent retrieves all Genesys Cloud supported content +func (p *supportedContentProxy) getAllSupportedContent(ctx context.Context) (*[]platformclientv2.Supportedcontent, *platformclientv2.APIResponse, error) { + return p.getAllSupportedContentAttr(ctx, p) +} + +// getSupportedContentIdByName returns a single Genesys Cloud supported content by a name +func (p *supportedContentProxy) getSupportedContentIdByName(ctx context.Context, name string) (id string, retryable bool, response *platformclientv2.APIResponse, err error) { + return p.getSupportedContentIdByNameAttr(ctx, p, name) +} + +// getSupportedContentById returns a single Genesys Cloud supported content by Id +func (p *supportedContentProxy) getSupportedContentById(ctx context.Context, id string) (supportedContent *platformclientv2.Supportedcontent, response *platformclientv2.APIResponse, err error) { + return p.getSupportedContentByIdAttr(ctx, p, id) +} + +// updateSupportedContent updates a Genesys Cloud supported content +func (p *supportedContentProxy) updateSupportedContent(ctx context.Context, id string, supportedContent *platformclientv2.Supportedcontent) (*platformclientv2.Supportedcontent, *platformclientv2.APIResponse, error) { + return p.updateSupportedContentAttr(ctx, p, id, supportedContent) +} + +// deleteSupportedContent deletes a Genesys Cloud supported content by Id +func (p *supportedContentProxy) deleteSupportedContent(ctx context.Context, id string) (response *platformclientv2.APIResponse, err error) { + return p.deleteSupportedContentAttr(ctx, p, id) +} + +// createSupportedContentFn is an implementation function for creating a Genesys Cloud supported content +func createSupportedContentFn(ctx context.Context, p *supportedContentProxy, supportedContent *platformclientv2.Supportedcontent) (*platformclientv2.Supportedcontent, *platformclientv2.APIResponse, error) { + return p.conversationsApi.PostConversationsMessagingSupportedcontent(*supportedContent) +} + +// getAllSupportedContentFn is the implementation for retrieving all supported content in Genesys Cloud +func getAllSupportedContentFn(ctx context.Context, p *supportedContentProxy) (*[]platformclientv2.Supportedcontent, *platformclientv2.APIResponse, error) { + var allSupportedContents []platformclientv2.Supportedcontent + const pageSize = 100 + + supportedContents, resp, err := p.conversationsApi.GetConversationsMessagingSupportedcontent(pageSize, 1) + if err != nil { + return nil, resp, fmt.Errorf("Failed to get supported content: %v", err) + } + if supportedContents.Entities == nil || len(*supportedContents.Entities) == 0 { + return &allSupportedContents, resp, nil + } + + allSupportedContents = append(allSupportedContents, *supportedContents.Entities...) + + for pageNum := 2; pageNum <= *supportedContents.PageCount; pageNum++ { + supportedContents, _, err := p.conversationsApi.GetConversationsMessagingSupportedcontent(pageSize, pageNum) + if err != nil { + return nil, resp, fmt.Errorf("Failed to get supported content: %v", err) + } + + if supportedContents.Entities == nil || len(*supportedContents.Entities) == 0 { + break + } + + allSupportedContents = append(allSupportedContents, *supportedContents.Entities...) + } + + for _, content := range allSupportedContents { + rc.SetCache(p.supportedContentCache, *content.Id, content) + } + + return &allSupportedContents, resp, nil +} + +// getSupportedContentIdByNameFn is an implementation of the function to get a Genesys Cloud supported content by name +func getSupportedContentIdByNameFn(ctx context.Context, p *supportedContentProxy, name string) (id string, retryable bool, response *platformclientv2.APIResponse, err error) { + supportedContents, resp, err := getAllSupportedContentFn(ctx, p) + if err != nil { + return "", false, resp, err + } + + if supportedContents == nil || len(*supportedContents) == 0 { + return "", true, resp, fmt.Errorf("No supported content found with name %s", name) + } + + for _, supportedContent := range *supportedContents { + if *supportedContent.Name == name { + log.Printf("Retrieved the supported content id %s by name %s", *supportedContent.Id, name) + return *supportedContent.Id, false, resp, nil + } + } + + return "", true, resp, fmt.Errorf("Unable to find supported content with name %s", name) +} + +// getSupportedContentByIdFn is an implementation of the function to get a Genesys Cloud supported content by Id +func getSupportedContentByIdFn(ctx context.Context, p *supportedContentProxy, id string) (supportedContent *platformclientv2.Supportedcontent, response *platformclientv2.APIResponse, err error) { + content := rc.GetCacheItem(p.supportedContentCache, id) + if content != nil { + return content, nil, nil + } + return p.conversationsApi.GetConversationsMessagingSupportedcontentSupportedContentId(id) +} + +// updateSupportedContentFn is an implementation of the function to update a Genesys Cloud supported content +func updateSupportedContentFn(ctx context.Context, p *supportedContentProxy, id string, supportedContent *platformclientv2.Supportedcontent) (*platformclientv2.Supportedcontent, *platformclientv2.APIResponse, error) { + return p.conversationsApi.PatchConversationsMessagingSupportedcontentSupportedContentId(id, *supportedContent) +} + +// deleteSupportedContentFn is an implementation function for deleting a Genesys Cloud supported content +func deleteSupportedContentFn(ctx context.Context, p *supportedContentProxy, id string) (response *platformclientv2.APIResponse, err error) { + return p.conversationsApi.DeleteConversationsMessagingSupportedcontentSupportedContentId(id) +} diff --git a/genesyscloud/conversations_messaging_supportedcontent/resource_genesyscloud_conversations_messaging_supportedcontent.go b/genesyscloud/conversations_messaging_supportedcontent/resource_genesyscloud_conversations_messaging_supportedcontent.go new file mode 100644 index 000000000..43bcd0c31 --- /dev/null +++ b/genesyscloud/conversations_messaging_supportedcontent/resource_genesyscloud_conversations_messaging_supportedcontent.go @@ -0,0 +1,127 @@ +package conversations_messaging_supportedcontent + +import ( + "context" + "fmt" + "log" + "terraform-provider-genesyscloud/genesyscloud/provider" + resourceExporter "terraform-provider-genesyscloud/genesyscloud/resource_exporter" + "terraform-provider-genesyscloud/genesyscloud/util" + "time" + + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/mypurecloud/platform-client-sdk-go/v133/platformclientv2" + + "terraform-provider-genesyscloud/genesyscloud/consistency_checker" + + "terraform-provider-genesyscloud/genesyscloud/util/constants" + "terraform-provider-genesyscloud/genesyscloud/util/resourcedata" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" +) + +/* +The resource_genesyscloud_conversations_messaging_supportedcontent.go contains all of the methods that perform the core logic for a resource. +*/ + +// getAllAuthSupportedContent retrieves all of the supported content via Terraform in the Genesys Cloud and is used for the exporter +func getAllAuthSupportedContents(ctx context.Context, clientConfig *platformclientv2.Configuration) (resourceExporter.ResourceIDMetaMap, diag.Diagnostics) { + proxy := getSupportedContentProxy(clientConfig) + resources := make(resourceExporter.ResourceIDMetaMap) + + supportedContents, resp, err := proxy.getAllSupportedContent(ctx) + if err != nil { + return nil, util.BuildAPIDiagnosticError(resourceName, fmt.Sprintf("Failed to get supported content: %s", err), resp) + } + + for _, supportedContent := range *supportedContents { + resources[*supportedContent.Id] = &resourceExporter.ResourceMeta{Name: *supportedContent.Name} + } + + return resources, nil +} + +// createSupportedContent is used by the supported_content resource to create Genesys cloud supported content +func createSupportedContent(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + sdkConfig := meta.(*provider.ProviderMeta).ClientConfig + proxy := getSupportedContentProxy(sdkConfig) + + supportedContentConfig := getSupportedContentFromResourceData(d) + + log.Printf("Creating supported content %s", *supportedContentConfig.Name) + supportedContent, resp, err := proxy.createSupportedContent(ctx, &supportedContentConfig) + if err != nil { + return util.BuildAPIDiagnosticError(resourceName, fmt.Sprintf("Failed to create supported content: %s", err), resp) + } + + d.SetId(*supportedContent.Id) + log.Printf("Created supported content %s", *supportedContent.Id) + return readSupportedContent(ctx, d, meta) +} + +// readSupportedContent is used by the supported_content resource to read an supported content from genesys cloud +func readSupportedContent(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + sdkConfig := meta.(*provider.ProviderMeta).ClientConfig + proxy := getSupportedContentProxy(sdkConfig) + + log.Printf("Reading supported content %s", d.Id()) + + cc := consistency_checker.NewConsistencyCheck(ctx, d, meta, ResourceSupportedContent(), constants.DefaultConsistencyChecks, resourceName) + return util.WithRetriesForRead(ctx, d, func() *retry.RetryError { + supportedContent, resp, getErr := proxy.getSupportedContentById(ctx, d.Id()) + if getErr != nil { + if util.IsStatus404(resp) { + return retry.RetryableError(util.BuildWithRetriesApiDiagnosticError(resourceName, fmt.Sprintf("Failed to read supported content %s: %s", d.Id(), getErr), resp)) + } + return retry.NonRetryableError(util.BuildWithRetriesApiDiagnosticError(resourceName, fmt.Sprintf("Failed to read supported content %s: %s", d.Id(), getErr), resp)) + } + + resourcedata.SetNillableValue(d, "name", supportedContent.Name) + resourcedata.SetNillableValueWithInterfaceArrayWithFunc(d, "media_types", supportedContent.MediaTypes, flattenMediaTypes) + log.Printf("Read supported content %s %s", d.Id(), *supportedContent.Name) + return cc.CheckState(d) + }) +} + +// updateSupportedContent is used by the supported_content resource to update an supported content in Genesys Cloud +func updateSupportedContent(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + sdkConfig := meta.(*provider.ProviderMeta).ClientConfig + proxy := getSupportedContentProxy(sdkConfig) + + supportedContentConfig := getSupportedContentFromResourceData(d) + + log.Printf("Updating supported content %s", *supportedContentConfig.Name) + supportedContent, resp, err := proxy.updateSupportedContent(ctx, d.Id(), &supportedContentConfig) + if err != nil { + return util.BuildAPIDiagnosticError(resourceName, fmt.Sprintf("Failed to update supported content: %s", err), resp) + } + + log.Printf("Updated supported content %s", *supportedContent.Id) + return readSupportedContent(ctx, d, meta) +} + +// deleteSupportedContent is used by the supported_content resource to delete an supported content from Genesys cloud +func deleteSupportedContent(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + sdkConfig := meta.(*provider.ProviderMeta).ClientConfig + proxy := getSupportedContentProxy(sdkConfig) + + _, err := proxy.deleteSupportedContent(ctx, d.Id()) + if err != nil { + return diag.Errorf("Failed to delete supported content %s: %s", d.Id(), err) + } + + return util.WithRetries(ctx, 180*time.Second, func() *retry.RetryError { + _, resp, err := proxy.getSupportedContentById(ctx, d.Id()) + + if err != nil { + if util.IsStatus404(resp) { + log.Printf("Deleted supported content %s", d.Id()) + return nil + } + return retry.NonRetryableError(util.BuildWithRetriesApiDiagnosticError(resourceName, fmt.Sprintf("Error deleting supported content %s: %s", d.Id(), err), resp)) + } + + return retry.RetryableError(util.BuildWithRetriesApiDiagnosticError(resourceName, fmt.Sprintf("supported content %s still exists: %s", d.Id(), err), resp)) + }) +} diff --git a/genesyscloud/conversations_messaging_supportedcontent/resource_genesyscloud_conversations_messaging_supportedcontent_schema.go b/genesyscloud/conversations_messaging_supportedcontent/resource_genesyscloud_conversations_messaging_supportedcontent_schema.go new file mode 100644 index 000000000..c543a711d --- /dev/null +++ b/genesyscloud/conversations_messaging_supportedcontent/resource_genesyscloud_conversations_messaging_supportedcontent_schema.go @@ -0,0 +1,124 @@ +package conversations_messaging_supportedcontent + +import ( + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + + "terraform-provider-genesyscloud/genesyscloud/provider" + resourceExporter "terraform-provider-genesyscloud/genesyscloud/resource_exporter" + registrar "terraform-provider-genesyscloud/genesyscloud/resource_register" +) + +/* +resource_genesycloud_supported_content_schema.go holds four functions within it: + +1. The registration code that registers the Datasource, Resource and Exporter for the package. +2. The resource schema definitions for the supported_content resource. +3. The datasource schema definitions for the supported_content datasource. +4. The resource exporter configuration for the supported_content exporter. +*/ +const resourceName = "genesyscloud_conversations_messaging_supportedcontent" + +// SetRegistrar registers all of the resources, datasources and exporters in the package +func SetRegistrar(regInstance registrar.Registrar) { + regInstance.RegisterResource(resourceName, ResourceSupportedContent()) + regInstance.RegisterDataSource(resourceName, DataSourceSupportedContent()) + regInstance.RegisterExporter(resourceName, SupportedContentExporter()) +} + +var ( + mediaTypeResource = &schema.Resource{ + Schema: map[string]*schema.Schema{ + `type`: { + Description: `The media type string as defined by RFC 2046. You can define specific types such as 'image/jpeg', 'video/mpeg', or specify wild cards for a range of types, 'image/*', or all types '*/*'. See https://www.iana.org/assignments/media-types/media-types.xhtml for a list of registered media types.`, + Optional: true, + Type: schema.TypeString, + }, + }, + } + + mediaTypeAccessResource = &schema.Resource{ + Schema: map[string]*schema.Schema{ + `inbound`: { + Description: `List of media types allowed for inbound messages from customers. If inbound messages from a customer contain media that is not in this list, the media will be dropped from the outbound message.`, + Optional: true, + Type: schema.TypeList, + Elem: mediaTypeResource, + }, + `outbound`: { + Description: `List of media types allowed for outbound messages to customers. If an outbound message is sent that contains media that is not in this list, the message will not be sent.`, + Optional: true, + Type: schema.TypeList, + Elem: mediaTypeResource, + }, + }, + } + + mediaTypesResource = &schema.Resource{ + Schema: map[string]*schema.Schema{ + `allow`: { + Description: `Specify allowed media types for inbound and outbound messages. If this field is empty, all inbound and outbound media will be blocked.`, + Optional: true, + Type: schema.TypeList, + MaxItems: 1, + Elem: mediaTypeAccessResource, + }, + }, + } +) + +// ResourceSupportedContent registers the genesyscloud_conversations_messaging_supportedcontent resource with Terraform +func ResourceSupportedContent() *schema.Resource { + + return &schema.Resource{ + Description: `Genesys Cloud supported content`, + + CreateContext: provider.CreateWithPooledClient(createSupportedContent), + ReadContext: provider.ReadWithPooledClient(readSupportedContent), + UpdateContext: provider.UpdateWithPooledClient(updateSupportedContent), + DeleteContext: provider.DeleteWithPooledClient(deleteSupportedContent), + Importer: &schema.ResourceImporter{ + StateContext: schema.ImportStatePassthroughContext, + }, + SchemaVersion: 1, + Schema: map[string]*schema.Schema{ + `name`: { + Description: `The name of the supported content profile`, + Required: true, + Type: schema.TypeString, + }, + `media_types`: { + Description: `Defines the allowable media that may be accepted for an inbound message or to be sent in an outbound message.`, + Optional: true, + Type: schema.TypeList, + MaxItems: 1, + Elem: mediaTypesResource, + }, + }, + } +} + +// SupportedContentExporter returns the resourceExporter object used to hold the genesyscloud_conversations_messaging_supportedcontent exporter's config +func SupportedContentExporter() *resourceExporter.ResourceExporter { + return &resourceExporter.ResourceExporter{ + GetResourcesFunc: provider.GetAllWithPooledClient(getAllAuthSupportedContents), + RefAttrs: map[string]*resourceExporter.RefAttrSettings{}, + } +} + +// DataSourceSupportedContent registers the genesyscloud_conversations_messaging_supportedcontent data source +func DataSourceSupportedContent() *schema.Resource { + return &schema.Resource{ + Description: `Genesys Cloud supported content data source. Select an supported content by name`, + ReadContext: provider.ReadWithPooledClient(dataSourceSupportedContentRead), + Importer: &schema.ResourceImporter{ + StateContext: schema.ImportStatePassthroughContext, + }, + Schema: map[string]*schema.Schema{ + "name": { + Description: `supported content name`, + Type: schema.TypeString, + Required: true, + }, + }, + } +} diff --git a/genesyscloud/conversations_messaging_supportedcontent/resource_genesyscloud_conversations_messaging_supportedcontent_test.go b/genesyscloud/conversations_messaging_supportedcontent/resource_genesyscloud_conversations_messaging_supportedcontent_test.go new file mode 100644 index 000000000..d738a4b3f --- /dev/null +++ b/genesyscloud/conversations_messaging_supportedcontent/resource_genesyscloud_conversations_messaging_supportedcontent_test.go @@ -0,0 +1,134 @@ +package conversations_messaging_supportedcontent + +import ( + "fmt" + "strings" + "testing" + + "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/mypurecloud/platform-client-sdk-go/v133/platformclientv2" + + "terraform-provider-genesyscloud/genesyscloud/provider" + "terraform-provider-genesyscloud/genesyscloud/util" + + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" +) + +/* +The resource_genesyscloud_conversations_messaging_supportedcontent_test.go contains all of the test cases for running the resource +tests for supported_content. +*/ + +func TestAccResourceSupportedContent(t *testing.T) { + t.Parallel() + var ( + resourceId = "testSupportedContent" + name = "Terraform Supported Content - " + uuid.NewString() + inboundType = "*/*" + outboundType = "*/*" + inboundType2 = "image/*" + inboundType3 = "video/mpeg" + ) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { util.TestAccPreCheck(t) }, + ProviderFactories: provider.GetProviderFactories(providerResources, providerDataSources), + Steps: []resource.TestStep{ + { + Config: GenerateSupportedContentResource( + resourceName, + resourceId, + name, + GenerateInboundTypeBlock(inboundType), + GenerateOutboundTypeBlock(outboundType), + ), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("genesyscloud_conversations_messaging_supportedcontent."+resourceId, "name", name), + resource.TestCheckResourceAttr("genesyscloud_conversations_messaging_supportedcontent."+resourceId, "media_types.0.allow.0.inbound.0.type", inboundType), + resource.TestCheckResourceAttr("genesyscloud_conversations_messaging_supportedcontent."+resourceId, "media_types.0.allow.0.outbound.0.type", outboundType), + ), + }, + //Update and add inbound block + { + Config: GenerateSupportedContentResource( + resourceName, + resourceId, + name, + GenerateInboundTypeBlock(inboundType2), + GenerateInboundTypeBlock(inboundType3), + GenerateOutboundTypeBlock(outboundType), + ), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("genesyscloud_conversations_messaging_supportedcontent."+resourceId, "name", name), + resource.TestCheckResourceAttr("genesyscloud_conversations_messaging_supportedcontent."+resourceId, "media_types.0.allow.0.inbound.0.type", inboundType2), + resource.TestCheckResourceAttr("genesyscloud_conversations_messaging_supportedcontent."+resourceId, "media_types.0.allow.0.inbound.1.type", inboundType3), + resource.TestCheckResourceAttr("genesyscloud_conversations_messaging_supportedcontent."+resourceId, "media_types.0.allow.0.outbound.0.type", outboundType), + ), + }, + { + // Import/Read + ResourceName: "genesyscloud_conversations_messaging_supportedcontent." + resourceId, + ImportState: true, + ImportStateVerify: true, + }, + }, + CheckDestroy: testVerifySupportedContentDestroyed, + }) +} + +func GenerateSupportedContentResource( + resourceName string, + resourceId string, + name string, + nestedBlocks ...string, +) string { + return fmt.Sprintf(`resource "%s" "%s" { + name = "%s" + media_types { + allow { + %s + } + } + } `, resourceName, resourceId, name, strings.Join(nestedBlocks, "\n")) +} + +func GenerateInboundTypeBlock( + inboundType string, +) string { + return fmt.Sprintf(` + inbound { + type="%s" + } + `, inboundType) +} + +func GenerateOutboundTypeBlock( + outboundType string, +) string { + return fmt.Sprintf(` + outbound { + type="%s" + } + `, outboundType) +} + +func testVerifySupportedContentDestroyed(state *terraform.State) error { + supportContentApi := platformclientv2.NewConversationsApi() + for _, rs := range state.RootModule().Resources { + if rs.Type != resourceName { + continue + } + + supportedContent, resp, err := supportContentApi.GetConversationsMessagingSupportedcontentSupportedContentId(rs.Primary.ID) + + if supportedContent != nil { + return fmt.Errorf("Supported Content (%s) still exists", rs.Primary.ID) + } else if util.IsStatus404(resp) { + continue + } else { + return fmt.Errorf("Unexpected error: %s", err) + } + } + return nil +} diff --git a/genesyscloud/conversations_messaging_supportedcontent/resource_genesyscloud_conversations_messaging_supportedcontent_utils.go b/genesyscloud/conversations_messaging_supportedcontent/resource_genesyscloud_conversations_messaging_supportedcontent_utils.go new file mode 100644 index 000000000..99735e57d --- /dev/null +++ b/genesyscloud/conversations_messaging_supportedcontent/resource_genesyscloud_conversations_messaging_supportedcontent_utils.go @@ -0,0 +1,117 @@ +package conversations_messaging_supportedcontent + +import ( + "terraform-provider-genesyscloud/genesyscloud/util/resourcedata" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/mypurecloud/platform-client-sdk-go/v133/platformclientv2" +) + +/* +The resource_genesyscloud_conversations_messaging_supportedcontent_utils.go file contains various helper methods to marshal +and unmarshal data into formats consumable by Terraform and/or Genesys Cloud. +*/ + +// getSupportedContentFromResourceData maps data from schema ResourceData object to a platformclientv2.Supportedcontent +func getSupportedContentFromResourceData(d *schema.ResourceData) platformclientv2.Supportedcontent { + var supportedContent platformclientv2.Supportedcontent + supportedContent.Name = platformclientv2.String(d.Get("name").(string)) + if mediaTypes, ok := d.Get("media_types").([]interface{}); ok && len(mediaTypes) > 0 { + supportedContent.MediaTypes = buildMediaTypes(d.Get("media_types").([]interface{})) + } + return supportedContent +} + +// buildMediaTypes maps an []interface{} into a Genesys Cloud *[]platformclientv2.Mediatype +func buildMediaTypes(mediaTypes []interface{}) *platformclientv2.Mediatypes { + var sdkMediaType platformclientv2.Mediatypes + + for _, mediaType := range mediaTypes { + mediaTypesMap, ok := mediaType.(map[string]interface{}) + if !ok { + continue + } + + resourcedata.BuildSDKInterfaceArrayValueIfNotNil(&sdkMediaType.Allow, mediaTypesMap, "allow", buildAllowedMediaTypeAccess) + } + return &sdkMediaType +} + +// buildMediaTypeAccesss maps an []interface{} into a Genesys Cloud *[]platformclientv2.Mediatypeaccess +func buildAllowedMediaTypeAccess(mediaTypeAccess []interface{}) *platformclientv2.Mediatypeaccess { + var sdkMediaTypeAccess platformclientv2.Mediatypeaccess + for _, mediaType := range mediaTypeAccess { + mediaTypeAccessMap, ok := mediaType.(map[string]interface{}) + if !ok { + continue + } + + resourcedata.BuildSDKInterfaceArrayValueIfNotNil(&sdkMediaTypeAccess.Inbound, mediaTypeAccessMap, "inbound", buildInboundOutboundMediaTypes) + resourcedata.BuildSDKInterfaceArrayValueIfNotNil(&sdkMediaTypeAccess.Outbound, mediaTypeAccessMap, "outbound", buildInboundOutboundMediaTypes) + + } + + return &sdkMediaTypeAccess +} + +// buildMediaTypess maps an []interface{} into a Genesys Cloud *[]platformclientv2.Mediatypes +func buildInboundOutboundMediaTypes(mediaTypes []interface{}) *[]platformclientv2.Mediatype { + mediaTypesSlice := make([]platformclientv2.Mediatype, 0) + for _, mediaType := range mediaTypes { + var sdkMediaTypes platformclientv2.Mediatype + mediaTypesMap, ok := mediaType.(map[string]interface{}) + if !ok { + continue + } + + resourcedata.BuildSDKStringValueIfNotNil(&sdkMediaTypes.VarType, mediaTypesMap, "type") + + mediaTypesSlice = append(mediaTypesSlice, sdkMediaTypes) + } + + return &mediaTypesSlice +} + +// flattenMediaTypes maps a Genesys Cloud *[]platformclientv2.Mediatype into a []interface{} +func flattenInboundOutboundMediaTypes(mediaTypes *[]platformclientv2.Mediatype) []interface{} { + if len(*mediaTypes) == 0 { + return nil + } + + var mediaTypeList []interface{} + for _, mediaType := range *mediaTypes { + mediaTypeMap := make(map[string]interface{}) + + resourcedata.SetMapValueIfNotNil(mediaTypeMap, "type", mediaType.VarType) + + mediaTypeList = append(mediaTypeList, mediaTypeMap) + } + + return mediaTypeList +} + +// flattenMediaTypeAccesss maps a Genesys Cloud *[]platformclientv2.Mediatypeaccess into a []interface{} +func flattenAllowedMediaTypeAccess(mediaTypeAccess *platformclientv2.Mediatypeaccess) []interface{} { + + var mediaTypeAccessList []interface{} + mediaTypeAccessMap := make(map[string]interface{}) + + resourcedata.SetMapInterfaceArrayWithFuncIfNotNil(mediaTypeAccessMap, "inbound", mediaTypeAccess.Inbound, flattenInboundOutboundMediaTypes) + resourcedata.SetMapInterfaceArrayWithFuncIfNotNil(mediaTypeAccessMap, "outbound", mediaTypeAccess.Outbound, flattenInboundOutboundMediaTypes) + + mediaTypeAccessList = append(mediaTypeAccessList, mediaTypeAccessMap) + + return mediaTypeAccessList +} + +// flattenMediaTypess maps a Genesys Cloud *[]platformclientv2.Mediatypes into a []interface{} +func flattenMediaTypes(mediaTypes *platformclientv2.Mediatypes) []interface{} { + var mediaTypesList []interface{} + mediaTypesMap := make(map[string]interface{}) + + resourcedata.SetMapInterfaceArrayWithFuncIfNotNil(mediaTypesMap, "allow", mediaTypes.Allow, flattenAllowedMediaTypeAccess) + + mediaTypesList = append(mediaTypesList, mediaTypesMap) + + return mediaTypesList +} diff --git a/genesyscloud/tfexporter/tf_exporter_resource_test.go b/genesyscloud/tfexporter/tf_exporter_resource_test.go index d1060fd0b..bd4c031c4 100644 --- a/genesyscloud/tfexporter/tf_exporter_resource_test.go +++ b/genesyscloud/tfexporter/tf_exporter_resource_test.go @@ -13,6 +13,7 @@ import ( architectSchedules "terraform-provider-genesyscloud/genesyscloud/architect_schedules" authRole "terraform-provider-genesyscloud/genesyscloud/auth_role" cMessagingSettings "terraform-provider-genesyscloud/genesyscloud/conversations_messaging_settings" + supportedContent "terraform-provider-genesyscloud/genesyscloud/conversations_messaging_supportedcontent" employeeperformanceExternalmetricsDefinition "terraform-provider-genesyscloud/genesyscloud/employeeperformance_externalmetrics_definitions" flowLogLevel "terraform-provider-genesyscloud/genesyscloud/flow_loglevel" flowMilestone "terraform-provider-genesyscloud/genesyscloud/flow_milestone" @@ -206,6 +207,9 @@ func (r *registerTestInstance) registerTestResources() { providerResources["genesyscloud_task_management_workbin"] = workbin.ResourceTaskManagementWorkbin() providerResources["genesyscloud_task_management_workitem_schema"] = workitemSchema.ResourceTaskManagementWorkitemSchema() providerResources["genesyscloud_task_management_worktype"] = worktype.ResourceTaskManagementWorktype() + + providerResources["genesyscloud_conversations_messaging_supportedcontent"] = supportedContent.ResourceSupportedContent() + providerResources["genesyscloud_conversations_messaging_settings"] = cMessagingSettings.ResourceConversationsMessagingSettings() providerResources["genesyscloud_tf_export"] = ResourceTfExport() } @@ -309,6 +313,8 @@ func (r *registerTestInstance) registerTestExporters() { RegisterExporter("genesyscloud_task_management_worktype", worktype.TaskManagementWorktypeExporter()) RegisterExporter("genesyscloud_conversations_messaging_settings", cMessagingSettings.ConversationsMessagingSettingsExporter()) + RegisterExporter("genesyscloud_conversations_messaging_supportedcontent", supportedContent.SupportedContentExporter()) + RegisterExporter("genesyscloud_script", scripts.ExporterScript()) resourceExporter.SetRegisterExporter(resourceExporters) diff --git a/main.go b/main.go index d597aa222..80a7ea4cb 100644 --- a/main.go +++ b/main.go @@ -16,6 +16,8 @@ import ( userPrompt "terraform-provider-genesyscloud/genesyscloud/architect_user_prompt" authRole "terraform-provider-genesyscloud/genesyscloud/auth_role" authorizatioProduct "terraform-provider-genesyscloud/genesyscloud/authorization_product" + cMessageSettings "terraform-provider-genesyscloud/genesyscloud/conversations_messaging_settings" + supportedContent "terraform-provider-genesyscloud/genesyscloud/conversations_messaging_supportedcontent" employeeperformanceExternalmetricsDefinition "terraform-provider-genesyscloud/genesyscloud/employeeperformance_externalmetrics_definitions" externalContacts "terraform-provider-genesyscloud/genesyscloud/external_contacts" flowLogLevel "terraform-provider-genesyscloud/genesyscloud/flow_loglevel" @@ -67,15 +69,14 @@ import ( routingEmailRoute "terraform-provider-genesyscloud/genesyscloud/routing_email_route" routingLanguage "terraform-provider-genesyscloud/genesyscloud/routing_language" routingQueue "terraform-provider-genesyscloud/genesyscloud/routing_queue" - routingSkillGroup "terraform-provider-genesyscloud/genesyscloud/routing_skill_group" - routingUtilization "terraform-provider-genesyscloud/genesyscloud/routing_utilization" - routingUtilizationLabel "terraform-provider-genesyscloud/genesyscloud/routing_utilization_label" - cMessageSettings "terraform-provider-genesyscloud/genesyscloud/conversations_messaging_settings" routingQueueConditionalGroupRouting "terraform-provider-genesyscloud/genesyscloud/routing_queue_conditional_group_routing" routingQueueOutboundEmailAddress "terraform-provider-genesyscloud/genesyscloud/routing_queue_outbound_email_address" routingSettings "terraform-provider-genesyscloud/genesyscloud/routing_settings" routingSkill "terraform-provider-genesyscloud/genesyscloud/routing_skill" + routingSkillGroup "terraform-provider-genesyscloud/genesyscloud/routing_skill_group" smsAddresses "terraform-provider-genesyscloud/genesyscloud/routing_sms_addresses" + routingUtilization "terraform-provider-genesyscloud/genesyscloud/routing_utilization" + routingUtilizationLabel "terraform-provider-genesyscloud/genesyscloud/routing_utilization_label" "terraform-provider-genesyscloud/genesyscloud/scripts" "terraform-provider-genesyscloud/genesyscloud/station" workbin "terraform-provider-genesyscloud/genesyscloud/task_management_workbin" @@ -247,6 +248,7 @@ func registerResources() { journeyViews.SetRegistrar(regInstance) //Registering journey views routingLanguage.SetRegistrar(regInstance) //Registering Routing Language routingEmailDomain.SetRegistrar(regInstance) //Registering Routing Email Domain + supportedContent.SetRegistrar(regInstance) //Registering Supported Content routingSkill.SetRegistrar(regInstance) //Registering Routing Skill cMessageSettings.SetRegistrar(regInstance) // Registering conversations messaging settings routingSkillGroup.SetRegistrar(regInstance) //Registering routing skill group