Skip to content

Commit

Permalink
Feat/devtooling 655: conversations_messaging_settings resource (#1150)
Browse files Browse the repository at this point in the history
* Created Resource

* Created Resource & added tests

* Added examples

* Update tf_exporter_resource_test.go
  • Loading branch information
BrianMoyles authored Jul 18, 2024
1 parent 651e9b8 commit 537b9d8
Show file tree
Hide file tree
Showing 16 changed files with 1,160 additions and 5 deletions.
30 changes: 30 additions & 0 deletions docs/data-sources/conversations_messaging_settings.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "genesyscloud_conversations_messaging_settings Data Source - terraform-provider-genesyscloud"
subcategory: ""
description: |-
Genesys Cloud conversations messaging settings data source. Select an conversations messaging settings by name
---

# genesyscloud_conversations_messaging_settings (Data Source)

Genesys Cloud conversations messaging settings data source. Select an conversations messaging settings by name

## Example Usage

```terraform
data "genesyscloud_conversations_messaging_settings" "example-messaging-settings" {
name = "settings name"
}
```

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

### Required

- `name` (String) conversations messaging settings name

### Read-Only

- `id` (String) The ID of this resource.
116 changes: 116 additions & 0 deletions docs/resources/conversations_messaging_settings.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
---
page_title: "genesyscloud_conversations_messaging_settings Resource - terraform-provider-genesyscloud"
subcategory: ""
description: |-
Genesys Cloud conversations messaging settings
---
# genesyscloud_conversations_messaging_settings (Resource)

Genesys Cloud conversations messaging settings

## 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/conversations/messaging/settings](https://developer.genesys.cloud/devapps/api-explorer#get-api-v2-conversations-messaging-settings)
* [POST /api/v2/conversations/messaging/settings](https://developer.genesys.cloud/devapps/api-explorer#post-api-v2-conversations-messaging-settings)
* [GET /api/v2/conversations/messaging/settings/{messageSettingId}](https://developer.genesys.cloud/devapps/api-explorer#get-api-v2-conversations-messaging-settings--messageSettingId-)
* [PATCH /api/v2/conversations/messaging/settings/{messageSettingId}](https://developer.genesys.cloud/devapps/api-explorer#patch-api-v2-conversations-messaging-settings--messageSettingId-)
* [DELETE /api/v2/conversations/messaging/settings/{messageSettingId}](https://developer.genesys.cloud/devapps/api-explorer#delete-api-v2-conversations-messaging-settings--messageSettingId-)

## Example Usage

```terraform
resource "genesyscloud_conversations_messaging_settings" "example-messaging-settings" {
name = "Sample Messaging Settings"
content {
story {
mention {
inbound = "Enabled"
}
reply {
inbound = "Enabled"
}
}
}
event {
typing {
on {
inbound = "Enabled"
outbound = "Enabled"
}
}
}
}
```

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

### Required

- `name` (String) The messaging Setting profile name

### Optional

- `content` (Block List, Max: 1) Settings relating to message contents (see [below for nested schema](#nestedblock--content))
- `event` (Block List, Max: 1) Settings relating to events which may occur (see [below for nested schema](#nestedblock--event))

### Read-Only

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

<a id="nestedblock--content"></a>
### Nested Schema for `content`

Optional:

- `story` (Block List, Max: 1) Settings relating to facebook and instagram stories feature (see [below for nested schema](#nestedblock--content--story))

<a id="nestedblock--content--story"></a>
### Nested Schema for `content.story`

Optional:

- `mention` (Block List, Max: 1) Setting relating to Story Mentions (see [below for nested schema](#nestedblock--content--story--mention))
- `reply` (Block List, Max: 1) Setting relating to Story Replies (see [below for nested schema](#nestedblock--content--story--reply))

<a id="nestedblock--content--story--mention"></a>
### Nested Schema for `content.story.mention`

Optional:

- `inbound` (String) Valid values: Enabled, Disabled.


<a id="nestedblock--content--story--reply"></a>
### Nested Schema for `content.story.reply`

Optional:

- `inbound` (String) Valid values: Enabled, Disabled.




<a id="nestedblock--event"></a>
### Nested Schema for `event`

Optional:

- `typing` (Block List, Max: 1) Settings regarding typing events (see [below for nested schema](#nestedblock--event--typing))

<a id="nestedblock--event--typing"></a>
### Nested Schema for `event.typing`

Optional:

- `on` (Block List, Max: 1) Should typing indication Events be sent (see [below for nested schema](#nestedblock--event--typing--on))

<a id="nestedblock--event--typing--on"></a>
### Nested Schema for `event.typing.on`

Optional:

- `inbound` (String) Status for the Inbound Direction. Valid values: Enabled, Disabled.
- `outbound` (String) Status for the outbound Direction. Valid values: Enabled, Disabled.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
data "genesyscloud_conversations_messaging_settings" "example-messaging-settings" {
name = "settings name"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
* [GET /api/v2/conversations/messaging/settings](https://developer.genesys.cloud/devapps/api-explorer#get-api-v2-conversations-messaging-settings)
* [POST /api/v2/conversations/messaging/settings](https://developer.genesys.cloud/devapps/api-explorer#post-api-v2-conversations-messaging-settings)
* [GET /api/v2/conversations/messaging/settings/{messageSettingId}](https://developer.genesys.cloud/devapps/api-explorer#get-api-v2-conversations-messaging-settings--messageSettingId-)
* [PATCH /api/v2/conversations/messaging/settings/{messageSettingId}](https://developer.genesys.cloud/devapps/api-explorer#patch-api-v2-conversations-messaging-settings--messageSettingId-)
* [DELETE /api/v2/conversations/messaging/settings/{messageSettingId}](https://developer.genesys.cloud/devapps/api-explorer#delete-api-v2-conversations-messaging-settings--messageSettingId-)
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
resource "genesyscloud_conversations_messaging_settings" "example-messaging-settings" {
name = "Sample Messaging Settings"
content {
story {
mention {
inbound = "Enabled"
}
reply {
inbound = "Enabled"
}
}
}
event {
typing {
on {
inbound = "Enabled"
outbound = "Enabled"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package conversations_messaging_settings

import (
"context"
"fmt"
"terraform-provider-genesyscloud/genesyscloud/provider"
"terraform-provider-genesyscloud/genesyscloud/util"
"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"
)

func dataSourceConversationsMessagingSettingsRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
sdkConfig := m.(*provider.ProviderMeta).ClientConfig
proxy := getConversationsMessagingSettingsProxy(sdkConfig)
name := d.Get("name").(string)

return util.WithRetries(ctx, 15*time.Second, func() *retry.RetryError {
messageSettingsId, resp, retryable, err := proxy.getConversationsMessagingSettingsIdByName(ctx, name)
if err != nil && !retryable {
return retry.NonRetryableError(util.BuildWithRetriesApiDiagnosticError(resourceName, fmt.Sprintf("error requesting conversations messaging setting by name %s | error: %s", name, err), resp))
}

if retryable {
return retry.RetryableError(util.BuildWithRetriesApiDiagnosticError(resourceName, fmt.Sprintf("no conversations messaging setting found with name %s", name), resp))
}
d.SetId(messageSettingsId)
return nil
})
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package conversations_messaging_settings

import (
"fmt"
"terraform-provider-genesyscloud/genesyscloud/provider"
"terraform-provider-genesyscloud/genesyscloud/util"
"testing"

"github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

func TestAccDataSourceConversationsMessagingSettings(t *testing.T) {
var (
id = "conversations_messaging_settings"
dataId = "conversations_messaging_settings_data"
name = "Messaging Settings " + uuid.NewString()
)
resource.Test(t, resource.TestCase{
PreCheck: func() { util.TestAccPreCheck(t) },
ProviderFactories: provider.GetProviderFactories(providerResources, providerDataSources),
Steps: []resource.TestStep{
{
Config: generateConversationsMessagingSettingsResource(
id,
name,
generateContentStoryBlock(
generateMentionInboundOnlySetting("Enabled"),
generateReplyInboundOnlySetting("Enabled"),
),
generateTypingOnSetting(
"Enabled",
"Disabled",
),
) + generateConversationsMessagingSettingsDataSource(
dataId,
name,
"genesyscloud_conversations_messaging_settings."+id,
),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrPair("data.genesyscloud_conversations_messaging_settings."+dataId, "id",
"genesyscloud_conversations_messaging_settings."+id, "id"),
),
},
},
})
}

func generateConversationsMessagingSettingsDataSource(id, name, dependsOn string) string {
return fmt.Sprintf(`data "genesyscloud_conversations_messaging_settings" "%s" {
name = "%s"
depends_on = [%s]
}
`, id, name, dependsOn)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package conversations_messaging_settings

import (
"sync"
"testing"

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

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] = ResourceConversationsMessagingSettings()
}

// registerTestDataSources registers all data sources used in the tests.
func (r *registerTestInstance) registerTestDataSources() {
r.datasourceMapMutex.Lock()
defer r.datasourceMapMutex.Unlock()

providerDataSources[resourceName] = DataSourceConversationsMessagingSettings()
}

// initTestResources initializes all test resources and data sources.
func initTestResources() {
providerDataSources = make(map[string]*schema.Resource)
providerResources = make(map[string]*schema.Resource)

regInstance := &registerTestInstance{}

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 conversations_messaging_settings package
initTestResources()

// Run the test suite for the conversations_messaging_settings package
m.Run()
}
Loading

0 comments on commit 537b9d8

Please sign in to comment.