-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat/devtooling 713 - genesyscloud_conversations_messaging_supportedc…
…ontent_default (#1263) * added supported content default resource * added exporter * comments resolved
- Loading branch information
1 parent
23767a8
commit 47ac0ba
Showing
10 changed files
with
421 additions
and
0 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
docs/resources/conversations_messaging_supportedcontent_default.md
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 @@ | ||
--- | ||
page_title: "genesyscloud_conversations_messaging_supportedcontent_default Resource - terraform-provider-genesyscloud" | ||
subcategory: "" | ||
description: |- | ||
Genesys Cloud conversations messaging supportedcontent default | ||
--- | ||
# genesyscloud_conversations_messaging_supportedcontent_default (Resource) | ||
|
||
Genesys Cloud conversations messaging supportedcontent default | ||
|
||
## 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: | ||
|
||
* [PUT /api/v2/conversations/messaging/supportedcontent/default](https://developer.genesys.cloud/devapps/api-explorer#put-api-v2-conversations-messaging-supportedcontent-default) | ||
* [GET /api/v2/conversations/messaging/supportedcontent/default](https://developer.genesys.cloud/devapps/api-explorer#get-api-v2-conversations-messaging-supportedcontent-default) | ||
|
||
|
||
|
||
## Example Usage | ||
|
||
```terraform | ||
resource "genesyscloud_conversations_messaging_supportedcontent_default" "example-default-supported-content" { | ||
content_id = genesyscloud_conversations_messaging_supportedcontent.supported_content.id | ||
} | ||
``` | ||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `content_id` (String) The SupportedContent unique identifier associated with this integration | ||
|
||
### Read-Only | ||
|
||
- `id` (String) The ID of this resource. | ||
|
3 changes: 3 additions & 0 deletions
3
...resources/genesyscloud_conversations_messaging_supportedcontent_default/apis.md
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,3 @@ | ||
* [PUT /api/v2/conversations/messaging/supportedcontent/default](https://developer.genesys.cloud/devapps/api-explorer#put-api-v2-conversations-messaging-supportedcontent-default) | ||
* [GET /api/v2/conversations/messaging/supportedcontent/default](https://developer.genesys.cloud/devapps/api-explorer#get-api-v2-conversations-messaging-supportedcontent-default) | ||
|
3 changes: 3 additions & 0 deletions
3
examples/resources/genesyscloud_conversations_messaging_supportedcontent_default/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,3 @@ | ||
resource "genesyscloud_conversations_messaging_supportedcontent_default" "example-default-supported-content" { | ||
content_id = genesyscloud_conversations_messaging_supportedcontent.supported_content.id | ||
} |
54 changes: 54 additions & 0 deletions
54
...ontent_default/genesyscloud_conversations_messaging_supportedcontent_default_init_test.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,54 @@ | ||
package conversations_messaging_supportedcontent_default | ||
|
||
import ( | ||
"sync" | ||
"testing" | ||
|
||
cmSupportedContent "terraform-provider-genesyscloud/genesyscloud/conversations_messaging_supportedcontent" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
/* | ||
The genesyscloud_conversations_messaging_supportedcontent_default_init_test.go file is used to initialize the data sources and resources | ||
used in testing the conversations_messaging_supportedcontent_default 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] = ResourceConversationsMessagingSupportedcontentDefault() | ||
providerResources["genesyscloud_conversations_messaging_supportedcontent"] = cmSupportedContent.ResourceSupportedContent() | ||
} | ||
|
||
// 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() | ||
} | ||
|
||
// 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 conversations_messaging_supportedcontent_default package | ||
initTestResources() | ||
|
||
// Run the test suite for the conversations_messaging_supportedcontent_default package | ||
m.Run() | ||
} |
69 changes: 69 additions & 0 deletions
69
...tedcontent_default/genesyscloud_conversations_messaging_supportedcontent_default_proxy.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,69 @@ | ||
package conversations_messaging_supportedcontent_default | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/mypurecloud/platform-client-sdk-go/v133/platformclientv2" | ||
) | ||
|
||
/* | ||
The genesyscloud_conversations_messaging_supportedcontent_default_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 *conversationsMessagingSupportedcontentDefaultProxy | ||
|
||
// Type definitions for each func on our proxy so we can easily mock them out later | ||
type getConversationsMessagingSupportedcontentDefaultFunc func(ctx context.Context, p *conversationsMessagingSupportedcontentDefaultProxy) (*platformclientv2.Supportedcontent, *platformclientv2.APIResponse, error) | ||
type updateConversationsMessagingSupportedcontentDefaultFunc func(ctx context.Context, p *conversationsMessagingSupportedcontentDefaultProxy, id string, supportedContentReference *platformclientv2.Supportedcontentreference) (*platformclientv2.Supportedcontent, *platformclientv2.APIResponse, error) | ||
|
||
// conversationsMessagingSupportedcontentDefaultProxy contains all of the methods that call genesys cloud APIs. | ||
type conversationsMessagingSupportedcontentDefaultProxy struct { | ||
clientConfig *platformclientv2.Configuration | ||
conversationsApi *platformclientv2.ConversationsApi | ||
getConversationsMessagingSupportedcontentDefaultAttr getConversationsMessagingSupportedcontentDefaultFunc | ||
updateConversationsMessagingSupportedcontentDefaultAttr updateConversationsMessagingSupportedcontentDefaultFunc | ||
} | ||
|
||
// newConversationsMessagingSupportedcontentDefaultProxy initializes the conversations messaging supportedcontent default proxy with all of the data needed to communicate with Genesys Cloud | ||
func newConversationsMessagingSupportedcontentDefaultProxy(clientConfig *platformclientv2.Configuration) *conversationsMessagingSupportedcontentDefaultProxy { | ||
api := platformclientv2.NewConversationsApiWithConfig(clientConfig) | ||
return &conversationsMessagingSupportedcontentDefaultProxy{ | ||
clientConfig: clientConfig, | ||
conversationsApi: api, | ||
getConversationsMessagingSupportedcontentDefaultAttr: getConversationsMessagingSupportedcontentDefaultFn, | ||
updateConversationsMessagingSupportedcontentDefaultAttr: updateConversationsMessagingSupportedcontentDefaultFn, | ||
} | ||
} | ||
|
||
// getConversationsMessagingSupportedcontentDefaultProxy 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 getConversationsMessagingSupportedcontentDefaultProxy(clientConfig *platformclientv2.Configuration) *conversationsMessagingSupportedcontentDefaultProxy { | ||
if internalProxy == nil { | ||
internalProxy = newConversationsMessagingSupportedcontentDefaultProxy(clientConfig) | ||
} | ||
|
||
return internalProxy | ||
} | ||
|
||
// getConversationsMessagingSupportedcontentDefault retrieves all Genesys Cloud conversations messaging supportedcontent default | ||
func (p *conversationsMessagingSupportedcontentDefaultProxy) getConversationsMessagingSupportedcontentDefault(ctx context.Context) (*platformclientv2.Supportedcontent, *platformclientv2.APIResponse, error) { | ||
return p.getConversationsMessagingSupportedcontentDefaultAttr(ctx, p) | ||
} | ||
|
||
// updateConversationsMessagingSupportedcontentDefault updates a Genesys Cloud conversations messaging supportedcontent default | ||
func (p *conversationsMessagingSupportedcontentDefaultProxy) updateConversationsMessagingSupportedcontentDefault(ctx context.Context, id string, conversationsMessagingSupportedcontentDefault *platformclientv2.Supportedcontentreference) (*platformclientv2.Supportedcontent, *platformclientv2.APIResponse, error) { | ||
return p.updateConversationsMessagingSupportedcontentDefaultAttr(ctx, p, id, conversationsMessagingSupportedcontentDefault) | ||
} | ||
|
||
// getConversationsMessagingSupportedcontentDefaultFn is the implementation for retrieving all conversations messaging supportedcontent default in Genesys Cloud | ||
func getConversationsMessagingSupportedcontentDefaultFn(ctx context.Context, p *conversationsMessagingSupportedcontentDefaultProxy) (*platformclientv2.Supportedcontent, *platformclientv2.APIResponse, error) { | ||
return p.conversationsApi.GetConversationsMessagingSupportedcontentDefault() | ||
} | ||
|
||
// updateConversationsMessagingSupportedcontentDefaultFn is an implementation of the function to update a Genesys Cloud conversations messaging supportedcontent default | ||
func updateConversationsMessagingSupportedcontentDefaultFn(ctx context.Context, p *conversationsMessagingSupportedcontentDefaultProxy, id string, conversationsMessagingSupportedcontentDefault *platformclientv2.Supportedcontentreference) (*platformclientv2.Supportedcontent, *platformclientv2.APIResponse, error) { | ||
return p.conversationsApi.PutConversationsMessagingSupportedcontentDefault(*conversationsMessagingSupportedcontentDefault) | ||
} |
97 changes: 97 additions & 0 deletions
97
...content_default/resource_genesyscloud_conversations_messaging_supportedcontent_default.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,97 @@ | ||
package conversations_messaging_supportedcontent_default | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"log" | ||
"terraform-provider-genesyscloud/genesyscloud/consistency_checker" | ||
"terraform-provider-genesyscloud/genesyscloud/provider" | ||
"terraform-provider-genesyscloud/genesyscloud/util" | ||
"terraform-provider-genesyscloud/genesyscloud/util/constants" | ||
"terraform-provider-genesyscloud/genesyscloud/util/resourcedata" | ||
|
||
resourceExporter "terraform-provider-genesyscloud/genesyscloud/resource_exporter" | ||
|
||
"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" | ||
) | ||
|
||
/* | ||
The resource_genesyscloud_conversations_messaging_supportedcontent_default.go contains all of the methods that perform the core logic for a resource. | ||
*/ | ||
|
||
// getAuthConversationsMessagingSupportedcontentDefault retrieves all of the conversations messaging supportedcontent default via Terraform in the Genesys Cloud and is used for the exporter | ||
func getAuthConversationsMessagingSupportedcontentDefaults(ctx context.Context, clientConfig *platformclientv2.Configuration) (resourceExporter.ResourceIDMetaMap, diag.Diagnostics) { | ||
proxy := getConversationsMessagingSupportedcontentDefaultProxy(clientConfig) | ||
resources := make(resourceExporter.ResourceIDMetaMap) | ||
|
||
_, resp, err := proxy.getConversationsMessagingSupportedcontentDefault(ctx) | ||
if err != nil { | ||
if util.IsStatus404(resp) { | ||
// Don't export if config doesn't exist | ||
return resources, nil | ||
} | ||
return nil, util.BuildAPIDiagnosticError(resourceName, fmt.Sprintf("Failed to get conversations messaging supportedcontent default: %s", err), resp) | ||
} | ||
|
||
resources["0"] = &resourceExporter.ResourceMeta{Name: "supported_content_default"} | ||
|
||
return resources, nil | ||
} | ||
|
||
// createConversationsMessagingSupportedcontentDefault is used by the conversations_messaging_supportedcontent_default resource to create Genesys cloud conversations messaging supportedcontent default | ||
func createConversationsMessagingSupportedcontentDefault(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
d.SetId("supported_content_default") | ||
return updateConversationsMessagingSupportedcontentDefault(ctx, d, meta) | ||
} | ||
|
||
// readConversationsMessagingSupportedcontentDefault is used by the conversations_messaging_supportedcontent_default resource to read an conversations messaging supportedcontent default from genesys cloud | ||
func readConversationsMessagingSupportedcontentDefault(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
sdkConfig := meta.(*provider.ProviderMeta).ClientConfig | ||
proxy := getConversationsMessagingSupportedcontentDefaultProxy(sdkConfig) | ||
cc := consistency_checker.NewConsistencyCheck(ctx, d, meta, ResourceConversationsMessagingSupportedcontentDefault(), constants.DefaultConsistencyChecks, resourceName) | ||
|
||
log.Printf("Reading conversations supported content default %s", d.Id()) | ||
|
||
return util.WithRetriesForRead(ctx, d, func() *retry.RetryError { | ||
supportedContentDefault, resp, err := proxy.getConversationsMessagingSupportedcontentDefault(ctx) | ||
if err != nil { | ||
if util.IsStatus404(resp) { | ||
return retry.RetryableError(util.BuildWithRetriesApiDiagnosticError(resourceName, fmt.Sprintf("Failed to read conversations supported content default %s: %s", d.Id(), err), resp)) | ||
} | ||
return retry.NonRetryableError(util.BuildWithRetriesApiDiagnosticError(resourceName, fmt.Sprintf("Failed to read conversations supported content default %s: %s", d.Id(), err), resp)) | ||
} | ||
|
||
resourcedata.SetNillableValue(d, "content_id", supportedContentDefault.Id) | ||
|
||
log.Printf("Read conversations supported content default %s %s", d.Id(), *supportedContentDefault.Id) | ||
return cc.CheckState(d) | ||
}) | ||
} | ||
|
||
// updateConversationsMessagingSupportedcontentDefault is used by the conversations_messaging_supportedcontent_default resource to update an conversations messaging supportedcontent default in Genesys Cloud | ||
func updateConversationsMessagingSupportedcontentDefault(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
sdkConfig := meta.(*provider.ProviderMeta).ClientConfig | ||
proxy := getConversationsMessagingSupportedcontentDefaultProxy(sdkConfig) | ||
supportedContentId := d.Get("content_id").(string) | ||
|
||
conversationsMessagingSupportedcontentDefault := platformclientv2.Supportedcontentreference{ | ||
Id: &supportedContentId, | ||
} | ||
|
||
log.Printf("Updating conversations messaging supportedcontent default %s", supportedContentId) | ||
supportedContentReference, resp, err := proxy.updateConversationsMessagingSupportedcontentDefault(ctx, d.Id(), &conversationsMessagingSupportedcontentDefault) | ||
if err != nil { | ||
return util.BuildAPIDiagnosticError(resourceName, fmt.Sprintf("Failed to update conversations messaging supportedcontent default: %s", err), resp) | ||
} | ||
|
||
log.Printf("Updated conversations messaging supportedcontent default %s", *supportedContentReference.Id) | ||
return readConversationsMessagingSupportedcontentDefault(ctx, d, meta) | ||
} | ||
|
||
// deleteConversationsMessagingSupportedcontentDefault is used by the conversations_messaging_supportedcontent_default resource to delete an conversations messaging supportedcontent default from Genesys cloud | ||
func deleteConversationsMessagingSupportedcontentDefault(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
return nil | ||
} |
60 changes: 60 additions & 0 deletions
60
..._default/resource_genesyscloud_conversations_messaging_supportedcontent_default_schema.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,60 @@ | ||
package conversations_messaging_supportedcontent_default | ||
|
||
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_conversations_messaging_supportedcontent_default_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 conversations_messaging_supportedcontent_default resource. | ||
3. The datasource schema definitions for the conversations_messaging_supportedcontent_default datasource. | ||
4. The resource exporter configuration for the conversations_messaging_supportedcontent_default exporter. | ||
*/ | ||
const resourceName = "genesyscloud_conversations_messaging_supportedcontent_default" | ||
|
||
// SetRegistrar registers all of the resources, datasources and exporters in the package | ||
func SetRegistrar(regInstance registrar.Registrar) { | ||
regInstance.RegisterResource(resourceName, ResourceConversationsMessagingSupportedcontentDefault()) | ||
regInstance.RegisterExporter(resourceName, ConversationsMessagingSupportedcontentDefaultExporter()) | ||
} | ||
|
||
// ResourceConversationsMessagingSupportedcontentDefault registers the genesyscloud_conversations_messaging_supportedcontent_default resource with Terraform | ||
func ResourceConversationsMessagingSupportedcontentDefault() *schema.Resource { | ||
return &schema.Resource{ | ||
Description: `Genesys Cloud conversations messaging supportedcontent default`, | ||
|
||
CreateContext: provider.CreateWithPooledClient(createConversationsMessagingSupportedcontentDefault), | ||
ReadContext: provider.ReadWithPooledClient(readConversationsMessagingSupportedcontentDefault), | ||
UpdateContext: provider.UpdateWithPooledClient(updateConversationsMessagingSupportedcontentDefault), | ||
DeleteContext: provider.DeleteWithPooledClient(deleteConversationsMessagingSupportedcontentDefault), | ||
Importer: &schema.ResourceImporter{ | ||
StateContext: schema.ImportStatePassthroughContext, | ||
}, | ||
SchemaVersion: 1, | ||
Schema: map[string]*schema.Schema{ | ||
`content_id`: { | ||
Description: `The SupportedContent unique identifier associated with this integration`, | ||
Required: true, | ||
Type: schema.TypeString, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
// ConversationsMessagingSupportedcontentDefaultExporter returns the resourceExporter object used to hold the genesyscloud_conversations_messaging_supportedcontent_default exporter's config | ||
func ConversationsMessagingSupportedcontentDefaultExporter() *resourceExporter.ResourceExporter { | ||
return &resourceExporter.ResourceExporter{ | ||
GetResourcesFunc: provider.GetAllWithPooledClient(getAuthConversationsMessagingSupportedcontentDefaults), | ||
RefAttrs: map[string]*resourceExporter.RefAttrSettings{ | ||
"content_id": { | ||
RefType: "genesyscloud_conversations_messaging_supportedcontent", | ||
}, | ||
}, | ||
} | ||
} |
Oops, something went wrong.