diff --git a/.github/workflows/test-workflow.yml b/.github/workflows/test-workflow.yml
deleted file mode 100644
index 2dcd800b0..000000000
--- a/.github/workflows/test-workflow.yml
+++ /dev/null
@@ -1,119 +0,0 @@
-name: test_workflow
-
-on:
- workflow_call:
- inputs:
- package-path:
- required: true
- type: string
- skip-regexp:
- type: string
- default: ''
- run-regexp:
- type: string
- default: ''
- test-log-artifact-name:
- type: string
- required: true
- sdk-log-artifact-name:
- type: string
- default: ''
- sdk-debug-log-file-path:
- type: string
- default: './genesyscloud/sdk_debug.log'
- running-export-tests:
- type: string
- default: 'false'
- coverage-out-filename:
- type: string
- default: ''
- coverage-html-filename:
- type: string
- default: ''
- tf-unit:
- type: string
- default: ''
- description: "used to set the TF_UNIT env variable for jobs that don't need sdk authorization"
- secrets:
- client-id:
- description: 'Genesys Cloud Client ID'
- required: true
- client-secret:
- description: 'Genesys Cloud Client Secret'
- required: true
-
-jobs:
- matrix:
- name: ''
- runs-on: ubuntu-latest
- timeout-minutes: 80
- strategy:
- fail-fast: false
- max-parallel: 2
- matrix:
- # list whatever Terraform versions here you would like to support
- terraform:
- - '1.6.6'
- steps:
- - name: Set up Go
- uses: actions/setup-go@v5
- with:
- go-version: '1.20'
- id: go
-
- - name: Setup Terraform CLI
- uses: hashicorp/setup-terraform@v3.1.1
- with:
- terraform_version: ${{ matrix.terraform }}
-
- - name: Check out code into the Go module directory
- uses: actions/checkout@v4
-
- - name: Get dependencies
- run: |
- go mod download
-
- - name: TF acceptance tests
- timeout-minutes: 80
- env:
- TF_ACC: '1'
- TF_LOG: 'DEBUG'
- TF_LOG_PATH: ${{ github.workspace }}/test.log
- TF_ACC_TERRAFORM_VERSION: ${{ matrix.terraform }}
- TF_UNIT: ${{ inputs.tf-unit }}
-
- GENESYSCLOUD_OAUTHCLIENT_ID: ${{ secrets.client-id }}
- GENESYSCLOUD_OAUTHCLIENT_SECRET: ${{ secrets.client-secret }}
- GENESYSCLOUD_REGION: 'us-east-1'
- GENESYSCLOUD_SDK_DEBUG: 'true'
- GENESYSCLOUD_TOKEN_POOL_SIZE: 20
- run: |
- if [ "$TF_ACC_TERRAFORM_VERSION" == "0.14.7" ]; then
- sleep 300 # This avoids conflicts with the API and other related issues e.g. too many routing email domains
- fi
-
- go test -timeout 80m -v -cover ${{ inputs.package-path }} -parallel 20 -coverprofile="${{ inputs.coverage-out-filename }}" -skip="${{ inputs.skip-regexp }}" -run="${{ inputs.run-regexp }}"
- go tool cover -html="${{ inputs.coverage-out-filename }}" -o="${{ inputs.coverage-html-filename }}"
- - name: 'Upload Logs'
- if: ${{ always() }}
- uses: actions/upload-artifact@v4
- with:
- name: ${{ inputs.test-log-artifact-name }} ${{ matrix.terraform }}
- path: ${{ github.workspace }}/test.log
- retention-days: 5
-
- - name: 'Upload SDK Log'
- if: ${{ always() && inputs.sdk-log-artifact-name != '' }}
- uses: actions/upload-artifact@v4
- with:
- name: ${{ inputs.sdk-log-artifact-name }} ${{ matrix.terraform }}
- path: ${{ inputs.sdk-debug-log-file-path }}
- retention-days: 5
-
- - name: 'Upload Export Result'
- if: ${{ always() && inputs.running-export-tests == 'true' }}
- uses: actions/upload-artifact@v4
- with:
- name: export-result ${{ matrix.terraform }}
- path: ${{ github.workspace }}/.terraform/
- retention-days: 5
\ No newline at end of file
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
deleted file mode 100644
index 64a7852e0..000000000
--- a/.github/workflows/test.yml
+++ /dev/null
@@ -1,129 +0,0 @@
-# This GitHub action runs your tests for each commit push and/or PR. Optionally
-# you can turn it on using a cron schedule for regular testing.
-#
-name: Tests
-on:
- push:
- paths-ignore:
- - 'README.md'
- # Run daily tests
- schedule:
- - cron: '0 10 * * *'
-jobs:
- # ensure the code builds...
- build:
- name: Build
- runs-on: ubuntu-latest
- timeout-minutes: 5
- steps:
-
- - name: Set up Go
- uses: actions/setup-go@v5
- with:
- go-version: '1.20'
- id: go
-
- - name: Check out code into the Go module directory
- uses: actions/checkout@v4
-
- - name: Get dependencies
- run: |
- go mod download
-
- - name: Build
- run: |
- go build -v .
-
- # run acceptance tests in a matrix with Terraform core versions
-
- outbound-tests:
- uses: ./.github/workflows/test-workflow.yml
- name: Outbound
- needs: build
- with:
- package-path: './genesyscloud/...'
- run-regexp: '(Outbound)+'
- coverage-out-filename: 'ob-coverage.out'
- coverage-html-filename: 'ob-coverage.html'
- test-log-artifact-name: 'outbound logs'
- secrets:
- client-id: ${{ secrets.TEST_GENESYSCLOUD_OAUTHCLIENT_ID }}
- client-secret: ${{ secrets.TEST_GENESYSCLOUD_OAUTHCLIENT_SECRET }}
-
- export-tests:
- uses: ./.github/workflows/test-workflow.yml
- name: Export
- needs: build
- with:
- package-path: './genesyscloud/tfexporter/...'
- coverage-out-filename: 'export-coverage.out'
- coverage-html-filename: 'export-coverage.html'
- running-export-tests: 'true'
- test-log-artifact-name: 'export logs'
- sdk-log-artifact-name: 'export sdk_log'
- sdk-debug-log-file-path: './genesyscloud/tfexporter/sdk_debug.log'
- secrets:
- client-id: ${{ secrets.TEST_GENESYSCLOUD_OAUTHCLIENT_ID }}
- client-secret: ${{ secrets.TEST_GENESYSCLOUD_OAUTHCLIENT_SECRET }}
-
- routing-tests:
- uses: ./.github/workflows/test-workflow.yml
- name: Routing
- needs: build
- with:
- package-path: './genesyscloud/...'
- run-regexp: '(Routing)+'
- coverage-out-filename: 'routing-coverage.out'
- coverage-html-filename: 'routing-coverage.html'
- test-log-artifact-name: 'routing logs'
- sdk-log-artifact-name: 'routing sdk_log'
- secrets:
- client-id: ${{ secrets.TEST_GENESYSCLOUD_OAUTHCLIENT_ID }}
- client-secret: ${{ secrets.TEST_GENESYSCLOUD_OAUTHCLIENT_SECRET }}
-
- all-other-unit-tests:
- uses: ./.github/workflows/test-workflow.yml
- name: All Other Unit Tests
- needs: build
- with:
- package-path: './genesyscloud/...'
- skip-regexp: 'TfExport|Outbound|Routing|TestAccDataSource|TestAccResource'
- coverage-out-filename: 'unit-coverage.out'
- coverage-html-filename: 'unit-coverage.html'
- test-log-artifact-name: 'unit test logs'
- tf-unit: '*'
- secrets:
- client-id: ${{ secrets.TEST_GENESYSCLOUD_OAUTHCLIENT_ID }}
- client-secret: ${{ secrets.TEST_GENESYSCLOUD_OAUTHCLIENT_SECRET }}
-
- all-other-datasource-tests:
- needs: build
- if: ${{ always() }}
- uses: ./.github/workflows/test-workflow.yml
- name: All Other DataSource Tests
- with:
- package-path: './genesyscloud/...'
- skip-regexp: '(TfExport)+|(Outbound)+|(Routing)+'
- run-regexp: 'TestAccDataSource'
- coverage-out-filename: 'data-source-coverage.out'
- coverage-html-filename: 'data-source-coverage.html'
- test-log-artifact-name: 'data source tests logs'
- secrets:
- client-id: ${{ secrets.TEST_GENESYSCLOUD_OAUTHCLIENT_ID }}
- client-secret: ${{ secrets.TEST_GENESYSCLOUD_OAUTHCLIENT_SECRET }}
-
- all-other-resource-tests:
- uses: ./.github/workflows/test-workflow.yml
- name: All Other Resource Tests
- needs: build
- if: ${{ always() }}
- with:
- package-path: './genesyscloud/...'
- skip-regexp: '(TfExport)+|(Outbound)+|(Routing)+'
- run-regexp: 'TestAccResource'
- coverage-out-filename: 'resource-coverage.out'
- coverage-html-filename: 'resource-coverage.html'
- test-log-artifact-name: 'resource tests logs'
- secrets:
- client-id: ${{ secrets.TEST_GENESYSCLOUD_OAUTHCLIENT_ID }}
- client-secret: ${{ secrets.TEST_GENESYSCLOUD_OAUTHCLIENT_SECRET }}
\ No newline at end of file
diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml
new file mode 100644
index 000000000..182d72809
--- /dev/null
+++ b/.github/workflows/unit-tests.yml
@@ -0,0 +1,27 @@
+name: Unit Tests
+on:
+ push:
+ paths-ignore:
+ - 'README.md'
+jobs:
+ unit-tests:
+ name: Unit Tests
+ runs-on: ubuntu-latest
+ timeout-minutes: 10
+ steps:
+ - name: Set up Go
+ uses: actions/setup-go@v5
+ with:
+ go-version: '1.20'
+ id: go
+
+ - name: Check out code into the Go module directory
+ uses: actions/checkout@v4
+
+ - name: Run Unit Tests
+ env:
+ TF_UNIT: '*'
+ ENABLE_STANDALONE_CGR: 'true'
+ ENABLE_STANDALONE_EMAIL_ADDRESS: 'true'
+ run: |
+ go test ./genesyscloud/... -v -run TestUnit
\ No newline at end of file
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/data-sources/task_management_worktype_status.md b/docs/data-sources/task_management_worktype_status.md
index 5e65a8420..3daf73e65 100644
--- a/docs/data-sources/task_management_worktype_status.md
+++ b/docs/data-sources/task_management_worktype_status.md
@@ -3,22 +3,29 @@
page_title: "genesyscloud_task_management_worktype_status Data Source - terraform-provider-genesyscloud"
subcategory: ""
description: |-
- Genesys Cloud task management worktype_status data source. Select a status by worktype name and status name
+ Genesys Cloud task management worktype status data source. Select an task management worktype status by name
---
# genesyscloud_task_management_worktype_status (Data Source)
-Genesys Cloud task management worktype_status data source. Select a status by worktype name and status name
+Genesys Cloud task management worktype status data source. Select an task management worktype status by name
+## Example Usage
+```terraform
+data "genesyscloud_task_management_worktype_status" "status_sample" {
+ worktype_id = genesyscloud_task_management_worktype.example.id
+ name = "Worktype status"
+}
+```
## Schema
### Required
-- `worktype_name` (String) Task management worktype name
-- `worktype_status_name` (String) Task management worktype status name
+- `name` (String) Task management worktype status name
+- `worktype_id` (String) The id of the worktype the status belongs to
### Read-Only
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/docs/resources/quality_forms_evaluation.md b/docs/resources/quality_forms_evaluation.md
index 34c06fd9c..2cbb55aa5 100644
--- a/docs/resources/quality_forms_evaluation.md
+++ b/docs/resources/quality_forms_evaluation.md
@@ -102,7 +102,7 @@ resource "genesyscloud_quality_forms_evaluation" "example-evaluation-form" {
### Optional
-- `published` (Boolean) Specifies if the evalutaion form is published. Defaults to `false`.
+- `published` (Boolean) Specifies if the evaluation form is published. Defaults to `false`.
### Read-Only
@@ -125,6 +125,10 @@ Optional:
- `na_enabled` (Boolean) Specifies whether a not applicable answer is enabled. Defaults to `false`.
- `visibility_condition` (Block List, Max: 1) Defines conditions where question would be visible (see [below for nested schema](#nestedblock--question_groups--visibility_condition))
+Read-Only:
+
+- `id` (String) ID of the question group.
+
### Nested Schema for `question_groups.questions`
@@ -142,6 +146,10 @@ Optional:
- `na_enabled` (Boolean) Specifies whether a not applicable answer is enabled. Defaults to `false`.
- `visibility_condition` (Block List, Max: 1) Defines conditions where question would be visible (see [below for nested schema](#nestedblock--question_groups--questions--visibility_condition))
+Read-Only:
+
+- `id` (String) ID of the question.
+
### Nested Schema for `question_groups.questions.answer_options`
@@ -150,6 +158,10 @@ Required:
- `text` (String)
- `value` (Number)
+Read-Only:
+
+- `id` (String) The ID for the answer option.
+
### Nested Schema for `question_groups.questions.visibility_condition`
diff --git a/docs/resources/quality_forms_survey.md b/docs/resources/quality_forms_survey.md
index 9e21ce611..655848456 100644
--- a/docs/resources/quality_forms_survey.md
+++ b/docs/resources/quality_forms_survey.md
@@ -129,6 +129,10 @@ Optional:
- `na_enabled` (Boolean) Specifies whether a not applicable answer is enabled. Defaults to `false`.
- `visibility_condition` (Block List, Max: 1) Defines conditions where question would be visible (see [below for nested schema](#nestedblock--question_groups--visibility_condition))
+Read-Only:
+
+- `id` (String) The ID of the survey question group.
+
### Nested Schema for `question_groups.questions`
@@ -146,6 +150,10 @@ Optional:
- `type` (String) Valid Values: multipleChoiceQuestion, freeTextQuestion, npsQuestion, readOnlyTextBlockQuestion Defaults to `multipleChoiceQuestion`.
- `visibility_condition` (Block List, Max: 1) Defines conditions where question would be visible (see [below for nested schema](#nestedblock--question_groups--questions--visibility_condition))
+Read-Only:
+
+- `id` (String) The ID of the survey question.
+
### Nested Schema for `question_groups.questions.answer_options`
@@ -156,14 +164,21 @@ Required:
Optional:
-- `assistance_conditions` (Block List) Options from which to choose an answer for this question. (see [below for nested schema](#nestedblock--question_groups--questions--answer_options--assistance_conditions))
+- `assistance_conditions` (Block Set) Options from which to choose an answer for this question. (see [below for nested schema](#nestedblock--question_groups--questions--answer_options--assistance_conditions))
+
+Read-Only:
+
+- `id` (String) The ID of the survey answer option.
### Nested Schema for `question_groups.questions.answer_options.assistance_conditions`
-Optional:
+Required:
- `operator` (String) List of assistance conditions which are combined together with a logical AND operator. Eg ( assistanceCondtion1 && assistanceCondition2 ) wherein assistanceCondition could be ( EXISTS topic1 || topic2 || ... ) or (NOTEXISTS topic3 || topic4 || ...).
+
+Optional:
+
- `topic_ids` (List of String) List of topicIds within the assistance condition which would be combined together using logical OR operator. Eg ( topicId_1 || topicId_2 ) .
diff --git a/docs/resources/routing_skill_group.md b/docs/resources/routing_skill_group.md
index 0db74782a..a9b8eb6fe 100644
--- a/docs/resources/routing_skill_group.md
+++ b/docs/resources/routing_skill_group.md
@@ -55,7 +55,7 @@ resource "genesyscloud_routing_skill_group" "skillgroup" {
- `description` (String) Description of the skill group
- `division_id` (String) The division to which this entity belongs
-- `member_division_ids` (List of String) The IDs of member divisions to add or remove for this skill group. An empty array means all divisions will be removed, "*" means all divisions will be added.
+- `member_division_ids` (List of String) The IDs of member divisions to add or remove for this skill group. An empty array means all divisions will be removed, '*' means all divisions will be added.
- `skill_conditions` (String) JSON encoded array of rules that will be used to determine group membership.
### Read-Only
diff --git a/docs/resources/task_management_worktype.md b/docs/resources/task_management_worktype.md
index 0b2b8acaf..12b026ac7 100644
--- a/docs/resources/task_management_worktype.md
+++ b/docs/resources/task_management_worktype.md
@@ -16,12 +16,6 @@ The following Genesys Cloud APIs are used by this resource. Ensure your OAuth Cl
* [PATCH /api/v2/taskmanagement/worktypes/{worktypeId}](https://developer.genesys.cloud/platform/preview-apis#patch-api-v2-taskmanagement-worktypes--worktypeId-)
* [DELETE /api/v2/taskmanagement/worktypes/{worktypeId}](https://developer.genesys.cloud/platform/preview-apis#delete-api-v2-taskmanagement-worktypes--worktypeId-)
* [POST /api/v2/taskmanagement/worktypes/query](https://developer.genesys.cloud/platform/preview-apis#post-api-v2-taskmanagement-worktypes-query)
-* [POST /api/v2/taskmanagement/worktypes/{worktypeId}/statuses](https://developer.genesys.cloud/platform/preview-apis#post-api-v2-taskmanagement-worktypes--worktypeId--statuses)
-* [GET /api/v2/taskmanagement/worktypes/{worktypeId}/statuses/{statusId}](https://developer.genesys.cloud/platform/preview-apis#get-api-v2-taskmanagement-worktypes--worktypeId--statuses--statusId-)
-* [PATCH /api/v2/taskmanagement/worktypes/{worktypeId}/statuses/{statusId}](https://developer.genesys.cloud/platform/preview-apis#patch-api-v2-taskmanagement-worktypes--worktypeId--statuses--statusId-)
-* [DELETE /api/v2/taskmanagement/worktypes/{worktypeId}/statuses/{statusId}](https://developer.genesys.cloud/platform/preview-apis#delete-api-v2-taskmanagement-worktypes--worktypeId--statuses--statusId-)
-
-
## Example Usage
@@ -45,36 +39,6 @@ resource "genesyscloud_task_management_worktype" "worktype_1" {
default_skills_ids = [genesyscloud_routing_skill.skill_1.id, genesyscloud_routing_skill.skill_2.id]
assignment_enabled = true
-
- defaultStatusName = "Open Status"
-
- statuses {
- name = "Open Status"
- description = "Description of open status"
- category = "Open"
- destination_status_names = ["WIP", "Waiting Status"]
- default_destination_status_name = "WIP"
- status_transition_delay_seconds = 86500
- status_transition_time = "04:20:00"
- }
-
- statuses {
- name = "WIP"
- description = "Description of WIP status"
- category = "InProgress"
- }
-
- statuses {
- name = "Waiting Status"
- description = "Description of waiting status"
- category = "Waiting"
- }
-
- statuses {
- name = "Close Status"
- description = "Description of close status"
- category = "Closed"
- }
}
```
@@ -97,34 +61,12 @@ resource "genesyscloud_task_management_worktype" "worktype_1" {
- `default_priority` (Number) The default priority for Workitems created from the Worktype. The valid range is between -25,000,000 and 25,000,000.
- `default_queue_id` (String) The default queue for Workitems created from the Worktype.
- `default_skills_ids` (List of String) The default skills for Workitems created from the Worktype.
-- `default_status_name` (String) The name of the default status for Workitems created from the Worktype. This status should be defined in 'statuses'.
- `default_ttl_seconds` (Number) The default time to time to live in seconds for Workitems created from the Worktype.
- `description` (String) The description of the Worktype.
- `division_id` (String) The division to which this entity belongs.
- `schema_version` (Number) Version of the workitem schema to use. If not provided, the worktype will use the latest version.
-- `statuses` (Block Set) The list of possible statuses for Workitems created from the Worktype. (see [below for nested schema](#nestedblock--statuses))
### Read-Only
- `id` (String) The ID of this resource.
-
-### Nested Schema for `statuses`
-
-Required:
-
-- `category` (String) The Category of the Status.
-- `name` (String) Name of the status
-
-Optional:
-
-- `default_destination_status_name` (String) Name of the default destination status to which this Status will transition to if auto status transition enabled.
-- `description` (String) The description of the Status.
-- `destination_status_names` (List of String) The names of the Statuses the Status can transition to. If null, the status can transition to any other status.
-- `status_transition_delay_seconds` (Number) Delay in seconds for auto status transition
-- `status_transition_time` (String) Time (HH:MM:SS format) at which auto status transition will occur after statusTransitionDelaySeconds delay. To set Time, the statusTransitionDelaySeconds must be equal to or greater than 86400 i.e. a day
-
-Read-Only:
-
-- `id` (String) Read-only identifier of the workitem status
-
diff --git a/docs/resources/task_management_worktype_status.md b/docs/resources/task_management_worktype_status.md
new file mode 100644
index 000000000..867374e36
--- /dev/null
+++ b/docs/resources/task_management_worktype_status.md
@@ -0,0 +1,59 @@
+---
+page_title: "genesyscloud_task_management_worktype_status Resource - terraform-provider-genesyscloud"
+subcategory: ""
+description: |-
+ Genesys Cloud task management worktype status
+---
+# genesyscloud_task_management_worktype_status (Resource)
+
+Genesys Cloud task management worktype status
+
+## 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/taskmanagement/worktypes/{worktypeId}/statuses](https://developer.genesys.cloud/devapps/api-explorer#get-api-v2-taskmanagement-worktypes--worktypeId--statuses)
+* [POST /api/v2/taskmanagement/worktypes/{worktypeId}/statuses](https://developer.genesys.cloud/devapps/api-explorer#post-api-v2-taskmanagement-worktypes--worktypeId--statuses)
+* [GET /api/v2/taskmanagement/worktypes/{worktypeId}/statuses/{statusId}](https://developer.genesys.cloud/devapps/api-explorer#get-api-v2-taskmanagement-worktypes--worktypeId--statuses--statusId-)
+* [PATCH /api/v2/taskmanagement/worktypes/{worktypeId}/statuses/{statusId}](https://developer.genesys.cloud/devapps/api-explorer#patch-api-v2-taskmanagement-worktypes--worktypeId--statuses--statusId-)
+* [DELETE /api/v2/taskmanagement/worktypes/{worktypeId}/statuses/{statusId}](https://developer.genesys.cloud/devapps/api-explorer#delete-api-v2-taskmanagement-worktypes--worktypeId--statuses--statusId-)
+
+
+
+## Example Usage
+
+```terraform
+resource "genesyscloud_task_management_worktype_status" "worktype_status" {
+ worktype_id = genesyscloud_task_management_worktype.example.id
+ name = "Open Status"
+ description = "Description of open status"
+ category = "Open"
+ destination_status_ids = [genesyscloud_task_management_worktype_status.status1.id, genesyscloud_task_management_worktype_status.status2.id]
+ default_destination_status_id = genesyscloud_task_management_worktype_status.status1.id
+ status_transition_delay_seconds = 86500
+ status_transition_time = "04:20:00"
+ default = false
+}
+```
+
+
+## Schema
+
+### Required
+
+- `category` (String) The Category of the Status. Changing the category will cause the resource to be dropped and recreated with a new id.
+- `name` (String) Name of the status.
+- `worktype_id` (String) The id of the worktype this status belongs to. Changing this attribute will cause the status to be dropped and recreated.
+
+### Optional
+
+- `default` (Boolean) This status is the default status for Workitems created from this Worktype. Only one status can be set as the default status at a time.
+- `default_destination_status_id` (String) Default destination status to which this Status will transition to if auto status transition enabled.
+- `description` (String) The description of the Status.
+- `destination_status_ids` (List of String) A list of destination Statuses where a Workitem with this Status can transition to. If the list is empty Workitems with this Status can transition to all other Statuses defined on the Worktype. A Status can have a maximum of 24 destinations.
+- `status_transition_delay_seconds` (Number) Delay in seconds for auto status transition. Required if default_destination_status_id is provided.
+- `status_transition_time` (String) Time is represented as an ISO-8601 string without a timezone. For example: HH:mm:ss
+
+### Read-Only
+
+- `id` (String) The ID of this resource.
+
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/data-sources/genesyscloud_task_management_worktype_status/data-source.tf b/examples/data-sources/genesyscloud_task_management_worktype_status/data-source.tf
new file mode 100644
index 000000000..f2750b160
--- /dev/null
+++ b/examples/data-sources/genesyscloud_task_management_worktype_status/data-source.tf
@@ -0,0 +1,4 @@
+data "genesyscloud_task_management_worktype_status" "status_sample" {
+ worktype_id = genesyscloud_task_management_worktype.example.id
+ name = "Worktype status"
+}
\ 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/examples/resources/genesyscloud_flow/inboundcall_flow_example2.yaml b/examples/resources/genesyscloud_flow/inboundcall_flow_example2.yaml
index c24e41399..0abbea664 100644
--- a/examples/resources/genesyscloud_flow/inboundcall_flow_example2.yaml
+++ b/examples/resources/genesyscloud_flow/inboundcall_flow_example2.yaml
@@ -1,17 +1,24 @@
-inboundCall:
- name: Terraform Flow Test-0f374aca-4d2e-4959-b1bb-9b4fa37e6c73
- description: test description 2
- defaultLanguage: en-us
- startUpRef: ./menus/menu[mainMenu]
- initialGreeting:
- tts: Archy says hi!!!!!
- menus:
- - menu:
- name: Main Menu
- audio:
- tts: You are at the Main Menu, press 9 to disconnect.
- refId: mainMenu
- choices:
- - menuDisconnect:
- name: Disconnect
- dtmf: digit_9
+inboundEmail:
+ name: Terraform Flow Test-d0c40522-88e4-4b66-aa48-f237afb819e0
+ division: New Home
+ startUpRef: "/inboundEmail/states/state[Initial State_10]"
+ defaultLanguage: en-us
+ supportedLanguages:
+ en-us:
+ defaultLanguageSkill:
+ noValue: true
+ settingsInboundEmailHandling:
+ emailHandling:
+ disconnect:
+ none: true
+ settingsErrorHandling:
+ errorHandling:
+ disconnect:
+ none: true
+ states:
+ - state:
+ name: Initial State
+ refId: Initial State_10
+ actions:
+ - disconnect:
+ name: Disconnect
diff --git a/examples/resources/genesyscloud_flow/inboundcall_flow_example3.yaml b/examples/resources/genesyscloud_flow/inboundcall_flow_example3.yaml
index ebf3cf1f7..251469ed7 100644
--- a/examples/resources/genesyscloud_flow/inboundcall_flow_example3.yaml
+++ b/examples/resources/genesyscloud_flow/inboundcall_flow_example3.yaml
@@ -1,24 +1,16 @@
-inboundEmail:
- name: Terraform Flow Test-0f374aca-4d2e-4959-b1bb-9b4fa37e6c73
- description: test description 1
- startUpRef: "/inboundEmail/states/state[Initial State_10]"
- defaultLanguage: en-us
- supportedLanguages:
- en-us:
- defaultLanguageSkill:
- noValue: true
- settingsInboundEmailHandling:
- emailHandling:
- disconnect:
- none: true
- settingsErrorHandling:
- errorHandling:
- disconnect:
- none: true
- states:
- - state:
- name: Initial State
- refId: Initial State_10
- actions:
- - disconnect:
- name: Disconnect
+inboundCall:
+ name: Terraform Flow Test-e602c7ba-318e-4373-99bb-bdf69dcc7600
+ defaultLanguage: en-us
+ startUpRef: ./menus/menu[mainMenu]
+ initialGreeting:
+ tts: Archy says hi!!!!!
+ menus:
+ - menu:
+ name: Main Menu
+ audio:
+ tts: You are at the Main Menu, press 9 to disconnect.
+ refId: mainMenu
+ choices:
+ - menuDisconnect:
+ name: Disconnect
+ dtmf: digit_9
\ No newline at end of file
diff --git a/examples/resources/genesyscloud_task_management_worktype/apis.md b/examples/resources/genesyscloud_task_management_worktype/apis.md
index b37164149..269d1dc79 100644
--- a/examples/resources/genesyscloud_task_management_worktype/apis.md
+++ b/examples/resources/genesyscloud_task_management_worktype/apis.md
@@ -2,9 +2,4 @@
* [GET /api/v2/taskmanagement/worktypes/{worktypeId}](https://developer.genesys.cloud/platform/preview-apis#get-api-v2-taskmanagement-worktypes--worktypeId-)
* [PATCH /api/v2/taskmanagement/worktypes/{worktypeId}](https://developer.genesys.cloud/platform/preview-apis#patch-api-v2-taskmanagement-worktypes--worktypeId-)
* [DELETE /api/v2/taskmanagement/worktypes/{worktypeId}](https://developer.genesys.cloud/platform/preview-apis#delete-api-v2-taskmanagement-worktypes--worktypeId-)
-* [POST /api/v2/taskmanagement/worktypes/query](https://developer.genesys.cloud/platform/preview-apis#post-api-v2-taskmanagement-worktypes-query)
-* [POST /api/v2/taskmanagement/worktypes/{worktypeId}/statuses](https://developer.genesys.cloud/platform/preview-apis#post-api-v2-taskmanagement-worktypes--worktypeId--statuses)
-* [GET /api/v2/taskmanagement/worktypes/{worktypeId}/statuses/{statusId}](https://developer.genesys.cloud/platform/preview-apis#get-api-v2-taskmanagement-worktypes--worktypeId--statuses--statusId-)
-* [PATCH /api/v2/taskmanagement/worktypes/{worktypeId}/statuses/{statusId}](https://developer.genesys.cloud/platform/preview-apis#patch-api-v2-taskmanagement-worktypes--worktypeId--statuses--statusId-)
-* [DELETE /api/v2/taskmanagement/worktypes/{worktypeId}/statuses/{statusId}](https://developer.genesys.cloud/platform/preview-apis#delete-api-v2-taskmanagement-worktypes--worktypeId--statuses--statusId-)
-
+* [POST /api/v2/taskmanagement/worktypes/query](https://developer.genesys.cloud/platform/preview-apis#post-api-v2-taskmanagement-worktypes-query)
\ No newline at end of file
diff --git a/examples/resources/genesyscloud_task_management_worktype/resource.tf b/examples/resources/genesyscloud_task_management_worktype/resource.tf
index 2daa3cd4b..63ea39da6 100644
--- a/examples/resources/genesyscloud_task_management_worktype/resource.tf
+++ b/examples/resources/genesyscloud_task_management_worktype/resource.tf
@@ -17,34 +17,4 @@ resource "genesyscloud_task_management_worktype" "worktype_1" {
default_skills_ids = [genesyscloud_routing_skill.skill_1.id, genesyscloud_routing_skill.skill_2.id]
assignment_enabled = true
-
- defaultStatusName = "Open Status"
-
- statuses {
- name = "Open Status"
- description = "Description of open status"
- category = "Open"
- destination_status_names = ["WIP", "Waiting Status"]
- default_destination_status_name = "WIP"
- status_transition_delay_seconds = 86500
- status_transition_time = "04:20:00"
- }
-
- statuses {
- name = "WIP"
- description = "Description of WIP status"
- category = "InProgress"
- }
-
- statuses {
- name = "Waiting Status"
- description = "Description of waiting status"
- category = "Waiting"
- }
-
- statuses {
- name = "Close Status"
- description = "Description of close status"
- category = "Closed"
- }
}
diff --git a/examples/resources/genesyscloud_task_management_worktype_status/apis.md b/examples/resources/genesyscloud_task_management_worktype_status/apis.md
new file mode 100644
index 000000000..30d943b39
--- /dev/null
+++ b/examples/resources/genesyscloud_task_management_worktype_status/apis.md
@@ -0,0 +1,6 @@
+* [GET /api/v2/taskmanagement/worktypes/{worktypeId}/statuses](https://developer.genesys.cloud/devapps/api-explorer#get-api-v2-taskmanagement-worktypes--worktypeId--statuses)
+* [POST /api/v2/taskmanagement/worktypes/{worktypeId}/statuses](https://developer.genesys.cloud/devapps/api-explorer#post-api-v2-taskmanagement-worktypes--worktypeId--statuses)
+* [GET /api/v2/taskmanagement/worktypes/{worktypeId}/statuses/{statusId}](https://developer.genesys.cloud/devapps/api-explorer#get-api-v2-taskmanagement-worktypes--worktypeId--statuses--statusId-)
+* [PATCH /api/v2/taskmanagement/worktypes/{worktypeId}/statuses/{statusId}](https://developer.genesys.cloud/devapps/api-explorer#patch-api-v2-taskmanagement-worktypes--worktypeId--statuses--statusId-)
+* [DELETE /api/v2/taskmanagement/worktypes/{worktypeId}/statuses/{statusId}](https://developer.genesys.cloud/devapps/api-explorer#delete-api-v2-taskmanagement-worktypes--worktypeId--statuses--statusId-)
+
diff --git a/examples/resources/genesyscloud_task_management_worktype_status/resource.tf b/examples/resources/genesyscloud_task_management_worktype_status/resource.tf
new file mode 100644
index 000000000..bfb1f7fc2
--- /dev/null
+++ b/examples/resources/genesyscloud_task_management_worktype_status/resource.tf
@@ -0,0 +1,11 @@
+resource "genesyscloud_task_management_worktype_status" "worktype_status" {
+ worktype_id = genesyscloud_task_management_worktype.example.id
+ name = "Open Status"
+ description = "Description of open status"
+ category = "Open"
+ destination_status_ids = [genesyscloud_task_management_worktype_status.status1.id, genesyscloud_task_management_worktype_status.status2.id]
+ default_destination_status_id = genesyscloud_task_management_worktype_status.status1.id
+ status_transition_delay_seconds = 86500
+ status_transition_time = "04:20:00"
+ default = false
+}
diff --git a/genesyscloud/architect_ivr/genesyscloud_architect_ivr_proxy_unit_test.go b/genesyscloud/architect_ivr/genesyscloud_architect_ivr_proxy_unit_test.go
index a49095e59..f2cce00a6 100644
--- a/genesyscloud/architect_ivr/genesyscloud_architect_ivr_proxy_unit_test.go
+++ b/genesyscloud/architect_ivr/genesyscloud_architect_ivr_proxy_unit_test.go
@@ -87,8 +87,8 @@ func TestUnitUploadIvrDnisChunksError(t *testing.T) {
mockGetError = fmt.Errorf("error on proxy.GetArchitectIvr")
mockPostError = fmt.Errorf("error on proxy.PostArchitectIvr")
mockPutError = fmt.Errorf("error on proxy.PutArchitectIvr")
- dnis = []string{"123", "abc", "iii", "zzz"}
maxDnisPerRequest = 2
+ dnis = []string{"123", "abc", "iii", "zzz"}
)
ivr := platformclientv2.Ivr{
@@ -98,7 +98,7 @@ func TestUnitUploadIvrDnisChunksError(t *testing.T) {
architectProxy := newArchitectIvrProxy(nil)
architectProxy.maxDnisPerRequest = maxDnisPerRequest
- // will be called on create after a chunk update fails because the ivr will need to be manually taken down, in that case
+ // Will be called on create after a chunk update fails because the ivr will need to be manually taken down, in that case
architectProxy.deleteArchitectIvrAttr = createMockDeleteIvrFunc(nil)
testCases := []architectIvrUploadErrorTestData{
diff --git a/genesyscloud/architect_ivr/resource_genesyscloud_architect_ivr_unit_test.go b/genesyscloud/architect_ivr/resource_genesyscloud_architect_ivr_unit_test.go
index 6b8073966..54d0f2c93 100644
--- a/genesyscloud/architect_ivr/resource_genesyscloud_architect_ivr_unit_test.go
+++ b/genesyscloud/architect_ivr/resource_genesyscloud_architect_ivr_unit_test.go
@@ -232,7 +232,7 @@ func TestUnitResourceArchitectCreate(t *testing.T) {
archProxy.createArchitectIvrAttr = func(ctx context.Context, a *architectIvrProxy, ivr platformclientv2.Ivr) (*platformclientv2.Ivr, *platformclientv2.APIResponse, error) {
assert.Equal(t, tName, *ivr.Name, "ivr.Name check failed in create createArchitectIvrAttr")
assert.Equal(t, tDescription, *ivr.Description, "ivr.Description check failed in create createArchitectIvrAttr")
- assert.EqualValues(t, &tDnis, ivr.Dnis, "ivr.Dnis check failed in create createArchitectIvrAttr")
+ assert.ElementsMatch(t, tDnis, *ivr.Dnis, "ivr.Dnis check failed in create createArchitectIvrAttr")
assert.Equal(t, tOpenHoursFlowId, *ivr.OpenHoursFlow.Id, "ivr.OpenHoursFlow.Id check failed in create createArchitectIvrAttr")
assert.Equal(t, tClosedHoursFlowId, *ivr.ClosedHoursFlow.Id, "ivr.ClosedHoursFlow.Id check failed in create createArchitectIvrAttr")
assert.Equal(t, tHolidayHoursFlowId, *ivr.HolidayHoursFlow.Id, "ivr.HolidayHoursFlow.Id check failed in create createArchitectIvrAttr")
@@ -303,7 +303,7 @@ func TestUnitResourceArchitectUpdate(t *testing.T) {
archProxy.updateArchitectIvrAttr = func(ctx context.Context, a *architectIvrProxy, id string, ivr platformclientv2.Ivr) (*platformclientv2.Ivr, *platformclientv2.APIResponse, error) {
assert.Equal(t, tName, *ivr.Name, "ivr.Name check failed in create updateArchitectIvrAttr")
assert.Equal(t, tDescription, *ivr.Description, "ivr.Description check failed in updateArchitectIvrAttr")
- assert.EqualValues(t, &tDnis, ivr.Dnis, "ivr.Dnis check failed in updateArchitectIvrAttr")
+ assert.ElementsMatch(t, tDnis, *ivr.Dnis, "ivr.Dnis check failed in updateArchitectIvrAttr")
assert.Equal(t, tOpenHoursFlowId, *ivr.OpenHoursFlow.Id, "ivr.OpenHoursFlow.Id check failed in updateArchitectIvrAttr")
assert.Equal(t, tClosedHoursFlowId, *ivr.ClosedHoursFlow.Id, "ivr.ClosedHoursFlow.Id check failed in updateArchitectIvrAttr")
assert.Equal(t, tHolidayHoursFlowId, *ivr.HolidayHoursFlow.Id, "ivr.HolidayHoursFlow.Id check failed in updateArchitectIvrAttr")
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/data_source_genesyscloud_quality_forms_evaluation.go b/genesyscloud/data_source_genesyscloud_quality_forms_evaluation.go
index 52aef5fed..addb5f443 100644
--- a/genesyscloud/data_source_genesyscloud_quality_forms_evaluation.go
+++ b/genesyscloud/data_source_genesyscloud_quality_forms_evaluation.go
@@ -43,8 +43,14 @@ type EvaluationFormQuestionStruct struct {
}
type AnswerOptionStruct struct {
- Text string
- Value int
+ Text string
+ Value int
+ AssistanceConditions []AssistanceConditionStruct
+}
+
+type AssistanceConditionStruct struct {
+ Operator string
+ TopicIds []string
}
type VisibilityConditionStruct struct {
diff --git a/genesyscloud/data_source_genesyscloud_routing_skill.go b/genesyscloud/data_source_genesyscloud_routing_skill.go
deleted file mode 100644
index bf82e832d..000000000
--- a/genesyscloud/data_source_genesyscloud_routing_skill.go
+++ /dev/null
@@ -1,129 +0,0 @@
-package genesyscloud
-
-import (
- "context"
- "fmt"
- "log"
- "terraform-provider-genesyscloud/genesyscloud/provider"
- rc "terraform-provider-genesyscloud/genesyscloud/resource_cache"
- "terraform-provider-genesyscloud/genesyscloud/util"
- "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"
- "github.com/mypurecloud/platform-client-sdk-go/v133/platformclientv2"
-)
-
-// The context is now added without Timeout ,
-// since the warming up of cache will take place for the first Datasource registered during a Terraform Apply.
-func dataSourceRoutingSkill() *schema.Resource {
- return &schema.Resource{
- Description: "Data source for Genesys Cloud Routing Skills. Select a skill by name.",
- ReadWithoutTimeout: provider.ReadWithPooledClient(dataSourceRoutingSkillRead),
- Schema: map[string]*schema.Schema{
- "name": {
- Description: "Skill name.",
- Type: schema.TypeString,
- Required: true,
- },
- },
- }
-}
-
-var (
- dataSourceRoutingSkillCache *rc.DataSourceCache
-)
-
-func dataSourceRoutingSkillRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
- sdkConfig := m.(*provider.ProviderMeta).ClientConfig
-
- key := d.Get("name").(string)
-
- if dataSourceRoutingSkillCache == nil {
- dataSourceRoutingSkillCache = rc.NewDataSourceCache(sdkConfig, hydrateRoutingSkillCacheFn, getSkillByNameFn)
- }
-
- queueId, err := rc.RetrieveId(dataSourceRoutingSkillCache, "genesyscloud_routing_skill", key, ctx)
-
- if err != nil {
- return err
- }
-
- d.SetId(queueId)
- return nil
-}
-
-func hydrateRoutingSkillCacheFn(c *rc.DataSourceCache) error {
- log.Printf("hydrating cache for data source genesyscloud_routing_skill")
-
- routingApi := platformclientv2.NewRoutingApiWithConfig(c.ClientConfig)
- const pageSize = 100
- skills, _, getErr := routingApi.GetRoutingSkills(pageSize, 1, "", nil)
-
- if getErr != nil {
- return fmt.Errorf("failed to get page of skills: %v", getErr)
- }
-
- if skills.Entities == nil || len(*skills.Entities) == 0 {
- return nil
- }
-
- for _, skill := range *skills.Entities {
- c.Cache[*skill.Name] = *skill.Id
- }
-
- for pageNum := 2; pageNum <= *skills.PageCount; pageNum++ {
-
- log.Printf("calling cache for data source genesyscloud_routing_skill")
-
- skills, _, getErr := routingApi.GetRoutingSkills(pageSize, pageNum, "", nil)
- log.Printf("calling cache for data source genesyscloud_routing_skill %v", pageNum)
- if getErr != nil {
- return fmt.Errorf("failed to get page of skills: %v", getErr)
- }
-
- if skills.Entities == nil || len(*skills.Entities) == 0 {
- break
- }
-
- // Add ids to cache
- for _, skill := range *skills.Entities {
- c.Cache[*skill.Name] = *skill.Id
- }
- }
-
- log.Printf("cache hydration completed for data source genesyscloud_routing_skill")
-
- return nil
-}
-
-func getSkillByNameFn(c *rc.DataSourceCache, name string, ctx context.Context) (string, diag.Diagnostics) {
- const pageSize = 100
- skillId := ""
- routingAPI := platformclientv2.NewRoutingApiWithConfig(c.ClientConfig)
-
- // Find first non-deleted skill by name. Retry in case new skill is not yet indexed by search
- diag := util.WithRetries(ctx, 15*time.Second, func() *retry.RetryError {
- for pageNum := 1; ; pageNum++ {
- skills, resp, getErr := routingAPI.GetRoutingSkills(pageSize, pageNum, name, nil)
- if getErr != nil {
- return retry.NonRetryableError(util.BuildWithRetriesApiDiagnosticError("genesyscloud_routing_skill", fmt.Sprintf("error requesting skill %s | error: %s", name, getErr), resp))
- }
-
- if skills.Entities == nil || len(*skills.Entities) == 0 {
- return retry.RetryableError(util.BuildWithRetriesApiDiagnosticError("genesyscloud_routing_skill", fmt.Sprintf("no routing skills found with name %s", name), resp))
- }
-
- for _, skill := range *skills.Entities {
- if skill.Name != nil && *skill.Name == name &&
- skill.State != nil && *skill.State != "deleted" {
- skillId = *skill.Id
- return nil
- }
- }
- }
- })
- return skillId, diag
-}
diff --git a/genesyscloud/data_source_genesyscloud_routing_skill_group.go b/genesyscloud/data_source_genesyscloud_routing_skill_group.go
deleted file mode 100644
index cb5b51cce..000000000
--- a/genesyscloud/data_source_genesyscloud_routing_skill_group.go
+++ /dev/null
@@ -1,101 +0,0 @@
-package genesyscloud
-
-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"
- "github.com/mypurecloud/platform-client-sdk-go/v133/platformclientv2"
-)
-
-func dataSourceRoutingSkillGroup() *schema.Resource {
- return &schema.Resource{
- Description: "Data source for Genesys Cloud Routing Skills Groups. Select a skill group by name.",
- ReadContext: provider.ReadWithPooledClient(dataSourceRoutingSkillGroupRead),
- Schema: map[string]*schema.Schema{
- "name": {
- Description: "Skill group name.",
- Type: schema.TypeString,
- Required: true,
- },
- },
- }
-}
-
-func dataSourceRoutingSkillGroupRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
- var (
- resp *platformclientv2.APIResponse
- err error
- )
-
- sdkConfig := m.(*provider.ProviderMeta).ClientConfig
- routingAPI := platformclientv2.NewRoutingApiWithConfig(sdkConfig)
- name := d.Get("name").(string)
-
- retryErr := util.WithRetries(ctx, 15*time.Second, func() *retry.RetryError {
- var skillGroups []platformclientv2.Skillgroupdefinition
- skillGroups, resp, err = getAllSkillGroupsByName(routingAPI, name)
- if err != nil {
- return retry.NonRetryableError(err)
- }
-
- for _, skillGroup := range skillGroups {
- if name == *skillGroup.Name {
- d.SetId(*skillGroup.Id)
- return nil
- }
- }
-
- return retry.RetryableError(fmt.Errorf("failed to find skill group with name '%s'", name))
- })
-
- if retryErr != nil {
- msg := fmt.Sprintf("failed to read skill group by name %s: %v", name, retryErr)
- if resp != nil {
- return util.BuildAPIDiagnosticError(getSkillGroupResourceName(), msg, resp)
- }
- return util.BuildDiagnosticError(getSkillGroupResourceName(), msg, fmt.Errorf("%v", retryErr))
- }
-
- return nil
-}
-
-func getAllSkillGroupsByName(api *platformclientv2.RoutingApi, name string) ([]platformclientv2.Skillgroupdefinition, *platformclientv2.APIResponse, error) {
- const pageSize = 100
- var (
- after string
- allSkillGroups []platformclientv2.Skillgroupdefinition
- )
-
- for {
- skillGroups, resp, err := api.GetRoutingSkillgroups(pageSize, name, after, "")
- if err != nil {
- return nil, resp, err
- }
-
- if skillGroups.Entities == nil || len(*skillGroups.Entities) == 0 {
- break
- }
-
- allSkillGroups = append(allSkillGroups, *skillGroups.Entities...)
-
- if skillGroups.NextUri == nil || *skillGroups.NextUri == "" {
- break
- }
-
- after, err = util.GetQueryParamValueFromUri(*skillGroups.NextUri, "after")
- if err != nil {
- return nil, nil, fmt.Errorf("error parsing NextUri '%s' while reading skill groups: %v", *skillGroups.NextUri, err)
- }
- if after == "" {
- break
- }
- }
-
- return allSkillGroups, nil, nil
-}
diff --git a/genesyscloud/outbound_ruleset/resource_genesyscloud_outbound_ruleset.go b/genesyscloud/outbound_ruleset/resource_genesyscloud_outbound_ruleset.go
index 932a5cda7..abab08551 100644
--- a/genesyscloud/outbound_ruleset/resource_genesyscloud_outbound_ruleset.go
+++ b/genesyscloud/outbound_ruleset/resource_genesyscloud_outbound_ruleset.go
@@ -13,7 +13,7 @@ import (
"terraform-provider-genesyscloud/genesyscloud/consistency_checker"
- gcloud "terraform-provider-genesyscloud/genesyscloud"
+ routingSkill "terraform-provider-genesyscloud/genesyscloud/routing_skill"
resourceExporter "terraform-provider-genesyscloud/genesyscloud/resource_exporter"
"terraform-provider-genesyscloud/genesyscloud/util/resourcedata"
@@ -38,7 +38,7 @@ func getAllAuthOutboundRuleset(ctx context.Context, clientConfig *platformclient
}
// DEVTOOLING-319: filters rule sets by removing the ones that reference skills that no longer exist in GC
- skillExporter := gcloud.RoutingSkillExporter()
+ skillExporter := routingSkill.RoutingSkillExporter()
skillMap, skillErr := skillExporter.GetResourcesFunc(ctx)
if skillErr != nil {
return nil, util.BuildDiagnosticError(resourceName, fmt.Sprintf("Failed to get skill resources"), fmt.Errorf("%v", skillErr))
diff --git a/genesyscloud/resource_genesyscloud_init.go b/genesyscloud/resource_genesyscloud_init.go
index 1f1db0c9b..ca549551f 100644
--- a/genesyscloud/resource_genesyscloud_init.go
+++ b/genesyscloud/resource_genesyscloud_init.go
@@ -29,8 +29,6 @@ func registerDataSources(l registrar.Registrar) {
l.RegisterDataSource("genesyscloud_organizations_me", DataSourceOrganizationsMe())
l.RegisterDataSource("genesyscloud_quality_forms_evaluation", DataSourceQualityFormsEvaluations())
l.RegisterDataSource("genesyscloud_quality_forms_survey", dataSourceQualityFormsSurvey())
- l.RegisterDataSource("genesyscloud_routing_skill", dataSourceRoutingSkill())
- l.RegisterDataSource("genesyscloud_routing_skill_group", dataSourceRoutingSkillGroup())
l.RegisterDataSource("genesyscloud_routing_wrapupcode", DataSourceRoutingWrapupcode())
l.RegisterDataSource("genesyscloud_user", DataSourceUser())
l.RegisterDataSource("genesyscloud_widget_deployment", dataSourceWidgetDeployments())
@@ -54,8 +52,6 @@ func registerResources(l registrar.Registrar) {
l.RegisterResource("genesyscloud_location", ResourceLocation())
l.RegisterResource("genesyscloud_quality_forms_evaluation", ResourceEvaluationForm())
l.RegisterResource("genesyscloud_quality_forms_survey", ResourceSurveyForm())
- l.RegisterResource("genesyscloud_routing_skill", ResourceRoutingSkill())
- l.RegisterResource("genesyscloud_routing_skill_group", ResourceRoutingSkillGroup())
l.RegisterResource("genesyscloud_routing_wrapupcode", ResourceRoutingWrapupCode())
l.RegisterResource("genesyscloud_user", ResourceUser())
l.RegisterResource("genesyscloud_widget_deployment", ResourceWidgetDeployment())
@@ -74,8 +70,6 @@ func registerExporters(l registrar.Registrar) {
l.RegisterExporter("genesyscloud_location", LocationExporter())
l.RegisterExporter("genesyscloud_quality_forms_evaluation", EvaluationFormExporter())
l.RegisterExporter("genesyscloud_quality_forms_survey", SurveyFormExporter())
- l.RegisterExporter("genesyscloud_routing_skill", RoutingSkillExporter())
- l.RegisterExporter("genesyscloud_routing_skill_group", ResourceSkillGroupExporter())
l.RegisterExporter("genesyscloud_routing_wrapupcode", RoutingWrapupCodeExporter())
l.RegisterExporter("genesyscloud_user", UserExporter())
l.RegisterExporter("genesyscloud_widget_deployment", WidgetDeploymentExporter())
diff --git a/genesyscloud/resource_genesyscloud_init_test.go b/genesyscloud/resource_genesyscloud_init_test.go
index 482f5e032..23c9a3aa1 100644
--- a/genesyscloud/resource_genesyscloud_init_test.go
+++ b/genesyscloud/resource_genesyscloud_init_test.go
@@ -15,7 +15,9 @@ import (
routingSettings "terraform-provider-genesyscloud/genesyscloud/routing_settings"
routingUtilization "terraform-provider-genesyscloud/genesyscloud/routing_utilization"
routingUtilizationLabel "terraform-provider-genesyscloud/genesyscloud/routing_utilization_label"
+ routingSkill "terraform-provider-genesyscloud/genesyscloud/routing_skill"
extensionPool "terraform-provider-genesyscloud/genesyscloud/telephony_providers_edges_extension_pool"
+ routingSkillGroup "terraform-provider-genesyscloud/genesyscloud/routing_skill_group"
"testing"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
@@ -59,8 +61,8 @@ func (r *registerTestInstance) registerTestResources() {
providerResources["genesyscloud_quality_forms_survey"] = ResourceSurveyForm()
providerResources["genesyscloud_routing_language"] = routinglanguage.ResourceRoutingLanguage()
providerResources["genesyscloud_routing_email_domain"] = routingEmailDomain.ResourceRoutingEmailDomain()
- providerResources["genesyscloud_routing_skill"] = ResourceRoutingSkill()
- providerResources["genesyscloud_routing_skill_group"] = ResourceRoutingSkillGroup()
+ providerResources["genesyscloud_routing_skill_group"] = routingSkillGroup.ResourceRoutingSkillGroup()
+ providerResources["genesyscloud_routing_skill"] = routingSkill.ResourceRoutingSkill()
providerResources["genesyscloud_routing_settings"] = routingSettings.ResourceRoutingSettings()
providerResources["genesyscloud_routing_utilization"] = routingUtilization.ResourceRoutingUtilization()
providerResources["genesyscloud_routing_wrapupcode"] = ResourceRoutingWrapupCode()
@@ -98,9 +100,9 @@ func (r *registerTestInstance) registerTestDataSources() {
providerDataSources["genesyscloud_quality_forms_evaluation"] = DataSourceQualityFormsEvaluations()
providerDataSources["genesyscloud_quality_forms_survey"] = dataSourceQualityFormsSurvey()
providerDataSources["genesyscloud_routing_language"] = routinglanguage.DataSourceRoutingLanguage()
- providerDataSources["genesyscloud_routing_skill"] = dataSourceRoutingSkill()
- providerDataSources["genesyscloud_routing_skill_group"] = dataSourceRoutingSkillGroup()
+ providerDataSources["genesyscloud_routing_skill"] = routingSkill.DataSourceRoutingSkill()
providerDataSources["genesyscloud_routing_email_domain"] = routingEmailDomain.DataSourceRoutingEmailDomain()
+ providerDataSources["genesyscloud_routing_skill_group"] = routingSkillGroup.DataSourceRoutingSkillGroup()
providerDataSources["genesyscloud_routing_wrapupcode"] = DataSourceRoutingWrapupcode()
providerDataSources["genesyscloud_user"] = DataSourceUser()
providerDataSources["genesyscloud_widget_deployment"] = dataSourceWidgetDeployments()
diff --git a/genesyscloud/resource_genesyscloud_journey_action_map.go b/genesyscloud/resource_genesyscloud_journey_action_map.go
index 6d74a105f..73e86aa60 100644
--- a/genesyscloud/resource_genesyscloud_journey_action_map.go
+++ b/genesyscloud/resource_genesyscloud_journey_action_map.go
@@ -147,9 +147,9 @@ var (
ValidateFunc: validation.StringInSlice([]string{"Web", "App" /*,"Custom", "Conversation" */}, false), // Custom and Conversation seem not to be supported by the API despite the documentation (DEVENGSD-607)
},
"session_type": {
- Description: "The session type for which this condition can be satisfied. Valid values: web, app.",
- Type: schema.TypeString,
- Required: true,
+ Description: "The session type for which this condition can be satisfied. Valid values: web, app.",
+ Type: schema.TypeString,
+ Required: true,
ValidateFunc: validation.StringInSlice([]string{"web", "app"}, false), // custom value seems not to be supported by the API despite the documentation
},
"event_name": {
diff --git a/genesyscloud/resource_genesyscloud_quality_forms_evaluation.go b/genesyscloud/resource_genesyscloud_quality_forms_evaluation.go
index 46d25aaf5..9a7230d49 100644
--- a/genesyscloud/resource_genesyscloud_quality_forms_evaluation.go
+++ b/genesyscloud/resource_genesyscloud_quality_forms_evaluation.go
@@ -16,7 +16,7 @@ import (
"terraform-provider-genesyscloud/genesyscloud/consistency_checker"
resourceExporter "terraform-provider-genesyscloud/genesyscloud/resource_exporter"
- lists "terraform-provider-genesyscloud/genesyscloud/util/lists"
+ "terraform-provider-genesyscloud/genesyscloud/util/lists"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
@@ -27,6 +27,11 @@ import (
var (
evaluationFormQuestionGroup = &schema.Resource{
Schema: map[string]*schema.Schema{
+ "id": {
+ Description: "ID of the question group.",
+ Type: schema.TypeString,
+ Computed: true,
+ },
"name": {
Description: "Name of display question in question group.",
Type: schema.TypeString,
@@ -80,6 +85,11 @@ var (
evaluationFormQuestion = &schema.Resource{
Schema: map[string]*schema.Schema{
+ "id": {
+ Description: "ID of the question.",
+ Type: schema.TypeString,
+ Computed: true,
+ },
"text": {
Description: "Individual question",
Type: schema.TypeString,
@@ -114,7 +124,7 @@ var (
Type: schema.TypeList,
Required: true,
MinItems: 2,
- Elem: evaluationFormAnswerOptions,
+ Elem: evaluationFormAnswerOptionsResource,
},
"is_kill": {
Description: "True if the question is a fatal question",
@@ -148,8 +158,13 @@ var (
},
}
- evaluationFormAnswerOptions = &schema.Resource{
+ evaluationFormAnswerOptionsResource = &schema.Resource{
Schema: map[string]*schema.Schema{
+ "id": {
+ Type: schema.TypeString,
+ Description: "The ID for the answer option.",
+ Computed: true,
+ },
"text": {
Type: schema.TypeString,
Required: true,
@@ -190,6 +205,11 @@ func EvaluationFormExporter() *resourceExporter.ResourceExporter {
GetResourcesFunc: provider.GetAllWithPooledClient(getAllEvaluationForms),
RefAttrs: map[string]*resourceExporter.RefAttrSettings{}, // No references
AllowZeroValues: []string{"question_groups.questions.answer_options.value", "question_groups.weight"},
+ ExcludedAttributes: []string{
+ "question_groups.id",
+ "question_groups.questions.id",
+ "question_groups.questions.answer_options.id",
+ },
}
}
@@ -211,7 +231,7 @@ func ResourceEvaluationForm() *schema.Resource {
Required: true,
},
"published": {
- Description: "Specifies if the evalutaion form is published.",
+ Description: "Specifies if the evaluation form is published.",
Type: schema.TypeBool,
Optional: true,
Default: false,
@@ -231,18 +251,13 @@ func createEvaluationForm(ctx context.Context, d *schema.ResourceData, meta inte
name := d.Get("name").(string)
published := d.Get("published").(bool)
- questionGroups, qgErr := buildSdkQuestionGroups(d)
- if qgErr != nil {
- return qgErr
- }
-
sdkConfig := meta.(*provider.ProviderMeta).ClientConfig
qualityAPI := platformclientv2.NewQualityApiWithConfig(sdkConfig)
log.Printf("Creating Evaluation Form %s", name)
form, resp, err := qualityAPI.PostQualityFormsEvaluations(platformclientv2.Evaluationform{
Name: &name,
- QuestionGroups: questionGroups,
+ QuestionGroups: buildSdkQuestionGroups(d),
})
if err != nil {
return util.BuildAPIDiagnosticError("genesyscloud_quality_forms_evaluation", fmt.Sprintf("Failed to create evaluation form %s error: %s", name, err), resp)
@@ -320,11 +335,6 @@ func updateEvaluationForm(ctx context.Context, d *schema.ResourceData, meta inte
name := d.Get("name").(string)
published := d.Get("published").(bool)
- questionGroups, qgErr := buildSdkQuestionGroups(d)
- if qgErr != nil {
- return qgErr
- }
-
sdkConfig := meta.(*provider.ProviderMeta).ClientConfig
qualityAPI := platformclientv2.NewQualityApiWithConfig(sdkConfig)
@@ -339,7 +349,7 @@ func updateEvaluationForm(ctx context.Context, d *schema.ResourceData, meta inte
log.Printf("Updating Evaluation Form %s", name)
form, resp, err := qualityAPI.PutQualityFormsEvaluation(*unpublishedForm.Id, platformclientv2.Evaluationform{
Name: &name,
- QuestionGroups: questionGroups,
+ QuestionGroups: buildSdkQuestionGroups(d),
})
if err != nil {
return util.BuildAPIDiagnosticError("genesyscloud_quality_forms_evaluation", fmt.Sprintf("Failed to update evaluation form %s error: %s", name, err), resp)
@@ -398,12 +408,11 @@ func deleteEvaluationForm(ctx context.Context, d *schema.ResourceData, meta inte
})
}
-func buildSdkQuestionGroups(d *schema.ResourceData) (*[]platformclientv2.Evaluationquestiongroup, diag.Diagnostics) {
+func buildSdkQuestionGroups(d *schema.ResourceData) *[]platformclientv2.Evaluationquestiongroup {
questionGroupType := "questionGroup"
var evalQuestionGroups []platformclientv2.Evaluationquestiongroup
- if questionGroups, ok := d.GetOk("question_groups"); ok {
- questionGroupList := questionGroups.([]interface{})
+ if questionGroupList, ok := d.Get("question_groups").([]interface{}); ok {
for _, questionGroup := range questionGroupList {
questionGroupsMap := questionGroup.(map[string]interface{})
@@ -433,7 +442,7 @@ func buildSdkQuestionGroups(d *schema.ResourceData) (*[]platformclientv2.Evaluat
}
}
- return &evalQuestionGroups, nil
+ return &evalQuestionGroups
}
func buildSdkQuestions(questions []interface{}) *[]platformclientv2.Evaluationquestion {
@@ -442,6 +451,7 @@ func buildSdkQuestions(questions []interface{}) *[]platformclientv2.Evaluationqu
sdkQuestions := make([]platformclientv2.Evaluationquestion, 0)
for _, question := range questions {
questionsMap := question.(map[string]interface{})
+
text := questionsMap["text"].(string)
helpText := questionsMap["help_text"].(string)
naEnabled := questionsMap["na_enabled"].(bool)
@@ -456,9 +466,9 @@ func buildSdkQuestions(questions []interface{}) *[]platformclientv2.Evaluationqu
VarType: &questionType,
NaEnabled: &naEnabled,
CommentsRequired: &commentsRequired,
- AnswerOptions: buildSdkAnswerOptions(answerQuestions),
IsKill: &isKill,
IsCritical: &isCritical,
+ AnswerOptions: buildSdkAnswerOptions(answerQuestions),
}
visibilityCondition := questionsMap["visibility_condition"].([]interface{})
@@ -494,7 +504,10 @@ func buildSdkVisibilityCondition(visibilityCondition []interface{}) *platformcli
return nil
}
- visibilityConditionMap := visibilityCondition[0].(map[string]interface{})
+ visibilityConditionMap, ok := visibilityCondition[0].(map[string]interface{})
+ if !ok {
+ return nil
+ }
combiningOperation := visibilityConditionMap["combining_operation"].(string)
predicates := visibilityConditionMap["predicates"].([]interface{})
@@ -510,10 +523,13 @@ func flattenQuestionGroups(questionGroups *[]platformclientv2.Evaluationquestion
return nil
}
- questionGroupList := []interface{}{}
+ var questionGroupList []interface{}
for _, questionGroup := range *questionGroups {
questionGroupMap := make(map[string]interface{})
+ if questionGroup.Id != nil {
+ questionGroupMap["id"] = *questionGroup.Id
+ }
if questionGroup.Name != nil {
questionGroupMap["name"] = *questionGroup.Name
}
@@ -549,10 +565,13 @@ func flattenQuestions(questions *[]platformclientv2.Evaluationquestion) []interf
return nil
}
- questionList := []interface{}{}
+ var questionList []interface{}
for _, question := range *questions {
questionMap := make(map[string]interface{})
+ if question.Id != nil {
+ questionMap["id"] = *question.Id
+ }
if question.Text != nil {
questionMap["text"] = *question.Text
}
@@ -588,17 +607,19 @@ func flattenAnswerOptions(answerOptions *[]platformclientv2.Answeroption) []inte
return nil
}
- answerOptionsList := []interface{}{}
+ var answerOptionsList []interface{}
for _, answerOption := range *answerOptions {
answerOptionMap := make(map[string]interface{})
+ if answerOption.Id != nil {
+ answerOptionMap["id"] = *answerOption.Id
+ }
if answerOption.Text != nil {
answerOptionMap["text"] = *answerOption.Text
}
if answerOption.Value != nil {
answerOptionMap["value"] = *answerOption.Value
}
-
answerOptionsList = append(answerOptionsList, answerOptionMap)
}
return answerOptionsList
@@ -678,12 +699,12 @@ func GenerateEvaluationFormQuestions(questions *[]EvaluationFormQuestionStruct)
for _, question := range *questions {
questionString := fmt.Sprintf(`
questions {
- text = "%s"
- help_text = "%s"
- na_enabled = %v
+ text = "%s"
+ help_text = "%s"
+ na_enabled = %v
comments_required = %v
- is_kill = %v
- is_critical = %v
+ is_kill = %v
+ is_critical = %v
%s
%s
}
@@ -713,7 +734,7 @@ func GenerateFormAnswerOptions(answerOptions *[]AnswerOptionStruct) string {
for _, answerOption := range *answerOptions {
answerOptionString := fmt.Sprintf(`
answer_options {
- text = "%s"
+ text = "%s"
value = %v
}
`, answerOption.Text,
diff --git a/genesyscloud/resource_genesyscloud_quality_forms_evaluation_test.go b/genesyscloud/resource_genesyscloud_quality_forms_evaluation_test.go
index bec7ffa7e..3c28fc71d 100644
--- a/genesyscloud/resource_genesyscloud_quality_forms_evaluation_test.go
+++ b/genesyscloud/resource_genesyscloud_quality_forms_evaluation_test.go
@@ -15,6 +15,8 @@ import (
func TestAccResourceEvaluationFormBasic(t *testing.T) {
formResource1 := "test-evaluation-form-1"
+ answer1Text := "Yes"
+ answer1Value := 1
// Most basic evaluation form
evaluationForm1 := EvaluationFormStruct{
@@ -28,12 +30,12 @@ func TestAccResourceEvaluationFormBasic(t *testing.T) {
Text: "Did the agent perform the opening spiel?",
AnswerOptions: []AnswerOptionStruct{
{
- Text: "Yes",
- Value: 1,
+ Text: answer1Text,
+ Value: answer1Value,
},
{
Text: "No",
- Value: 0,
+ Value: 2,
},
},
},
diff --git a/genesyscloud/resource_genesyscloud_quality_forms_survey.go b/genesyscloud/resource_genesyscloud_quality_forms_survey.go
index 9684600e1..b8104360a 100644
--- a/genesyscloud/resource_genesyscloud_quality_forms_survey.go
+++ b/genesyscloud/resource_genesyscloud_quality_forms_survey.go
@@ -53,6 +53,11 @@ type SurveyFormQuestionStruct struct {
var (
surveyQuestionGroup = &schema.Resource{
Schema: map[string]*schema.Schema{
+ "id": {
+ Description: "The ID of the survey question group.",
+ Type: schema.TypeString,
+ Computed: true,
+ },
"name": {
Description: "Name of display question in question group.",
Type: schema.TypeString,
@@ -83,6 +88,11 @@ var (
surveyQuestion = &schema.Resource{
Schema: map[string]*schema.Schema{
+ "id": {
+ Description: "The ID of the survey question.",
+ Type: schema.TypeString,
+ Computed: true,
+ },
"text": {
Description: "Individual question",
Type: schema.TypeString,
@@ -151,6 +161,11 @@ var (
surveyFormAnswerOptions = &schema.Resource{
Schema: map[string]*schema.Schema{
+ "id": {
+ Type: schema.TypeString,
+ Description: "The ID of the survey answer option.",
+ Computed: true,
+ },
"text": {
Type: schema.TypeString,
Required: true,
@@ -161,19 +176,20 @@ var (
},
"assistance_conditions": {
Description: "Options from which to choose an answer for this question.",
- Type: schema.TypeList,
+ Type: schema.TypeSet,
Optional: true,
- Elem: assistanceConditions,
+ Elem: assistanceConditionsResource,
},
},
}
- assistanceConditions = &schema.Resource{
+ assistanceConditionsResource = &schema.Resource{
Schema: map[string]*schema.Schema{
"operator": {
- Description: "List of assistance conditions which are combined together with a logical AND operator. Eg ( assistanceCondtion1 && assistanceCondition2 ) wherein assistanceCondition could be ( EXISTS topic1 || topic2 || ... ) or (NOTEXISTS topic3 || topic4 || ...).",
- Type: schema.TypeString,
- Optional: true,
+ Description: "List of assistance conditions which are combined together with a logical AND operator. Eg ( assistanceCondtion1 && assistanceCondition2 ) wherein assistanceCondition could be ( EXISTS topic1 || topic2 || ... ) or (NOTEXISTS topic3 || topic4 || ...).",
+ Type: schema.TypeString,
+ Required: true,
+ ValidateFunc: validation.StringInSlice([]string{"EXISTS", "NOTEXISTS"}, true),
},
"topic_ids": {
Description: "List of topicIds within the assistance condition which would be combined together using logical OR operator. Eg ( topicId_1 || topicId_2 ) .",
@@ -213,6 +229,11 @@ func SurveyFormExporter() *resourceExporter.ResourceExporter {
GetResourcesFunc: provider.GetAllWithPooledClient(getAllSurveyForms),
RefAttrs: map[string]*resourceExporter.RefAttrSettings{}, // No references
AllowZeroValues: []string{"question_groups.questions.answer_options.value"},
+ ExcludedAttributes: []string{
+ "question_groups.id",
+ "question_groups.questions.id",
+ "question_groups.questions.answer_options.id",
+ },
}
}
@@ -511,13 +532,14 @@ func buildSurveyQuestions(questions []interface{}) *[]platformclientv2.Surveyque
naEnabled := questionsMap["na_enabled"].(bool)
answerQuestions := questionsMap["answer_options"].([]interface{})
maxResponseCharacters := questionsMap["max_response_characters"].(int)
+ sdkAnswerOptions := buildSdkAnswerOptions(answerQuestions)
sdkQuestion := platformclientv2.Surveyquestion{
Text: &text,
HelpText: &helpText,
VarType: &questionType,
NaEnabled: &naEnabled,
- AnswerOptions: buildSdkAnswerOptions(answerQuestions),
+ AnswerOptions: sdkAnswerOptions,
MaxResponseCharacters: &maxResponseCharacters,
}
@@ -540,10 +562,13 @@ func flattenSurveyQuestionGroups(questionGroups *[]platformclientv2.Surveyquesti
return nil
}
- questionGroupList := []interface{}{}
+ var questionGroupList []interface{}
for _, questionGroup := range *questionGroups {
questionGroupMap := make(map[string]interface{})
+ if questionGroup.Id != nil {
+ questionGroupMap["id"] = *questionGroup.Id
+ }
if questionGroup.Name != nil {
questionGroupMap["name"] = *questionGroup.Name
}
@@ -567,10 +592,13 @@ func flattenSurveyQuestions(questions *[]platformclientv2.Surveyquestion) []inte
return nil
}
- questionList := []interface{}{}
+ var questionList []interface{}
for _, question := range *questions {
questionMap := make(map[string]interface{})
+ if question.Id != nil {
+ questionMap["id"] = *question.Id
+ }
if question.Text != nil {
questionMap["text"] = *question.Text
}
diff --git a/genesyscloud/resource_genesyscloud_routing_skill.go b/genesyscloud/resource_genesyscloud_routing_skill.go
deleted file mode 100644
index 33093ab37..000000000
--- a/genesyscloud/resource_genesyscloud_routing_skill.go
+++ /dev/null
@@ -1,163 +0,0 @@
-package genesyscloud
-
-import (
- "context"
- "fmt"
- "log"
- "terraform-provider-genesyscloud/genesyscloud/provider"
- "terraform-provider-genesyscloud/genesyscloud/util"
- "terraform-provider-genesyscloud/genesyscloud/util/constants"
- "time"
-
- "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
-
- "terraform-provider-genesyscloud/genesyscloud/consistency_checker"
-
- resourceExporter "terraform-provider-genesyscloud/genesyscloud/resource_exporter"
-
- "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"
-)
-
-func getAllRoutingSkills(_ context.Context, clientConfig *platformclientv2.Configuration) (resourceExporter.ResourceIDMetaMap, diag.Diagnostics) {
- resources := make(resourceExporter.ResourceIDMetaMap)
- routingAPI := platformclientv2.NewRoutingApiWithConfig(clientConfig)
-
- for pageNum := 1; ; pageNum++ {
- const pageSize = 100
- skills, resp, getErr := routingAPI.GetRoutingSkills(pageSize, pageNum, "", nil)
- if getErr != nil {
- return nil, util.BuildAPIDiagnosticError("genesyscloud_routing_skill", fmt.Sprintf("Failed to get skills error: %s", getErr), resp)
- }
-
- if skills.Entities == nil || len(*skills.Entities) == 0 {
- break
- }
-
- for _, skill := range *skills.Entities {
- if skill.State != nil && *skill.State != "deleted" {
- resources[*skill.Id] = &resourceExporter.ResourceMeta{Name: *skill.Name}
- }
- }
- }
-
- return resources, nil
-}
-
-func RoutingSkillExporter() *resourceExporter.ResourceExporter {
- return &resourceExporter.ResourceExporter{
- GetResourcesFunc: provider.GetAllWithPooledClient(getAllRoutingSkills),
- RefAttrs: map[string]*resourceExporter.RefAttrSettings{}, // No references
- }
-}
-
-func ResourceRoutingSkill() *schema.Resource {
- return &schema.Resource{
- Description: "Genesys Cloud Routing Skill",
-
- CreateContext: provider.CreateWithPooledClient(createRoutingSkill),
- ReadContext: provider.ReadWithPooledClient(readRoutingSkill),
- DeleteContext: provider.DeleteWithPooledClient(deleteRoutingSkill),
- Importer: &schema.ResourceImporter{
- StateContext: schema.ImportStatePassthroughContext,
- },
- SchemaVersion: 1,
- Schema: map[string]*schema.Schema{
- "name": {
- Description: "Skill name. Changing the name attribute will cause the skill object object to dropped and recreated with a new ID.",
- Type: schema.TypeString,
- Required: true,
- ForceNew: true,
- },
- },
- }
-}
-
-func createRoutingSkill(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
- name := d.Get("name").(string)
-
- sdkConfig := meta.(*provider.ProviderMeta).ClientConfig
- routingAPI := platformclientv2.NewRoutingApiWithConfig(sdkConfig)
-
- log.Printf("Creating skill %s", name)
- skill, resp, err := routingAPI.PostRoutingSkills(platformclientv2.Routingskill{
- Name: &name,
- })
- if err != nil {
- return util.BuildAPIDiagnosticError("genesyscloud_routing_skill", fmt.Sprintf("Failed to create skill %s error: %s", name, err), resp)
- }
-
- d.SetId(*skill.Id)
-
- log.Printf("Created skill %s %s", name, *skill.Id)
- return readRoutingSkill(ctx, d, meta)
-}
-
-func readRoutingSkill(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
- sdkConfig := meta.(*provider.ProviderMeta).ClientConfig
- routingAPI := platformclientv2.NewRoutingApiWithConfig(sdkConfig)
- cc := consistency_checker.NewConsistencyCheck(ctx, d, meta, ResourceRoutingSkill(), constants.DefaultConsistencyChecks, "genesyscloud_routing_skill")
-
- log.Printf("Reading skill %s", d.Id())
- return util.WithRetriesForRead(ctx, d, func() *retry.RetryError {
- skill, resp, getErr := routingAPI.GetRoutingSkill(d.Id())
- if getErr != nil {
- if util.IsStatus404(resp) {
- return retry.RetryableError(util.BuildWithRetriesApiDiagnosticError("genesyscloud_routing_skill", fmt.Sprintf("Failed to read skill %s | error: %s", d.Id(), getErr), resp))
- }
- return retry.NonRetryableError(util.BuildWithRetriesApiDiagnosticError("genesyscloud_routing_skill", fmt.Sprintf("Failed to read skill %s | error: %s", d.Id(), getErr), resp))
- }
-
- if skill.State != nil && *skill.State == "deleted" {
- d.SetId("")
- return nil
- }
-
- d.Set("name", *skill.Name)
- log.Printf("Read skill %s %s", d.Id(), *skill.Name)
- return cc.CheckState(d)
- })
-}
-
-func deleteRoutingSkill(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
- name := d.Get("name").(string)
-
- sdkConfig := meta.(*provider.ProviderMeta).ClientConfig
- routingAPI := platformclientv2.NewRoutingApiWithConfig(sdkConfig)
-
- log.Printf("Deleting skill %s", name)
- resp, err := routingAPI.DeleteRoutingSkill(d.Id())
- if err != nil {
- return util.BuildAPIDiagnosticError("genesyscloud_routing_skill", fmt.Sprintf("Failed to delete skill %s error: %s", name, err), resp)
- }
-
- return util.WithRetries(ctx, 30*time.Second, func() *retry.RetryError {
- routingSkill, resp, err := routingAPI.GetRoutingSkill(d.Id())
- if err != nil {
- if util.IsStatus404(resp) {
- // Routing skill deleted
- log.Printf("Deleted Routing skill %s", d.Id())
- return nil
- }
- return retry.NonRetryableError(util.BuildWithRetriesApiDiagnosticError("genesyscloud_routing_skill", fmt.Sprintf("Error deleting Routing skill %s | error: %s", d.Id(), err), resp))
- }
-
- if routingSkill.State != nil && *routingSkill.State == "deleted" {
- // Routing skill deleted
- log.Printf("Deleted Routing skill %s", d.Id())
- return nil
- }
-
- return retry.RetryableError(util.BuildWithRetriesApiDiagnosticError("genesyscloud_routing_skill", fmt.Sprintf("Routing skill %s still exists", d.Id()), resp))
- })
-}
-
-func GenerateRoutingSkillResource(
- resourceID string,
- name string) string {
- return fmt.Sprintf(`resource "genesyscloud_routing_skill" "%s" {
- name = "%s"
- }
- `, resourceID, name)
-}
diff --git a/genesyscloud/resource_genesyscloud_routing_skill_group.go b/genesyscloud/resource_genesyscloud_routing_skill_group.go
deleted file mode 100644
index 5e47d30c1..000000000
--- a/genesyscloud/resource_genesyscloud_routing_skill_group.go
+++ /dev/null
@@ -1,569 +0,0 @@
-package genesyscloud
-
-import (
- "context"
- "encoding/json"
- "fmt"
- "log"
- "net/http"
- "strings"
- "terraform-provider-genesyscloud/genesyscloud/provider"
- "terraform-provider-genesyscloud/genesyscloud/util"
- "terraform-provider-genesyscloud/genesyscloud/util/constants"
- "time"
-
- "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
-
- "terraform-provider-genesyscloud/genesyscloud/consistency_checker"
-
- resourceExporter "terraform-provider-genesyscloud/genesyscloud/resource_exporter"
- lists "terraform-provider-genesyscloud/genesyscloud/util/lists"
-
- "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"
-)
-
-type SkillGroupsRequest struct {
- Name string `json:"name"`
- Description string `json:"description"`
- Division struct {
- ID string `json:"id,omitempty"`
- Name string `json:"name,omitempty"`
- } `json:"division,omitempty"`
- SkillConditions struct{} `json:"skillConditions"` //Keep this here. Even though we do not use this field in the struct The generated attributed is used as a placeholder
-}
-
-func getAllSkillGroups(_ context.Context, clientConfig *platformclientv2.Configuration) (resourceExporter.ResourceIDMetaMap, diag.Diagnostics) {
- resources := make(resourceExporter.ResourceIDMetaMap)
- routingAPI := platformclientv2.NewRoutingApiWithConfig(clientConfig)
-
- allSkillGroups, resp, err := getAllSkillGroupsByName(routingAPI, "")
- if err != nil {
- msg := fmt.Sprintf("failed to read skill groups: %v", err)
- return nil, util.BuildAPIDiagnosticError(getSkillGroupResourceName(), msg, resp)
- }
-
- for _, skillGroup := range allSkillGroups {
- resources[*skillGroup.Id] = &resourceExporter.ResourceMeta{Name: *skillGroup.Name}
- }
-
- return resources, nil
-}
-
-func ResourceSkillGroupExporter() *resourceExporter.ResourceExporter {
- return &resourceExporter.ResourceExporter{
- GetResourcesFunc: provider.GetAllWithPooledClient(getAllSkillGroups),
- RefAttrs: map[string]*resourceExporter.RefAttrSettings{
- "division_id": {RefType: "genesyscloud_auth_division"},
- "member_division_ids": {RefType: "genesyscloud_auth_division"},
- },
- RemoveIfMissing: map[string][]string{
- "division_id": {"division_id"},
- },
- JsonEncodeAttributes: []string{"skill_conditions"},
- }
-}
-
-func getSkillGroupResourceName() string {
- return "genesyscloud_routing_skill_group"
-}
-
-func ResourceRoutingSkillGroup() *schema.Resource {
- return &schema.Resource{
- Description: `Genesys Cloud Skill Group`,
-
- CreateContext: provider.CreateWithPooledClient(createSkillGroups),
- ReadContext: provider.ReadWithPooledClient(readSkillGroups),
- UpdateContext: provider.UpdateWithPooledClient(updateSkillGroups),
- DeleteContext: provider.DeleteWithPooledClient(deleteSkillGroups),
- Importer: &schema.ResourceImporter{
- StateContext: schema.ImportStatePassthroughContext,
- },
- SchemaVersion: 1,
- Schema: map[string]*schema.Schema{
- "name": {
- Description: "The group name",
- Type: schema.TypeString,
- Required: true,
- },
- "description": {
- Description: "Description of the skill group",
- Type: schema.TypeString,
- Optional: true,
- Computed: true,
- },
- "division_id": {
- Description: "The division to which this entity belongs",
- Type: schema.TypeString,
- Optional: true,
- Computed: true,
- },
- "skill_conditions": {
- Description: "JSON encoded array of rules that will be used to determine group membership.",
- Type: schema.TypeString,
- Optional: true,
- Computed: true,
- DiffSuppressFunc: util.SuppressEquivalentJsonDiffs,
- },
- "member_division_ids": {
- Description: "The IDs of member divisions to add or remove for this skill group. An empty array means all divisions will be removed, \"*\" means all divisions will be added.",
- Type: schema.TypeList,
- MaxItems: 50,
- Optional: true,
- Elem: &schema.Schema{Type: schema.TypeString},
- },
- },
- }
-}
-
-func createSkillGroups(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
- return createOrUpdateSkillGroups(ctx, d, meta, "/api/v2/routing/skillgroups", true)
-}
-
-func createOrUpdateSkillGroups(ctx context.Context, d *schema.ResourceData, meta interface{}, route string, create bool) diag.Diagnostics {
- if create == true {
- log.Printf("Creating a skill group using")
- } else {
- log.Printf("Updating a skill group using")
- }
- // TODO: After public API endpoint is published and exposed to public, change to SDK method instead of direct invocation
- skillGroupsRequest := &SkillGroupsRequest{
- Name: d.Get("name").(string),
- Description: d.Get("description").(string),
- }
-
- //Get the division information
- divisionId := d.Get("division_id").(string)
- if divisionId != "" {
- skillGroupsRequest.Division.ID = divisionId
- }
-
- //Merge in skill conditions
- finalSkillGroupsJson, err := mergeSkillConditionsIntoSkillGroups(d, skillGroupsRequest)
- if err != nil {
- return util.BuildDiagnosticError(getSkillGroupResourceName(), fmt.Sprintf("Failed to read the before skills groups request before: %s", skillGroupsRequest.Name), err)
- }
-
- sdkConfig := meta.(*provider.ProviderMeta).ClientConfig
- routingAPI := platformclientv2.NewRoutingApiWithConfig(sdkConfig)
- apiClient := &routingAPI.Configuration.APIClient
- path := routingAPI.Configuration.BasePath + route
- headerParams := BuildHeaderParams(routingAPI)
-
- /*
- Since API Client expects either a struct or map of maps (of json), convert the JSON string to a map
- and then pass it into API client
- */
- var skillGroupsPayload map[string]interface{}
- err = json.Unmarshal([]byte(finalSkillGroupsJson), &skillGroupsPayload)
- if err != nil {
- return util.BuildDiagnosticError(getSkillGroupResourceName(), fmt.Sprintf("Failed to unmarshal the JSON payload while creating/updating the skills group %s", skillGroupsRequest.Name), err)
- }
-
- httpMethod := "POST"
- if create == false {
- httpMethod = "PATCH"
- }
-
- response, err := apiClient.CallAPI(path, httpMethod, skillGroupsPayload, headerParams, nil, nil, "", nil)
- if err != nil {
- return util.BuildAPIDiagnosticError(getSkillGroupResourceName(), fmt.Sprintf("Failed to create/update skill groups %s error: %s", skillGroupsRequest.Name, err), response)
- }
-
- //Get the results and pull out the id
- skillGroupPayload := make(map[string]interface{})
- err = json.Unmarshal(response.RawBody, &skillGroupPayload)
- if err != nil {
- return util.BuildDiagnosticError(getSkillGroupResourceName(), fmt.Sprintf("Failed to unmarshal skill groups"), err)
- }
-
- if create == true {
- id := skillGroupPayload["id"].(string)
- d.SetId(id)
- log.Printf("Created skill group %s %s", skillGroupsRequest.Name, id)
- } else {
- log.Printf("Updated skill group %s", skillGroupsRequest.Name)
- }
-
- // Update member division IDs
- apiSkillGroupMemberDivisionIds, diagErr := readSkillGroupMemberDivisionIds(d, routingAPI)
- if diagErr != nil {
- return diagErr
- }
-
- diagErr = postSkillGroupMemberDivisions(ctx, d, meta, routingAPI, apiSkillGroupMemberDivisionIds, create)
- if diagErr != nil {
- return diagErr
- }
-
- return readSkillGroups(ctx, d, meta)
-}
-
-func postSkillGroupMemberDivisions(ctx context.Context, d *schema.ResourceData, meta interface{}, routingAPI *platformclientv2.RoutingApi, apiSkillGroupMemberDivisionIds []string, create bool) diag.Diagnostics {
- name := d.Get("name").(string)
- memberDivisionIds := d.Get("member_division_ids").([]interface{})
-
- if memberDivisionIds == nil {
- return readSkillGroups(ctx, d, meta)
- }
- schemaDivisionIds := lists.InterfaceListToStrings(memberDivisionIds)
-
- toAdd, toRemove, diagErr := createListsForSkillgroupsMembersDivisionsPost(schemaDivisionIds, apiSkillGroupMemberDivisionIds, create, meta)
- if diagErr != nil {
- return diagErr
- }
-
- toRemove, diagErr = removeSkillGroupDivisionID(d, toRemove)
- if diagErr != nil {
- return diagErr
- }
-
- if len(toAdd) < 1 && len(toRemove) < 1 {
- return readSkillGroups(ctx, d, meta)
- }
-
- log.Printf("Updating skill group %s member divisions", name)
-
- skillGroupsMemberDivisionIdsPayload := make(map[string][]string, 0)
- if len(toRemove) > 0 {
- skillGroupsMemberDivisionIdsPayload["removeDivisionIds"] = toRemove
- }
- if len(toAdd) > 0 {
- skillGroupsMemberDivisionIdsPayload["addDivisionIds"] = toAdd
- }
-
- headerParams := BuildHeaderParams(routingAPI)
- apiClient := &routingAPI.Configuration.APIClient
- path := fmt.Sprintf("%s/api/v2/routing/skillgroups/%s/members/divisions", routingAPI.Configuration.BasePath, d.Id())
- response, err := apiClient.CallAPI(path, "POST", skillGroupsMemberDivisionIdsPayload, headerParams, nil, nil, "", nil)
- if err != nil || response.Error != nil {
- return util.BuildAPIDiagnosticError(getSkillGroupResourceName(), fmt.Sprintf("Failed to create/update skill group %s member divisions error: %s", d.Id(), err), response)
- }
-
- log.Printf("Updated skill group %s member divisions", name)
- return nil
-}
-
-func getAllAuthDivisionIds(meta interface{}) ([]string, diag.Diagnostics) {
- sdkConfig := meta.(*provider.ProviderMeta).ClientConfig
- allIds := make([]string, 0)
-
- divisionResourcesMap, err := getAllAuthDivisions(nil, sdkConfig)
- if err != nil {
- return nil, err
- }
-
- for key, _ := range divisionResourcesMap {
- allIds = append(allIds, key)
- }
-
- return allIds, nil
-}
-
-func createListsForSkillgroupsMembersDivisionsPost(schemaMemberDivisionIds []string, apiMemberDivisionIds []string,
- create bool, meta interface{}) ([]string, []string, diag.Diagnostics) {
- toAdd := make([]string, 0)
- toRemove := make([]string, 0)
-
- if allMemberDivisionsSpecified(schemaMemberDivisionIds) {
- if len(schemaMemberDivisionIds) > 1 {
- return nil, nil, util.BuildDiagnosticError(getSkillGroupResourceName(), fmt.Sprintf(`member_division_ids should not contain more than one item when the value of an item is "*"`), fmt.Errorf(`member_division_ids should not contain more than one item when the value of an item is "*"`))
- }
- toAdd, err := getAllAuthDivisionIds(meta)
- return toAdd, nil, err
- }
-
- if len(schemaMemberDivisionIds) > 0 {
- if create == true {
- return schemaMemberDivisionIds, nil, nil
- }
- toAdd, toRemove = organizeMemberDivisionIdsForUpdate(schemaMemberDivisionIds, apiMemberDivisionIds)
- return toAdd, toRemove, nil
- }
-
- // Empty array - remove all
- for _, id := range apiMemberDivisionIds {
- toRemove = append(toRemove, id)
- }
- return nil, toRemove, nil
-}
-
-/*
-Sometimes you just need to get ugly. skillConditions has a recursive function that is super ugly to manage to a static Golang
-Struct. So our struct always has a placeholder "skillConditions": {} field. So what I do is convert the struct to JSON and then
-check to see if skill_conditions on the Terraform resource data. I then do a string replace on the skillConditions json attribute
-and replace the empty stringConditions string with the contents of skill_conditions.
-
-Not the most eloquent code, but these are uncivilized times.
-*/
-func mergeSkillConditionsIntoSkillGroups(d *schema.ResourceData, skillGroupsRequest *SkillGroupsRequest) (string, error) {
- skillsConditionsJsonString := fmt.Sprintf(`"skillConditions": %s`, d.Get("skill_conditions").(string))
-
- //Get the before image of the JSON. Note this a byte array
- skillGroupsRequestBefore, err := json.Marshal(skillGroupsRequest)
- if err != nil {
- return "", err
- }
-
- skillGroupsRequestAfter := ""
-
- //Skill conditions are present, replace skill conditions with the content of the string
- if d.Get("skill_conditions").(string) != "" {
- skillGroupsRequestAfter = strings.Replace(string(skillGroupsRequestBefore), `"skillConditions":{}`, skillsConditionsJsonString, 1)
- } else {
- //Skill conditions are not present, get rid of skill conditions.
- skillGroupsRequestAfter = strings.Replace(string(skillGroupsRequestBefore), `,"skillConditions":{}`, "", 1)
- }
-
- return skillGroupsRequestAfter, nil
-}
-
-func readSkillGroups(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
- sdkConfig := meta.(*provider.ProviderMeta).ClientConfig
- routingAPI := platformclientv2.NewRoutingApiWithConfig(sdkConfig)
- cc := consistency_checker.NewConsistencyCheck(ctx, d, meta, ResourceRoutingSkillGroup(), constants.DefaultConsistencyChecks, "genesyscloud_skill_group")
-
- // TODO: After public API endpoint is published and exposed to public, change to SDK method instead of direct invocation
- apiClient := &routingAPI.Configuration.APIClient
- path := routingAPI.Configuration.BasePath + "/api/v2/routing/skillgroups/" + d.Id()
-
- // add default headers if any
- headerParams := BuildHeaderParams(routingAPI)
-
- log.Printf("Reading skills group %s", d.Id())
-
- return util.WithRetriesForRead(ctx, d, func() *retry.RetryError {
-
- skillGroupPayload := make(map[string]interface{})
- response, err := apiClient.CallAPI(path, "GET", nil, headerParams, nil, nil, "", nil)
-
- if err != nil {
- return retry.NonRetryableError(util.BuildWithRetriesApiDiagnosticError(getSkillGroupResourceName(), fmt.Sprintf("Failed to retrieve skill groups %s", err), response))
- }
-
- if err == nil && response.Error != nil && response.StatusCode != http.StatusNotFound {
- return retry.NonRetryableError(util.BuildWithRetriesApiDiagnosticError(getSkillGroupResourceName(), fmt.Sprintf("Failed to retrieve skill groups. %s", err), response))
- }
-
- err = json.Unmarshal(response.RawBody, &skillGroupPayload)
- if err != nil {
- return retry.NonRetryableError(fmt.Errorf("Failed to unmarshal skill groups. %s", err))
- }
-
- if err == nil && util.IsStatus404(response) {
- return retry.RetryableError(util.BuildWithRetriesApiDiagnosticError(getSkillGroupResourceName(), fmt.Sprintf("Failed to read skill groups %s | error: %s", d.Id(), err), response))
- }
-
- name := skillGroupPayload["name"]
- divisionId := skillGroupPayload["division"].(map[string]interface{})["id"]
- description := skillGroupPayload["description"]
- skillConditionsBytes, err := json.Marshal(skillGroupPayload["skillConditions"])
-
- if err != nil {
- return retry.NonRetryableError(fmt.Errorf("Failed to unmarshal skill groups conditions. %s", err))
- }
-
- skillConditions := string(skillConditionsBytes)
-
- if name != "" {
- d.Set("name", name)
- } else {
- d.Set("name", nil)
- }
-
- if divisionId != nil && divisionId != "" {
- d.Set("division_id", divisionId)
- } else {
- d.Set("division_id", nil)
- }
-
- if description != "" {
- d.Set("description", description)
- } else {
- d.Set("description", nil)
- }
-
- if skillConditions != "" {
- d.Set("skill_conditions", skillConditions)
- } else {
- d.Set("skill_conditions", nil)
- }
-
- apiMemberDivisionIds, diagErr := readSkillGroupMemberDivisionIds(d, routingAPI)
- if diagErr != nil {
- return retry.NonRetryableError(fmt.Errorf("%v", diagErr))
- }
-
- var schemaMemberDivisionIds []string
- if divIds, ok := d.Get("member_division_ids").([]interface{}); ok {
- schemaMemberDivisionIds = lists.InterfaceListToStrings(divIds)
- }
-
- memberDivisionIds := organizeMemberDivisionIdsForRead(schemaMemberDivisionIds, apiMemberDivisionIds, divisionId.(string))
- _ = d.Set("member_division_ids", memberDivisionIds)
-
- log.Printf("Read skill groups name %s %s", d.Id(), name)
- return cc.CheckState(d)
- })
-}
-
-func BuildHeaderParams(routingAPI *platformclientv2.RoutingApi) map[string]string {
- headerParams := make(map[string]string)
-
- for key := range routingAPI.Configuration.DefaultHeader {
- headerParams[key] = routingAPI.Configuration.DefaultHeader[key]
- }
-
- headerParams["Authorization"] = "Bearer " + routingAPI.Configuration.AccessToken
- headerParams["Content-Type"] = "application/json"
- headerParams["Accept"] = "application/json"
-
- return headerParams
-}
-
-func updateSkillGroups(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
- route := "/api/v2/routing/skillgroups/" + d.Id()
- return createOrUpdateSkillGroups(ctx, d, meta, route, false)
-}
-
-func deleteSkillGroups(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
- name := d.Get("name").(string)
-
- sdkConfig := meta.(*provider.ProviderMeta).ClientConfig
- routingAPI := platformclientv2.NewRoutingApiWithConfig(sdkConfig)
-
- // TODO: After public API endpoint is published and exposed to public, change to SDK method instead of direct invocation
- apiClient := &routingAPI.Configuration.APIClient
- path := routingAPI.Configuration.BasePath + "/api/v2/routing/skillgroups/" + d.Id()
-
- // add default headers if any
- headerParams := BuildHeaderParams(routingAPI)
-
- log.Printf("Deleting skills group %s", name)
- response, err := apiClient.CallAPI(path, "DELETE", nil, headerParams, nil, nil, "", nil)
-
- if err != nil {
- if util.IsStatus404(response) {
- //Skills Group already deleted
- log.Printf("Skills Group was already deleted %s", d.Id())
- return nil
- }
- return util.BuildAPIDiagnosticError(getSkillGroupResourceName(), fmt.Sprintf("Failed to delete skill group %s error: %s", d.Id(), err), response)
- }
-
- return util.WithRetries(ctx, 30*time.Second, func() *retry.RetryError {
- log.Printf("Deleting skills group %s", name)
- response, err := apiClient.CallAPI(path, "DELETE", nil, headerParams, nil, nil, "", nil)
-
- if err != nil {
- if util.IsStatus404(response) {
- // Skills Group Deleted
- log.Printf("Deleted skills group %s", d.Id())
- return nil
- }
- return retry.NonRetryableError(util.BuildWithRetriesApiDiagnosticError(getSkillGroupResourceName(), fmt.Sprintf("Error deleting skill group %s | error: %s", d.Id(), err), response))
- }
- return retry.RetryableError(util.BuildWithRetriesApiDiagnosticError(getSkillGroupResourceName(), fmt.Sprintf("Skill group %s still exists", d.Id()), response))
- })
-}
-
-func readSkillGroupMemberDivisionIds(d *schema.ResourceData, routingAPI *platformclientv2.RoutingApi) ([]string, diag.Diagnostics) {
- headers := BuildHeaderParams(routingAPI)
- apiClient := &routingAPI.Configuration.APIClient
- path := fmt.Sprintf("%s/api/v2/routing/skillgroups/%s/members/divisions", routingAPI.Configuration.BasePath, d.Id())
-
- log.Printf("Reading skill group %s member divisions", d.Get("name").(string))
-
- response, err := apiClient.CallAPI(path, "GET", nil, headers, nil, nil, "", nil)
- if err != nil || response.Error != nil {
- return nil, util.BuildAPIDiagnosticError(getSkillGroupResourceName(), fmt.Sprintf("Failed to get member divisions for skill group %s error: %s", d.Id(), err), response)
- }
-
- memberDivisionsPayload := make(map[string]interface{}, 0)
- err = json.Unmarshal(response.RawBody, &memberDivisionsPayload)
- if err != nil {
- return nil, util.BuildDiagnosticError(getSkillGroupResourceName(), fmt.Sprintf("Failed to unmarshal member divisions"), err)
- }
-
- apiSkillGroupMemberDivisionIds := make([]string, 0)
- entities := memberDivisionsPayload["entities"].([]interface{})
- for _, entity := range entities {
- if entityMap, ok := entity.(map[string]interface{}); ok {
- apiSkillGroupMemberDivisionIds = append(apiSkillGroupMemberDivisionIds, entityMap["id"].(string))
- }
- }
-
- log.Printf("Read skill group %s member divisions", d.Get("name").(string))
-
- return apiSkillGroupMemberDivisionIds, nil
-}
-
-func allMemberDivisionsSpecified(schemaSkillGroupMemberDivisionIds []string) bool {
- return lists.ItemInSlice("*", schemaSkillGroupMemberDivisionIds)
-}
-
-func organizeMemberDivisionIdsForUpdate(schemaIds, apiIds []string) ([]string, []string) {
- toAdd := make([]string, 0)
- toRemove := make([]string, 0)
- // items that are in hcl and not in api-returned list - add
- for _, id := range schemaIds {
- if !lists.ItemInSlice(id, apiIds) {
- toAdd = append(toAdd, id)
- }
- }
- // items that are not in hcl and are in api-returned list - remove
- for _, id := range apiIds {
- if !lists.ItemInSlice(id, schemaIds) {
- toRemove = append(toRemove, id)
- }
- }
- return toAdd, toRemove
-}
-
-// Prepare member_division_ids list to avoid an unnecessary plan not empty error
-func organizeMemberDivisionIdsForRead(schemaList, apiList []string, divisionId string) []string {
- if !lists.ItemInSlice(divisionId, schemaList) {
- apiList = lists.RemoveStringFromSlice(divisionId, apiList)
- }
- if len(schemaList) == 1 && schemaList[0] == "*" {
- return schemaList
- } else {
- // if hcl & api lists are the same but with different ordering - set with original ordering
- if lists.AreEquivalent(schemaList, apiList) {
- return schemaList
- } else {
- return apiList
- }
- }
-}
-
-// Remove the value of division_id, or if this field was left blank; the home division ID
-func removeSkillGroupDivisionID(d *schema.ResourceData, list []string) ([]string, diag.Diagnostics) {
- if len(list) == 0 || list == nil {
- return list, nil
- }
- divisionId := d.Get("division_id").(string)
- if divisionId == "" {
- id, diagErr := util.GetHomeDivisionID()
- if diagErr != nil {
- return nil, diagErr
- }
- divisionId = id
- }
- if lists.ItemInSlice(divisionId, list) {
- list = lists.RemoveStringFromSlice(divisionId, list)
- }
- return list, nil
-}
-
-func GenerateRoutingSkillGroupResourceBasic(
- resourceID string,
- name string,
- description string) string {
- return fmt.Sprintf(`resource "%s" "%s" {
- name = "%s"
- description="%s"
- }
- `, getSkillGroupResourceName(), resourceID, name, description)
-}
diff --git a/genesyscloud/resource_genesyscloud_user_test.go b/genesyscloud/resource_genesyscloud_user_test.go
index 4717f9318..0f3c3b4fe 100644
--- a/genesyscloud/resource_genesyscloud_user_test.go
+++ b/genesyscloud/resource_genesyscloud_user_test.go
@@ -3,12 +3,15 @@ package genesyscloud
import (
"context"
"fmt"
+ "log"
"strconv"
"strings"
"terraform-provider-genesyscloud/genesyscloud/provider"
routinglanguage "terraform-provider-genesyscloud/genesyscloud/routing_language"
routingUtilization "terraform-provider-genesyscloud/genesyscloud/routing_utilization"
routingUtilizationLabel "terraform-provider-genesyscloud/genesyscloud/routing_utilization_label"
+ routingSkill "terraform-provider-genesyscloud/genesyscloud/routing_skill"
+
extensionPool "terraform-provider-genesyscloud/genesyscloud/telephony_providers_edges_extension_pool"
"terraform-provider-genesyscloud/genesyscloud/util"
"testing"
@@ -465,7 +468,7 @@ func TestAccResourceUserSkills(t *testing.T) {
email1,
userName1,
generateUserRoutingSkill("genesyscloud_routing_skill."+skillResource1+".id", proficiency1),
- ) + GenerateRoutingSkillResource(skillResource1, skillName1),
+ ) + routingSkill.GenerateRoutingSkillResource(skillResource1, skillName1),
Check: resource.ComposeTestCheckFunc(
validateUserSkill("genesyscloud_user."+userResource1, "genesyscloud_routing_skill."+skillResource1, proficiency1),
),
@@ -478,10 +481,10 @@ func TestAccResourceUserSkills(t *testing.T) {
userName1,
generateUserRoutingSkill("genesyscloud_routing_skill."+skillResource1+".id", proficiency1),
generateUserRoutingSkill("genesyscloud_routing_skill."+skillResource2+".id", proficiency2),
- ) + GenerateRoutingSkillResource(
+ ) + routingSkill.GenerateRoutingSkillResource(
skillResource1,
skillName1,
- ) + GenerateRoutingSkillResource(
+ ) + routingSkill.GenerateRoutingSkillResource(
skillResource2,
skillName2,
),
@@ -497,7 +500,7 @@ func TestAccResourceUserSkills(t *testing.T) {
email1,
userName1,
generateUserRoutingSkill("genesyscloud_routing_skill."+skillResource2+".id", proficiency1),
- ) + GenerateRoutingSkillResource(
+ ) + routingSkill.GenerateRoutingSkillResource(
skillResource2,
skillName2,
),
@@ -1200,6 +1203,7 @@ func testVerifyUsersDestroyed(state *terraform.State) error {
}
return retry.NonRetryableError(util.BuildWithRetriesApiDiagnosticError("genesyscloud_user", fmt.Sprintf("Unexpected error: %s", err), resp))
}
+
return retry.RetryableError(util.BuildWithRetriesApiDiagnosticError("genesyscloud_user", fmt.Sprintf("User (%s) still exists", rs.Primary.ID), resp))
}
return nil
@@ -1213,6 +1217,46 @@ func testVerifyUsersDestroyed(state *terraform.State) error {
return nil
}
+func checkUserDeleted(id string) resource.TestCheckFunc {
+ log.Printf("Fetching user with ID: %s\n", id)
+ return func(s *terraform.State) error {
+ maxAttempts := 30
+ for i := 0; i < maxAttempts; i++ {
+
+ deleted, err := isUserDeleted(id)
+ if err != nil {
+ return err
+ }
+ if deleted {
+ return nil
+ }
+ time.Sleep(10 * time.Second)
+ }
+ return fmt.Errorf("user %s was not deleted properly", id)
+ }
+}
+
+func isUserDeleted(id string) (bool, error) {
+ sdkConfig, _ := provider.AuthorizeSdk()
+ usersAPI := platformclientv2.NewUsersApiWithConfig(sdkConfig)
+ // Attempt to get the user
+ _, response, err := usersAPI.GetUser(id, nil, "", "")
+
+ // Check if the user is not found (deleted)
+ if response != nil && response.StatusCode == 404 {
+ return true, nil // User is deleted
+ }
+
+ // Handle other errors
+ if err != nil {
+ log.Printf("Error fetching user: %v", err)
+ return false, err
+ }
+
+ // If user is found, it means the user is not deleted
+ return false, nil
+}
+
func validateUserSkill(userResourceName string, skillResourceName string, proficiency string) resource.TestCheckFunc {
return func(state *terraform.State) error {
userResource, ok := state.RootModule().Resources[userResourceName]
diff --git a/genesyscloud/responsemanagement_responseasset/resource_genesyscloud_responsemanagement_responseasset_schema.go b/genesyscloud/responsemanagement_responseasset/resource_genesyscloud_responsemanagement_responseasset_schema.go
index 0849c57ff..ce8e52f9d 100644
--- a/genesyscloud/responsemanagement_responseasset/resource_genesyscloud_responsemanagement_responseasset_schema.go
+++ b/genesyscloud/responsemanagement_responseasset/resource_genesyscloud_responsemanagement_responseasset_schema.go
@@ -4,9 +4,8 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"terraform-provider-genesyscloud/genesyscloud/provider"
resourceExporter "terraform-provider-genesyscloud/genesyscloud/resource_exporter"
- "terraform-provider-genesyscloud/genesyscloud/validators"
-
registrar "terraform-provider-genesyscloud/genesyscloud/resource_register"
+ "terraform-provider-genesyscloud/genesyscloud/validators"
)
/*
diff --git a/genesyscloud/routing_email_route/genesyscloud_routing_email_route_init_test.go b/genesyscloud/routing_email_route/genesyscloud_routing_email_route_init_test.go
index dd8dee2d5..b34fcae5b 100644
--- a/genesyscloud/routing_email_route/genesyscloud_routing_email_route_init_test.go
+++ b/genesyscloud/routing_email_route/genesyscloud_routing_email_route_init_test.go
@@ -2,12 +2,14 @@ package routing_email_route
import (
"sync"
- "terraform-provider-genesyscloud/genesyscloud"
+ routingSkillGroup "terraform-provider-genesyscloud/genesyscloud/routing_skill_group"
architectFlow "terraform-provider-genesyscloud/genesyscloud/architect_flow"
routingQueue "terraform-provider-genesyscloud/genesyscloud/routing_queue"
routingLanguage "terraform-provider-genesyscloud/genesyscloud/routing_language"
routingEmailDomain "terraform-provider-genesyscloud/genesyscloud/routing_email_domain"
+ routingSkill "terraform-provider-genesyscloud/genesyscloud/routing_skill"
+
"testing"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
@@ -38,9 +40,9 @@ func (r *registerTestInstance) registerTestResources() {
providerResources["genesyscloud_routing_email_domain"] = routingEmailDomain.ResourceRoutingEmailDomain()
providerResources["genesyscloud_routing_queue"] = routingQueue.ResourceRoutingQueue()
providerResources["genesyscloud_routing_language"] = routingLanguage.ResourceRoutingLanguage()
- providerResources["genesyscloud_routing_skill"] = genesyscloud.ResourceRoutingSkill()
+ providerResources["genesyscloud_routing_skill"] = routingSkill.ResourceRoutingSkill()
providerResources["genesyscloud_flow"] = architectFlow.ResourceArchitectFlow()
- providerResources["genesyscloud_routing_skill_group"] = genesyscloud.ResourceRoutingSkillGroup()
+ providerResources["genesyscloud_routing_skill_group"] = routingSkillGroup.ResourceRoutingSkillGroup()
}
// registerTestDataSources registers all data sources used in the tests.
diff --git a/genesyscloud/routing_email_route/resource_genesyscloud_routing_email_route_test.go b/genesyscloud/routing_email_route/resource_genesyscloud_routing_email_route_test.go
index e8ebb5b46..700aaa04a 100644
--- a/genesyscloud/routing_email_route/resource_genesyscloud_routing_email_route_test.go
+++ b/genesyscloud/routing_email_route/resource_genesyscloud_routing_email_route_test.go
@@ -5,12 +5,12 @@ import (
"log"
"regexp"
"strings"
- gcloud "terraform-provider-genesyscloud/genesyscloud"
"terraform-provider-genesyscloud/genesyscloud/architect_flow"
"terraform-provider-genesyscloud/genesyscloud/provider"
routingQueue "terraform-provider-genesyscloud/genesyscloud/routing_queue"
routingLanguage "terraform-provider-genesyscloud/genesyscloud/routing_language"
routingEmailDomain "terraform-provider-genesyscloud/genesyscloud/routing_email_domain"
+ routingSkill "terraform-provider-genesyscloud/genesyscloud/routing_skill"
"terraform-provider-genesyscloud/genesyscloud/util"
"testing"
@@ -130,7 +130,7 @@ func TestAccResourceRoutingEmailRoute(t *testing.T) {
) + routingLanguage.GenerateRoutingLanguageResource(
langResource,
langName,
- ) + gcloud.GenerateRoutingSkillResource(
+ ) + routingSkill.GenerateRoutingSkillResource(
skillResource,
skillName,
) + architect_flow.GenerateFlowResource(
@@ -202,7 +202,7 @@ func TestAccResourceRoutingEmailRoute(t *testing.T) {
) + routingLanguage.GenerateRoutingLanguageResource(
langResource,
langName,
- ) + gcloud.GenerateRoutingSkillResource(
+ ) + routingSkill.GenerateRoutingSkillResource(
skillResource,
skillName,
) + GenerateRoutingEmailRouteResource(
@@ -259,7 +259,7 @@ func TestAccResourceRoutingEmailRoute(t *testing.T) {
) + routingLanguage.GenerateRoutingLanguageResource(
langResource,
langName,
- ) + gcloud.GenerateRoutingSkillResource(
+ ) + routingSkill.GenerateRoutingSkillResource(
skillResource,
skillName,
) + GenerateRoutingEmailRouteResource(
@@ -321,7 +321,7 @@ func TestAccResourceRoutingEmailRoute(t *testing.T) {
) + routingLanguage.GenerateRoutingLanguageResource(
langResource,
langName,
- ) + gcloud.GenerateRoutingSkillResource(
+ ) + routingSkill.GenerateRoutingSkillResource(
skillResource,
skillName,
) + GenerateRoutingEmailRouteResource(
diff --git a/genesyscloud/routing_queue/genesyscloud_routing_queue_init_test.go b/genesyscloud/routing_queue/genesyscloud_routing_queue_init_test.go
index 6a9d21473..953cf461c 100644
--- a/genesyscloud/routing_queue/genesyscloud_routing_queue_init_test.go
+++ b/genesyscloud/routing_queue/genesyscloud_routing_queue_init_test.go
@@ -6,7 +6,9 @@ import (
architectFlow "terraform-provider-genesyscloud/genesyscloud/architect_flow"
"terraform-provider-genesyscloud/genesyscloud/architect_user_prompt"
"terraform-provider-genesyscloud/genesyscloud/group"
+ routingSkillGroup "terraform-provider-genesyscloud/genesyscloud/routing_skill_group"
"testing"
+ routingSkill "terraform-provider-genesyscloud/genesyscloud/routing_skill"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
@@ -34,11 +36,11 @@ func (r *registerTestInstance) registerTestResources() {
providerResources[resourceName] = ResourceRoutingQueue()
providerResources["genesyscloud_user"] = gcloud.ResourceUser()
- providerResources["genesyscloud_routing_skill"] = gcloud.ResourceRoutingSkill()
+ providerResources["genesyscloud_routing_skill"] = routingSkill.ResourceRoutingSkill()
providerResources["genesyscloud_group"] = group.ResourceGroup()
providerResources["genesyscloud_routing_wrapupcode"] = gcloud.ResourceRoutingWrapupCode()
providerResources["genesyscloud_flow"] = architectFlow.ResourceArchitectFlow()
- providerResources["genesyscloud_routing_skill_group"] = gcloud.ResourceRoutingSkillGroup()
+ providerResources["genesyscloud_routing_skill_group"] = routingSkillGroup.ResourceRoutingSkillGroup()
providerResources["genesyscloud_architect_user_prompt"] = architect_user_prompt.ResourceArchitectUserPrompt()
}
diff --git a/genesyscloud/routing_queue/resource_genesyscloud_routing_queue_test.go b/genesyscloud/routing_queue/resource_genesyscloud_routing_queue_test.go
index 0d86f40fd..fe1a4e13f 100644
--- a/genesyscloud/routing_queue/resource_genesyscloud_routing_queue_test.go
+++ b/genesyscloud/routing_queue/resource_genesyscloud_routing_queue_test.go
@@ -11,8 +11,10 @@ import (
"terraform-provider-genesyscloud/genesyscloud/architect_user_prompt"
"terraform-provider-genesyscloud/genesyscloud/group"
"terraform-provider-genesyscloud/genesyscloud/provider"
+ routingSkillGroup "terraform-provider-genesyscloud/genesyscloud/routing_skill_group"
"terraform-provider-genesyscloud/genesyscloud/util"
featureToggles "terraform-provider-genesyscloud/genesyscloud/util/feature_toggles"
+ routingSkill "terraform-provider-genesyscloud/genesyscloud/routing_skill"
"terraform-provider-genesyscloud/genesyscloud/util/testrunner"
"testing"
"time"
@@ -68,7 +70,7 @@ func TestAccResourceRoutingQueueBasic(t *testing.T) {
Steps: []resource.TestStep{
{
// Create
- Config: generateUserWithCustomAttrs(testUserResource, testUserEmail, testUserName) + genesyscloud.GenerateRoutingSkillResource(queueSkillResource, queueSkillName) +
+ Config: generateUserWithCustomAttrs(testUserResource, testUserEmail, testUserName) + routingSkill.GenerateRoutingSkillResource(queueSkillResource, queueSkillName) +
group.GenerateGroupResource(
bullseyeMemberGroupName,
"MySeries6Groupv20",
@@ -249,7 +251,7 @@ func TestAccResourceRoutingQueueConditionalRouting(t *testing.T) {
time.Sleep(30 * time.Second)
},
// Create
- Config: genesyscloud.GenerateRoutingSkillGroupResourceBasic(
+ Config: routingSkillGroup.GenerateRoutingSkillGroupResourceBasic(
skillGroupResourceId,
skillGroupName,
"description",
@@ -346,7 +348,7 @@ func TestAccResourceRoutingQueueConditionalRouting(t *testing.T) {
queueResource2,
queueName2,
) +
- genesyscloud.GenerateRoutingSkillGroupResourceBasic(
+ routingSkillGroup.GenerateRoutingSkillGroupResourceBasic(
skillGroupResourceId,
skillGroupName,
"description",
@@ -520,7 +522,7 @@ func TestAccResourceRoutingQueueParToCGR(t *testing.T) {
ProviderFactories: provider.GetProviderFactories(providerResources, providerDataSources),
Steps: []resource.TestStep{
{
- Config: genesyscloud.GenerateRoutingSkillGroupResourceBasic(
+ Config: routingSkillGroup.GenerateRoutingSkillGroupResourceBasic(
skillGroupResourceId,
skillGroupName,
"description",
@@ -828,7 +830,7 @@ func TestAccResourceRoutingQueueSkillgroupMembers(t *testing.T) {
ProviderFactories: provider.GetProviderFactories(providerResources, providerDataSources),
Steps: []resource.TestStep{
{
- Config: genesyscloud.GenerateRoutingSkillResource(
+ Config: routingSkill.GenerateRoutingSkillResource(
skillResourceId,
skillName,
) + skillGroupConfig + user2Config +
@@ -1600,7 +1602,7 @@ func TestAccResourceRoutingQueueSkillGroups(t *testing.T) {
Steps: []resource.TestStep{
{
// Create
- Config: generateUserWithCustomAttrs(testUserResource, testUserEmail, testUserName) + genesyscloud.GenerateRoutingSkillGroupResourceBasic(skillGroupResource, skillGroupName, skillGroupDescription) +
+ Config: generateUserWithCustomAttrs(testUserResource, testUserEmail, testUserName) + routingSkillGroup.GenerateRoutingSkillGroupResourceBasic(skillGroupResource, skillGroupName, skillGroupDescription) +
group.GenerateBasicGroupResource(groupResource, groupName,
group.GenerateGroupOwners("genesyscloud_user."+testUserResource+".id"),
) +
diff --git a/genesyscloud/routing_queue_conditional_group_routing/genesyscloud_routing_queue_conditional_group_routing_init_test.go b/genesyscloud/routing_queue_conditional_group_routing/genesyscloud_routing_queue_conditional_group_routing_init_test.go
index 07ee75aaf..3c16ab62c 100644
--- a/genesyscloud/routing_queue_conditional_group_routing/genesyscloud_routing_queue_conditional_group_routing_init_test.go
+++ b/genesyscloud/routing_queue_conditional_group_routing/genesyscloud_routing_queue_conditional_group_routing_init_test.go
@@ -6,6 +6,7 @@ import (
gcloud "terraform-provider-genesyscloud/genesyscloud"
"terraform-provider-genesyscloud/genesyscloud/group"
routingQueue "terraform-provider-genesyscloud/genesyscloud/routing_queue"
+ routingSkillGroup "terraform-provider-genesyscloud/genesyscloud/routing_skill_group"
"testing"
)
@@ -28,7 +29,7 @@ func (r *registerTestInstance) registerTestResources() {
providerResources[resourceName] = ResourceRoutingQueueConditionalGroupRouting()
providerResources["genesyscloud_routing_queue"] = routingQueue.ResourceRoutingQueue()
- providerResources["genesyscloud_routing_skill_group"] = gcloud.ResourceRoutingSkillGroup()
+ providerResources["genesyscloud_routing_skill_group"] = routingSkillGroup.ResourceRoutingSkillGroup()
providerResources["genesyscloud_user"] = gcloud.ResourceUser()
providerResources["genesyscloud_group"] = group.ResourceGroup()
}
diff --git a/genesyscloud/routing_queue_conditional_group_routing/resource_genesyscloud_routing_queue_conditional_group_routing_test.go b/genesyscloud/routing_queue_conditional_group_routing/resource_genesyscloud_routing_queue_conditional_group_routing_test.go
index 259314613..fcc99d737 100644
--- a/genesyscloud/routing_queue_conditional_group_routing/resource_genesyscloud_routing_queue_conditional_group_routing_test.go
+++ b/genesyscloud/routing_queue_conditional_group_routing/resource_genesyscloud_routing_queue_conditional_group_routing_test.go
@@ -6,10 +6,10 @@ import (
"os"
"strings"
"sync"
- gcloud "terraform-provider-genesyscloud/genesyscloud"
"terraform-provider-genesyscloud/genesyscloud/group"
"terraform-provider-genesyscloud/genesyscloud/provider"
routingQueue "terraform-provider-genesyscloud/genesyscloud/routing_queue"
+ routingSkillGroup "terraform-provider-genesyscloud/genesyscloud/routing_skill_group"
"terraform-provider-genesyscloud/genesyscloud/util"
featureToggles "terraform-provider-genesyscloud/genesyscloud/util/feature_toggles"
"testing"
@@ -72,7 +72,7 @@ func TestAccResourceRoutingQueueConditionalGroupRouting(t *testing.T) {
{
// Create the queue first so we can save the id to a channel and use it in the later test steps
// The reason we are doing this is that we need to verify the parent queue is never dropped and recreated because of CGR
- Config: gcloud.GenerateRoutingSkillGroupResourceBasic(
+ Config: routingSkillGroup.GenerateRoutingSkillGroupResourceBasic(
skillGroupResourceId,
skillGroupName,
"description",
@@ -95,7 +95,7 @@ func TestAccResourceRoutingQueueConditionalGroupRouting(t *testing.T) {
},
{
// Create rule
- Config: gcloud.GenerateRoutingSkillGroupResourceBasic(
+ Config: routingSkillGroup.GenerateRoutingSkillGroupResourceBasic(
skillGroupResourceId,
skillGroupName,
"description",
@@ -142,7 +142,7 @@ func TestAccResourceRoutingQueueConditionalGroupRouting(t *testing.T) {
groupResourceId,
groupName,
group.GenerateGroupOwners("genesyscloud_user."+testUserResource+".id"),
- ) + gcloud.GenerateRoutingSkillGroupResourceBasic(
+ ) + routingSkillGroup.GenerateRoutingSkillGroupResourceBasic(
skillGroupResourceId,
skillGroupName,
"description",
diff --git a/genesyscloud/routing_queue_conditional_group_routing/resource_genesyscloud_routing_queue_conditional_group_routing_unit_test.go b/genesyscloud/routing_queue_conditional_group_routing/resource_genesyscloud_routing_queue_conditional_group_routing_unit_test.go
index fc4f84f7f..0d23ea6a7 100644
--- a/genesyscloud/routing_queue_conditional_group_routing/resource_genesyscloud_routing_queue_conditional_group_routing_unit_test.go
+++ b/genesyscloud/routing_queue_conditional_group_routing/resource_genesyscloud_routing_queue_conditional_group_routing_unit_test.go
@@ -4,6 +4,7 @@ import (
"context"
"net/http"
"terraform-provider-genesyscloud/genesyscloud/provider"
+ featureToggles "terraform-provider-genesyscloud/genesyscloud/util/feature_toggles"
"testing"
"github.com/google/go-cmp/cmp"
@@ -18,6 +19,10 @@ func TestUnitResourceRoutingQueueConditionalGroupRoutingUpdate(t *testing.T) {
tRules := generateRuleData()
tId := tQueueId + "/rules"
+ if !featureToggles.CSGToggleExists() {
+ t.Skipf("Skipping because %s env variable is not set", featureToggles.CSGToggleName())
+ }
+
groupRoutingProxy := &routingQueueConditionalGroupRoutingProxy{}
groupRoutingProxy.updateRoutingQueueConditionRoutingAttr = func(ctx context.Context, p *routingQueueConditionalGroupRoutingProxy, queueId string, rules *[]platformclientv2.Conditionalgrouproutingrule) (*[]platformclientv2.Conditionalgrouproutingrule, *platformclientv2.APIResponse, error) {
equal := cmp.Equal(tRules, *rules)
@@ -57,6 +62,10 @@ func TestUnitResourceRoutingQueueConditionalGroupRoutingRead(t *testing.T) {
tRules := generateRuleData()
tId := tQueueId + "/rules"
+ if !featureToggles.CSGToggleExists() {
+ t.Skipf("Skipping because %s env variable is not set", featureToggles.CSGToggleName())
+ }
+
groupRoutingProxy := &routingQueueConditionalGroupRoutingProxy{}
groupRoutingProxy.getRoutingQueueConditionRoutingAttr = func(ctx context.Context, p *routingQueueConditionalGroupRoutingProxy, queueId string) (*[]platformclientv2.Conditionalgrouproutingrule, *platformclientv2.APIResponse, error) {
diff --git a/genesyscloud/routing_queue_outbound_email_address/resource_genesyscloud_routing_queue_outbound_email_address_unit_test.go b/genesyscloud/routing_queue_outbound_email_address/resource_genesyscloud_routing_queue_outbound_email_address_unit_test.go
index 00f239f42..7ac363a35 100644
--- a/genesyscloud/routing_queue_outbound_email_address/resource_genesyscloud_routing_queue_outbound_email_address_unit_test.go
+++ b/genesyscloud/routing_queue_outbound_email_address/resource_genesyscloud_routing_queue_outbound_email_address_unit_test.go
@@ -4,6 +4,7 @@ import (
"context"
"net/http"
"terraform-provider-genesyscloud/genesyscloud/provider"
+ featureToggles "terraform-provider-genesyscloud/genesyscloud/util/feature_toggles"
"testing"
"github.com/google/uuid"
@@ -19,6 +20,10 @@ func TestUnitResourceRoutingQueueOutboundEmailAddressUpdate(t *testing.T) {
tId := tQueueId
+ if !featureToggles.OEAToggleExists() {
+ t.Skipf("Skipping because env variable %s is not set", featureToggles.OEAToggleName())
+ }
+
groupRoutingProxy := &routingQueueOutboundEmailAddressProxy{}
groupRoutingProxy.updateRoutingQueueOutboundEmailAddressAttr = func(ctx context.Context, p *routingQueueOutboundEmailAddressProxy, queueId string, address *platformclientv2.Queueemailaddress) (*platformclientv2.Queueemailaddress, *platformclientv2.APIResponse, error) {
assert.Equal(t, tDomainId, *address.Domain.Id)
@@ -71,6 +76,10 @@ func TestUnitResourceRoutingQueueOutboundEmailAddressRead(t *testing.T) {
tRouteId := uuid.NewString()
tId := tQueueId
+ if !featureToggles.OEAToggleExists() {
+ t.Skipf("Skipping because env variable %s is not set", featureToggles.OEAToggleName())
+ }
+
groupRoutingProxy := &routingQueueOutboundEmailAddressProxy{}
groupRoutingProxy.getRoutingQueueOutboundEmailAddressAttr = func(ctx context.Context, p *routingQueueOutboundEmailAddressProxy, queueId string) (*platformclientv2.Queueemailaddress, *platformclientv2.APIResponse, error) {
diff --git a/genesyscloud/routing_skill/data_source_genesyscloud_routing_skill.go b/genesyscloud/routing_skill/data_source_genesyscloud_routing_skill.go
new file mode 100644
index 000000000..4b89dac5b
--- /dev/null
+++ b/genesyscloud/routing_skill/data_source_genesyscloud_routing_skill.go
@@ -0,0 +1,78 @@
+package routing_skill
+
+import (
+ "context"
+ "fmt"
+ "log"
+ "terraform-provider-genesyscloud/genesyscloud/provider"
+ rc "terraform-provider-genesyscloud/genesyscloud/resource_cache"
+ "terraform-provider-genesyscloud/genesyscloud/util"
+ "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"
+)
+
+var dataSourceRoutingSkillCache *rc.DataSourceCache
+
+func dataSourceRoutingSkillRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
+ sdkConfig := m.(*provider.ProviderMeta).ClientConfig
+ key := d.Get("name").(string)
+
+ if dataSourceRoutingSkillCache == nil {
+ dataSourceRoutingSkillCache = rc.NewDataSourceCache(sdkConfig, hydrateRoutingSkillCacheFn, getSkillByNameFn)
+ }
+
+ queueId, err := rc.RetrieveId(dataSourceRoutingSkillCache, resourceName, key, ctx)
+ if err != nil {
+ return err
+ }
+
+ d.SetId(queueId)
+ return nil
+}
+
+func hydrateRoutingSkillCacheFn(c *rc.DataSourceCache) error {
+ log.Printf("hydrating cache for data source genesyscloud_routing_skill")
+ proxy := getRoutingSkillProxy(c.ClientConfig)
+
+ skills, resp, getErr := proxy.getAllRoutingSkills(context.TODO(), "")
+ if getErr != nil {
+ return fmt.Errorf("failed to get page of skills: %v %v", getErr, resp)
+ }
+
+ if skills == nil || len(*skills) == 0 {
+ return nil
+ }
+
+ for _, skill := range *skills {
+ c.Cache[*skill.Name] = *skill.Id
+ }
+
+ log.Printf("cache hydration completed for data source genesyscloud_routing_skill")
+
+ return nil
+}
+
+func getSkillByNameFn(c *rc.DataSourceCache, name string, ctx context.Context) (string, diag.Diagnostics) {
+ skillId := ""
+ proxy := getRoutingSkillProxy(c.ClientConfig)
+
+ // Find first non-deleted skill by name. Retry in case new skill is not yet indexed by search
+ diag := util.WithRetries(ctx, 15*time.Second, func() *retry.RetryError {
+ skill, resp, retryable, getErr := proxy.getRoutingSkillIdByName(ctx, name)
+ if getErr != nil && !retryable {
+ return retry.NonRetryableError(util.BuildWithRetriesApiDiagnosticError(resourceName, fmt.Sprintf("error requesting skill %s | error: %s", name, getErr), resp))
+ }
+
+ if retryable {
+ return retry.RetryableError(util.BuildWithRetriesApiDiagnosticError(resourceName, fmt.Sprintf("no routing skills found with name %s", name), resp))
+ }
+
+ skillId = skill
+ return nil
+ })
+ return skillId, diag
+}
diff --git a/genesyscloud/data_source_genesyscloud_routing_skill_test.go b/genesyscloud/routing_skill/data_source_genesyscloud_routing_skill_test.go
similarity index 90%
rename from genesyscloud/data_source_genesyscloud_routing_skill_test.go
rename to genesyscloud/routing_skill/data_source_genesyscloud_routing_skill_test.go
index becba0679..cd565b3f3 100644
--- a/genesyscloud/data_source_genesyscloud_routing_skill_test.go
+++ b/genesyscloud/routing_skill/data_source_genesyscloud_routing_skill_test.go
@@ -1,14 +1,15 @@
-package genesyscloud
+package routing_skill
import (
"fmt"
- "github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
"log"
"terraform-provider-genesyscloud/genesyscloud/provider"
"terraform-provider-genesyscloud/genesyscloud/util"
"testing"
"time"
+ "github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
+
"github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)
@@ -57,8 +58,8 @@ func waitSeconds(duration time.Duration) resource.TestCheckFunc {
func generateRoutingSkillDataSource(
resourceID string,
name string,
-// Must explicitly use depends_on in terraform v0.13 when a data source references a resource
-// Fixed in v0.14 https://github.com/hashicorp/terraform/pull/26284
+ // Must explicitly use depends_on in terraform v0.13 when a data source references a resource
+ // Fixed in v0.14 https://github.com/hashicorp/terraform/pull/26284
dependsOnResource string) string {
return fmt.Sprintf(`data "genesyscloud_routing_skill" "%s" {
name = %s
diff --git a/genesyscloud/routing_skill/genesyscloud_routing_skill_init_test.go b/genesyscloud/routing_skill/genesyscloud_routing_skill_init_test.go
new file mode 100644
index 000000000..618bf2ce9
--- /dev/null
+++ b/genesyscloud/routing_skill/genesyscloud_routing_skill_init_test.go
@@ -0,0 +1,52 @@
+package routing_skill
+
+import (
+ "sync"
+ "testing"
+
+ "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
+)
+
+var providerDataSources map[string]*schema.Resource
+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] = ResourceRoutingSkill()
+}
+
+// registerTestDataSources registers all data sources used in the tests.
+func (r *registerTestInstance) registerTestDataSources() {
+ r.datasourceMapMutex.Lock()
+ defer r.datasourceMapMutex.Unlock()
+
+ providerDataSources[resourceName] = DataSourceRoutingSkill()
+}
+
+// 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.registerTestDataSources()
+ 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 routing_skill package
+ initTestResources()
+
+ // Run the test suite for the routing_skill package
+ m.Run()
+}
diff --git a/genesyscloud/routing_skill/genesyscloud_routing_skill_proxy.go b/genesyscloud/routing_skill/genesyscloud_routing_skill_proxy.go
new file mode 100644
index 000000000..12ade10ec
--- /dev/null
+++ b/genesyscloud/routing_skill/genesyscloud_routing_skill_proxy.go
@@ -0,0 +1,145 @@
+package routing_skill
+
+import (
+ "context"
+ "fmt"
+ "log"
+ rc "terraform-provider-genesyscloud/genesyscloud/resource_cache"
+
+ "github.com/mypurecloud/platform-client-sdk-go/v133/platformclientv2"
+)
+
+var internalProxy *routingSkillProxy
+
+type getAllRoutingSkillsFunc func(ctx context.Context, p *routingSkillProxy, name string) (*[]platformclientv2.Routingskill, *platformclientv2.APIResponse, error)
+type createRoutingSkillFunc func(ctx context.Context, p *routingSkillProxy, routingSkill *platformclientv2.Routingskill) (*platformclientv2.Routingskill, *platformclientv2.APIResponse, error)
+type getRoutingSkillByIdFunc func(ctx context.Context, p *routingSkillProxy, id string) (*platformclientv2.Routingskill, *platformclientv2.APIResponse, error)
+type getRoutingSkillIdByNameFunc func(ctx context.Context, p *routingSkillProxy, name string) (string, *platformclientv2.APIResponse, bool, error)
+type deleteRoutingSkillFunc func(ctx context.Context, p *routingSkillProxy, id string) (*platformclientv2.APIResponse, error)
+
+// routingSkillProxy contains all of the methods that call genesys cloud APIs.
+type routingSkillProxy struct {
+ clientConfig *platformclientv2.Configuration
+ routingApi *platformclientv2.RoutingApi
+ createRoutingSkillAttr createRoutingSkillFunc
+ getAllRoutingSkillsAttr getAllRoutingSkillsFunc
+ getRoutingSkillIdByNameAttr getRoutingSkillIdByNameFunc
+ getRoutingSkillByIdAttr getRoutingSkillByIdFunc
+ deleteRoutingSkillAttr deleteRoutingSkillFunc
+ routingCache rc.CacheInterface[platformclientv2.Routingskill]
+}
+
+// newRoutingSkillProxy initializes the routing skill proxy with all of the data needed to communicate with Genesys Cloud
+func newRoutingSkillProxy(clientConfig *platformclientv2.Configuration) *routingSkillProxy {
+ api := platformclientv2.NewRoutingApiWithConfig(clientConfig)
+ routingCache := rc.NewResourceCache[platformclientv2.Routingskill]()
+ return &routingSkillProxy{
+ clientConfig: clientConfig,
+ routingApi: api,
+ createRoutingSkillAttr: createRoutingSkillFn,
+ getAllRoutingSkillsAttr: getAllRoutingSkillsFn,
+ getRoutingSkillIdByNameAttr: getRoutingSkillIdByNameFn,
+ getRoutingSkillByIdAttr: getRoutingSkillByIdFn,
+ deleteRoutingSkillAttr: deleteRoutingSkillFn,
+ routingCache: routingCache,
+ }
+}
+
+func getRoutingSkillProxy(clientConfig *platformclientv2.Configuration) *routingSkillProxy {
+ if internalProxy == nil {
+ internalProxy = newRoutingSkillProxy(clientConfig)
+ }
+
+ return internalProxy
+}
+
+func (p *routingSkillProxy) getAllRoutingSkills(ctx context.Context, name string) (*[]platformclientv2.Routingskill, *platformclientv2.APIResponse, error) {
+ return p.getAllRoutingSkillsAttr(ctx, p, name)
+}
+
+func (p *routingSkillProxy) createRoutingSkill(ctx context.Context, routingSkill *platformclientv2.Routingskill) (*platformclientv2.Routingskill, *platformclientv2.APIResponse, error) {
+ return p.createRoutingSkillAttr(ctx, p, routingSkill)
+}
+
+func (p *routingSkillProxy) getRoutingSkillById(ctx context.Context, id string) (*platformclientv2.Routingskill, *platformclientv2.APIResponse, error) {
+ return p.getRoutingSkillByIdAttr(ctx, p, id)
+}
+
+func (p *routingSkillProxy) getRoutingSkillIdByName(ctx context.Context, name string) (string, *platformclientv2.APIResponse, bool, error) {
+ return p.getRoutingSkillIdByNameAttr(ctx, p, name)
+}
+
+func (p *routingSkillProxy) deleteRoutingSkill(ctx context.Context, id string) (*platformclientv2.APIResponse, error) {
+ return p.deleteRoutingSkillAttr(ctx, p, id)
+}
+
+func getAllRoutingSkillsFn(ctx context.Context, p *routingSkillProxy, name string) (*[]platformclientv2.Routingskill, *platformclientv2.APIResponse, error) {
+ var allRoutingSkills []platformclientv2.Routingskill
+ const pageSize = 100
+
+ routingSkills, resp, err := p.routingApi.GetRoutingSkills(pageSize, 1, name, nil)
+ if err != nil {
+ return nil, resp, err
+ }
+
+ if routingSkills.Entities == nil || len(*routingSkills.Entities) == 0 {
+ return &allRoutingSkills, resp, nil
+ }
+
+ allRoutingSkills = append(allRoutingSkills, *routingSkills.Entities...)
+
+ for pageNum := 2; pageNum <= *routingSkills.PageCount; pageNum++ {
+ routingSkills, _, err := p.routingApi.GetRoutingSkills(pageSize, pageNum, name, nil)
+ if err != nil {
+ return nil, resp, err
+ }
+
+ if routingSkills.Entities == nil || len(*routingSkills.Entities) == 0 {
+ break
+ }
+
+ allRoutingSkills = append(allRoutingSkills, *routingSkills.Entities...)
+
+ }
+
+ for _, skill := range allRoutingSkills {
+ rc.SetCache(p.routingCache, *skill.Id, skill)
+ }
+
+ return &allRoutingSkills, resp, nil
+}
+
+func createRoutingSkillFn(ctx context.Context, p *routingSkillProxy, routingSkill *platformclientv2.Routingskill) (*platformclientv2.Routingskill, *platformclientv2.APIResponse, error) {
+ return p.routingApi.PostRoutingSkills(*routingSkill)
+}
+
+func getRoutingSkillByIdFn(ctx context.Context, p *routingSkillProxy, id string) (*platformclientv2.Routingskill, *platformclientv2.APIResponse, error) {
+ if skill := rc.GetCacheItem(p.routingCache, id); skill != nil {
+ return skill, nil, nil
+ }
+ return p.routingApi.GetRoutingSkill(id)
+}
+
+func getRoutingSkillIdByNameFn(ctx context.Context, p *routingSkillProxy, name string) (string, *platformclientv2.APIResponse, bool, error) {
+ routingSkills, resp, err := getAllRoutingSkillsFn(ctx, p, name)
+ if err != nil {
+ return "", resp, false, err
+ }
+
+ if routingSkills == nil || len(*routingSkills) == 0 {
+ return "", resp, true, err
+ }
+
+ for _, routingSkill := range *routingSkills {
+ if *routingSkill.Name == name {
+ log.Printf("Retrieved the routing skill id %s by name %s", *routingSkill.Id, name)
+ return *routingSkill.Id, resp, false, nil
+ }
+ }
+
+ return "", resp, true, fmt.Errorf("unable to find routing skill with name %s", name)
+}
+
+func deleteRoutingSkillFn(ctx context.Context, p *routingSkillProxy, id string) (*platformclientv2.APIResponse, error) {
+ return p.routingApi.DeleteRoutingSkill(id)
+}
diff --git a/genesyscloud/routing_skill/resource_genesyscloud_routing_skill.go b/genesyscloud/routing_skill/resource_genesyscloud_routing_skill.go
new file mode 100644
index 000000000..7c8693c96
--- /dev/null
+++ b/genesyscloud/routing_skill/resource_genesyscloud_routing_skill.go
@@ -0,0 +1,122 @@
+package routing_skill
+
+import (
+ "context"
+ "fmt"
+ "log"
+ "terraform-provider-genesyscloud/genesyscloud/provider"
+ "terraform-provider-genesyscloud/genesyscloud/util"
+ "terraform-provider-genesyscloud/genesyscloud/util/constants"
+ "time"
+
+ "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
+
+ "terraform-provider-genesyscloud/genesyscloud/consistency_checker"
+
+ resourceExporter "terraform-provider-genesyscloud/genesyscloud/resource_exporter"
+
+ "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"
+)
+
+func getAllRoutingSkills(ctx context.Context, clientConfig *platformclientv2.Configuration) (resourceExporter.ResourceIDMetaMap, diag.Diagnostics) {
+ resources := make(resourceExporter.ResourceIDMetaMap)
+ proxy := getRoutingSkillProxy(clientConfig)
+
+ skills, resp, getErr := proxy.getAllRoutingSkills(ctx, "")
+ if getErr != nil {
+ return nil, util.BuildAPIDiagnosticError(resourceName, fmt.Sprintf("Failed to get all routing skills | error: %s", getErr), resp)
+ }
+
+ for _, skill := range *skills {
+ if skill.State != nil && *skill.State != "deleted" {
+ resources[*skill.Id] = &resourceExporter.ResourceMeta{Name: *skill.Name}
+ }
+ }
+
+ return resources, nil
+}
+
+func createRoutingSkill(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
+ sdkConfig := meta.(*provider.ProviderMeta).ClientConfig
+ proxy := getRoutingSkillProxy(sdkConfig)
+ name := d.Get("name").(string)
+
+ log.Printf("Creating skill %s", name)
+ skill, resp, err := proxy.createRoutingSkill(ctx, &platformclientv2.Routingskill{
+ Name: &name,
+ })
+ if err != nil {
+ return util.BuildAPIDiagnosticError(resourceName, fmt.Sprintf("Failed to create skill %s error: %s", name, err), resp)
+ }
+
+ d.SetId(*skill.Id)
+ log.Printf("Created skill %s %s", name, *skill.Id)
+ return readRoutingSkill(ctx, d, meta)
+}
+
+func readRoutingSkill(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
+ sdkConfig := meta.(*provider.ProviderMeta).ClientConfig
+ proxy := getRoutingSkillProxy(sdkConfig)
+ cc := consistency_checker.NewConsistencyCheck(ctx, d, meta, ResourceRoutingSkill(), constants.DefaultConsistencyChecks, resourceName)
+
+ log.Printf("Reading skill %s", d.Id())
+ return util.WithRetriesForRead(ctx, d, func() *retry.RetryError {
+ skill, resp, getErr := proxy.getRoutingSkillById(ctx, d.Id())
+ if getErr != nil {
+ if util.IsStatus404(resp) {
+ return retry.RetryableError(util.BuildWithRetriesApiDiagnosticError(resourceName, fmt.Sprintf("Failed to read skill %s | error: %s", d.Id(), getErr), resp))
+ }
+ return retry.NonRetryableError(util.BuildWithRetriesApiDiagnosticError(resourceName, fmt.Sprintf("Failed to read skill %s | error: %s", d.Id(), getErr), resp))
+ }
+
+ if skill.State != nil && *skill.State == "deleted" {
+ d.SetId("")
+ return nil
+ }
+
+ _ = d.Set("name", *skill.Name)
+ log.Printf("Read skill %s %s", d.Id(), *skill.Name)
+ return cc.CheckState(d)
+ })
+}
+
+func deleteRoutingSkill(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
+ sdkConfig := meta.(*provider.ProviderMeta).ClientConfig
+ proxy := getRoutingSkillProxy(sdkConfig)
+ name := d.Get("name").(string)
+
+ log.Printf("Deleting Routing skill %s", name)
+ resp, err := proxy.deleteRoutingSkill(ctx, d.Id())
+ if err != nil {
+ return util.BuildAPIDiagnosticError(resourceName, fmt.Sprintf("Failed to delete skill %s error: %s", name, err), resp)
+ }
+
+ return util.WithRetries(ctx, 30*time.Second, func() *retry.RetryError {
+ routingSkill, resp, err := proxy.getRoutingSkillById(ctx, d.Id())
+ if err != nil {
+ if util.IsStatus404(resp) {
+ log.Printf("Deleted Routing skill %s", d.Id())
+ return nil
+ }
+ return retry.NonRetryableError(util.BuildWithRetriesApiDiagnosticError(resourceName, fmt.Sprintf("Error deleting Routing skill %s | error: %s", d.Id(), err), resp))
+ }
+
+ if routingSkill.State != nil && *routingSkill.State == "deleted" {
+ log.Printf("Deleted Routing skill %s", d.Id())
+ return nil
+ }
+
+ return retry.RetryableError(util.BuildWithRetriesApiDiagnosticError(resourceName, fmt.Sprintf("Routing skill %s still exists", d.Id()), resp))
+ })
+}
+
+func GenerateRoutingSkillResource(
+ resourceID string,
+ name string) string {
+ return fmt.Sprintf(`resource "genesyscloud_routing_skill" "%s" {
+ name = "%s"
+ }
+ `, resourceID, name)
+}
diff --git a/genesyscloud/routing_skill/resource_genesyscloud_routing_skill_schema.go b/genesyscloud/routing_skill/resource_genesyscloud_routing_skill_schema.go
new file mode 100644
index 000000000..d6720c668
--- /dev/null
+++ b/genesyscloud/routing_skill/resource_genesyscloud_routing_skill_schema.go
@@ -0,0 +1,62 @@
+package routing_skill
+
+import (
+ "terraform-provider-genesyscloud/genesyscloud/provider"
+ resourceExporter "terraform-provider-genesyscloud/genesyscloud/resource_exporter"
+ registrar "terraform-provider-genesyscloud/genesyscloud/resource_register"
+
+ "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
+)
+
+const resourceName = "genesyscloud_routing_skill"
+
+func SetRegistrar(regInstance registrar.Registrar) {
+ regInstance.RegisterResource(resourceName, ResourceRoutingSkill())
+ regInstance.RegisterExporter(resourceName, RoutingSkillExporter())
+ regInstance.RegisterDataSource(resourceName, DataSourceRoutingSkill())
+}
+
+// The context is now added without Timeout ,
+// since the warming up of cache will take place for the first Datasource registered during a Terraform Apply.
+func DataSourceRoutingSkill() *schema.Resource {
+ return &schema.Resource{
+ Description: "Data source for Genesys Cloud Routing Skills. Select a skill by name.",
+ ReadWithoutTimeout: provider.ReadWithPooledClient(dataSourceRoutingSkillRead),
+ Schema: map[string]*schema.Schema{
+ "name": {
+ Description: "Skill name.",
+ Type: schema.TypeString,
+ Required: true,
+ },
+ },
+ }
+}
+
+func ResourceRoutingSkill() *schema.Resource {
+ return &schema.Resource{
+ Description: "Genesys Cloud Routing Skill",
+
+ CreateContext: provider.CreateWithPooledClient(createRoutingSkill),
+ ReadContext: provider.ReadWithPooledClient(readRoutingSkill),
+ DeleteContext: provider.DeleteWithPooledClient(deleteRoutingSkill),
+ Importer: &schema.ResourceImporter{
+ StateContext: schema.ImportStatePassthroughContext,
+ },
+ SchemaVersion: 1,
+ Schema: map[string]*schema.Schema{
+ "name": {
+ Description: "Skill name. Changing the name attribute will cause the skill object object to dropped and recreated with a new ID.",
+ Type: schema.TypeString,
+ Required: true,
+ ForceNew: true,
+ },
+ },
+ }
+}
+
+func RoutingSkillExporter() *resourceExporter.ResourceExporter {
+ return &resourceExporter.ResourceExporter{
+ GetResourcesFunc: provider.GetAllWithPooledClient(getAllRoutingSkills),
+ RefAttrs: map[string]*resourceExporter.RefAttrSettings{}, // No references
+ }
+}
diff --git a/genesyscloud/resource_genesyscloud_routing_skill_test.go b/genesyscloud/routing_skill/resource_genesyscloud_routing_skill_test.go
similarity index 98%
rename from genesyscloud/resource_genesyscloud_routing_skill_test.go
rename to genesyscloud/routing_skill/resource_genesyscloud_routing_skill_test.go
index e847a18ff..c715e6b82 100644
--- a/genesyscloud/resource_genesyscloud_routing_skill_test.go
+++ b/genesyscloud/routing_skill/resource_genesyscloud_routing_skill_test.go
@@ -1,4 +1,4 @@
-package genesyscloud
+package routing_skill
import (
"fmt"
diff --git a/genesyscloud/routing_skill_group/data_source_genesyscloud_routing_skill_group.go b/genesyscloud/routing_skill_group/data_source_genesyscloud_routing_skill_group.go
new file mode 100644
index 000000000..141d851d3
--- /dev/null
+++ b/genesyscloud/routing_skill_group/data_source_genesyscloud_routing_skill_group.go
@@ -0,0 +1,32 @@
+package routing_skill_group
+
+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 dataSourceRoutingSkillGroupRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
+ sdkConfig := m.(*provider.ProviderMeta).ClientConfig
+ proxy := getRoutingSkillGroupsProxy(sdkConfig)
+ name := d.Get("name").(string)
+
+ return util.WithRetries(ctx, 15*time.Second, func() *retry.RetryError {
+ skillGroupId, resp, retryable, err := proxy.getRoutingSkillGroupsIdByName(ctx, name)
+ if err != nil && !retryable {
+ return retry.NonRetryableError(util.BuildWithRetriesApiDiagnosticError(resourceName, fmt.Sprintf("Error requesting routing skill group %s | error: %s", name, err), resp))
+ }
+
+ if retryable {
+ return retry.RetryableError(util.BuildWithRetriesApiDiagnosticError(resourceName, fmt.Sprintf("No routing skill group found with name %s", name), resp))
+ }
+ d.SetId(skillGroupId)
+ return nil
+ })
+}
diff --git a/genesyscloud/data_source_genesyscloud_routing_skill_group_test.go b/genesyscloud/routing_skill_group/data_source_genesyscloud_routing_skill_group_test.go
similarity index 94%
rename from genesyscloud/data_source_genesyscloud_routing_skill_group_test.go
rename to genesyscloud/routing_skill_group/data_source_genesyscloud_routing_skill_group_test.go
index 834da4175..14413c397 100644
--- a/genesyscloud/data_source_genesyscloud_routing_skill_group_test.go
+++ b/genesyscloud/routing_skill_group/data_source_genesyscloud_routing_skill_group_test.go
@@ -1,4 +1,4 @@
-package genesyscloud
+package routing_skill_group
import (
"fmt"
@@ -51,5 +51,5 @@ func generateRoutingSkillGroupDataSource(
name = %s
depends_on=[%s]
}
- `, getSkillGroupResourceName(), resourceID, name, dependsOnResource)
+ `, resourceName, resourceID, name, dependsOnResource)
}
diff --git a/genesyscloud/routing_skill_group/genesyscloud_routing_skill_group_init_test.go b/genesyscloud/routing_skill_group/genesyscloud_routing_skill_group_init_test.go
new file mode 100644
index 000000000..a6cb02fe6
--- /dev/null
+++ b/genesyscloud/routing_skill_group/genesyscloud_routing_skill_group_init_test.go
@@ -0,0 +1,59 @@
+package routing_skill_group
+
+import (
+ "sync"
+ "terraform-provider-genesyscloud/genesyscloud"
+ "testing"
+ routingSkill "terraform-provider-genesyscloud/genesyscloud/routing_skill"
+
+ "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
+)
+
+var providerDataSources map[string]*schema.Resource
+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] = ResourceRoutingSkillGroup()
+ providerResources["genesyscloud_auth_division"] = genesyscloud.ResourceAuthDivision()
+ providerResources["genesyscloud_user"] = genesyscloud.ResourceUser()
+ providerResources["genesyscloud_routing_skill"] = routingSkill.ResourceRoutingSkill()
+}
+
+// registerTestDataSources registers all data sources used in the tests.
+func (r *registerTestInstance) registerTestDataSources() {
+ r.datasourceMapMutex.Lock()
+ defer r.datasourceMapMutex.Unlock()
+
+ providerDataSources[resourceName] = DataSourceRoutingSkillGroup()
+ providerDataSources["genesyscloud_auth_division_home"] = genesyscloud.DataSourceAuthDivisionHome()
+
+}
+
+// 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.registerTestDataSources()
+ 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 routing_skill_group package
+ initTestResources()
+
+ // Run the test suite for the routing_skill_group package
+ m.Run()
+}
diff --git a/genesyscloud/routing_skill_group/genesyscloud_routing_skill_group_proxy.go b/genesyscloud/routing_skill_group/genesyscloud_routing_skill_group_proxy.go
new file mode 100644
index 000000000..4352d4e2c
--- /dev/null
+++ b/genesyscloud/routing_skill_group/genesyscloud_routing_skill_group_proxy.go
@@ -0,0 +1,186 @@
+package routing_skill_group
+
+import (
+ "context"
+ "fmt"
+ "log"
+ "terraform-provider-genesyscloud/genesyscloud/util"
+
+ "github.com/mypurecloud/platform-client-sdk-go/v133/platformclientv2"
+)
+
+var internalProxy *routingSkillGroupsProxy
+
+type getAllRoutingSkillGroupsFunc func(ctx context.Context, p *routingSkillGroupsProxy, name string) (*[]platformclientv2.Skillgroupdefinition, *platformclientv2.APIResponse, error)
+type createRoutingSkillGroupsFunc func(ctx context.Context, p *routingSkillGroupsProxy, skillGroupWithMemberDivisions *platformclientv2.Skillgroupwithmemberdivisions) (*platformclientv2.Skillgroupwithmemberdivisions, *platformclientv2.APIResponse, error)
+type getRoutingSkillGroupsByIdFunc func(ctx context.Context, p *routingSkillGroupsProxy, id string) (*platformclientv2.Skillgroup, *platformclientv2.APIResponse, error)
+type getRoutingSkillGroupsIdByNameFunc func(ctx context.Context, p *routingSkillGroupsProxy, name string) (string, *platformclientv2.APIResponse, bool, error)
+type updateRoutingSkillGroupsFunc func(ctx context.Context, p *routingSkillGroupsProxy, id string, skillGroupWithMemberDivisions *platformclientv2.Skillgroup) (*platformclientv2.Skillgroup, *platformclientv2.APIResponse, error)
+type deleteRoutingSkillGroupsFunc func(ctx context.Context, p *routingSkillGroupsProxy, id string) (*platformclientv2.APIResponse, error)
+type createRoutingSkillGroupsMemberDivisionFunc func(ctx context.Context, p *routingSkillGroupsProxy, id string, reqBody platformclientv2.Skillgroupmemberdivisions) (*platformclientv2.APIResponse, error)
+type getRoutingSkillGroupsMemberDivisonFunc func(ctx context.Context, p *routingSkillGroupsProxy, id string) (*platformclientv2.Skillgroupmemberdivisionlist, *platformclientv2.APIResponse, error)
+
+// routingSkillGroupsProxy contains all of the methods that call genesys cloud APIs.
+type routingSkillGroupsProxy struct {
+ clientConfig *platformclientv2.Configuration
+ routingApi *platformclientv2.RoutingApi
+ createRoutingSkillGroupsAttr createRoutingSkillGroupsFunc
+ getAllRoutingSkillGroupsAttr getAllRoutingSkillGroupsFunc
+ getRoutingSkillGroupsIdByNameAttr getRoutingSkillGroupsIdByNameFunc
+ getRoutingSkillGroupsByIdAttr getRoutingSkillGroupsByIdFunc
+ updateRoutingSkillGroupsAttr updateRoutingSkillGroupsFunc
+ deleteRoutingSkillGroupsAttr deleteRoutingSkillGroupsFunc
+ createRoutingSkillGroupsMemberDivisionAttr createRoutingSkillGroupsMemberDivisionFunc
+ getRoutingSkillGroupsMemberDivisonAttr getRoutingSkillGroupsMemberDivisonFunc
+}
+
+// newRoutingSkillGroupsProxy initializes the routing skill groups proxy with all of the data needed to communicate with Genesys Cloud
+func newRoutingSkillGroupsProxy(clientConfig *platformclientv2.Configuration) *routingSkillGroupsProxy {
+ api := platformclientv2.NewRoutingApiWithConfig(clientConfig)
+ return &routingSkillGroupsProxy{
+ clientConfig: clientConfig,
+ routingApi: api,
+ createRoutingSkillGroupsAttr: createRoutingSkillGroupsFn,
+ getAllRoutingSkillGroupsAttr: getAllRoutingSkillGroupsFn,
+ getRoutingSkillGroupsIdByNameAttr: getRoutingSkillGroupsIdByNameFn,
+ getRoutingSkillGroupsByIdAttr: getRoutingSkillGroupsByIdFn,
+ updateRoutingSkillGroupsAttr: updateRoutingSkillGroupsFn,
+ deleteRoutingSkillGroupsAttr: deleteRoutingSkillGroupsFn,
+ createRoutingSkillGroupsMemberDivisionAttr: createRoutingSkillGroupsMemberDivisionFn,
+ getRoutingSkillGroupsMemberDivisonAttr: getRoutingSkillGroupsMemberDivisonFn,
+ }
+}
+
+// getRoutingSkillGroupsProxy 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 getRoutingSkillGroupsProxy(clientConfig *platformclientv2.Configuration) *routingSkillGroupsProxy {
+ if internalProxy == nil {
+ internalProxy = newRoutingSkillGroupsProxy(clientConfig)
+ }
+ return internalProxy
+}
+
+// getRoutingSkillGroups retrieves all Genesys Cloud routing skill groups
+func (p *routingSkillGroupsProxy) getAllRoutingSkillGroups(ctx context.Context, name string) (*[]platformclientv2.Skillgroupdefinition, *platformclientv2.APIResponse, error) {
+ return p.getAllRoutingSkillGroupsAttr(ctx, p, name)
+}
+
+// createRoutingSkillGroups creates a Genesys Cloud routing skill groups
+func (p *routingSkillGroupsProxy) createRoutingSkillGroups(ctx context.Context, routingSkillGroups *platformclientv2.Skillgroupwithmemberdivisions) (*platformclientv2.Skillgroupwithmemberdivisions, *platformclientv2.APIResponse, error) {
+ return p.createRoutingSkillGroupsAttr(ctx, p, routingSkillGroups)
+}
+
+// getRoutingSkillGroupsById returns a single Genesys Cloud routing skill groups by Id
+func (p *routingSkillGroupsProxy) getRoutingSkillGroupsById(ctx context.Context, id string) (*platformclientv2.Skillgroup, *platformclientv2.APIResponse, error) {
+ return p.getRoutingSkillGroupsByIdAttr(ctx, p, id)
+}
+
+// getRoutingSkillGroupsIdByName returns a single Genesys Cloud routing skill groups by a name
+func (p *routingSkillGroupsProxy) getRoutingSkillGroupsIdByName(ctx context.Context, name string) (string, *platformclientv2.APIResponse, bool, error) {
+ return p.getRoutingSkillGroupsIdByNameAttr(ctx, p, name)
+}
+
+// updateRoutingSkillGroups updates a Genesys Cloud routing skill groups
+func (p *routingSkillGroupsProxy) updateRoutingSkillGroups(ctx context.Context, id string, routingSkillGroups *platformclientv2.Skillgroup) (*platformclientv2.Skillgroup, *platformclientv2.APIResponse, error) {
+ return p.updateRoutingSkillGroupsAttr(ctx, p, id, routingSkillGroups)
+}
+
+// deleteRoutingSkillGroups deletes a Genesys Cloud routing skill groups by Id
+func (p *routingSkillGroupsProxy) deleteRoutingSkillGroups(ctx context.Context, id string) (*platformclientv2.APIResponse, error) {
+ return p.deleteRoutingSkillGroupsAttr(ctx, p, id)
+}
+
+func (p *routingSkillGroupsProxy) createRoutingSkillGroupsMemberDivision(ctx context.Context, id string, reqBody platformclientv2.Skillgroupmemberdivisions) (*platformclientv2.APIResponse, error) {
+ return p.createRoutingSkillGroupsMemberDivisionAttr(ctx, p, id, reqBody)
+}
+
+func (p *routingSkillGroupsProxy) getRoutingSkillGroupsMemberDivison(ctx context.Context, id string) (*platformclientv2.Skillgroupmemberdivisionlist, *platformclientv2.APIResponse, error) {
+ return p.getRoutingSkillGroupsMemberDivisonAttr(ctx, p, id)
+}
+
+// getAllRoutingSkillGroupsFn is the implementation for retrieving all routing skill groups in Genesys Cloud
+func getAllRoutingSkillGroupsFn(ctx context.Context, p *routingSkillGroupsProxy, name string) (*[]platformclientv2.Skillgroupdefinition, *platformclientv2.APIResponse, error) {
+ var (
+ allSkillGroups []platformclientv2.Skillgroupdefinition
+ pageSize = 100
+ after string
+ err error
+ response *platformclientv2.APIResponse
+ )
+
+ for i := 0; ; i++ {
+ skillGroups, resp, getErr := p.routingApi.GetRoutingSkillgroups(pageSize, name, after, "")
+ response = resp
+ if getErr != nil {
+ return nil, resp, fmt.Errorf("unable to get routing skill groups %s", getErr)
+ }
+
+ if skillGroups.Entities == nil || len(*skillGroups.Entities) == 0 {
+ break
+ }
+
+ allSkillGroups = append(allSkillGroups, *skillGroups.Entities...)
+
+ if skillGroups.NextUri == nil || *skillGroups.NextUri == "" {
+ break
+ }
+
+ after, err = util.GetQueryParamValueFromUri(*skillGroups.NextUri, "after")
+ if err != nil {
+ return nil, resp, fmt.Errorf("unable to parse after cursor from skill groups next uri: %v", err)
+ }
+ if after == "" {
+ break
+ }
+ }
+ return &allSkillGroups, response, nil
+}
+
+// createRoutingSkillGroupsFn is an implementation function for creating a Genesys Cloud routing skill groups
+func createRoutingSkillGroupsFn(ctx context.Context, p *routingSkillGroupsProxy, routingSkillGroups *platformclientv2.Skillgroupwithmemberdivisions) (*platformclientv2.Skillgroupwithmemberdivisions, *platformclientv2.APIResponse, error) {
+ return p.routingApi.PostRoutingSkillgroups(*routingSkillGroups)
+}
+
+// getRoutingSkillGroupsByIdFn is an implementation of the function to get a Genesys Cloud routing skill groups by Id
+func getRoutingSkillGroupsByIdFn(ctx context.Context, p *routingSkillGroupsProxy, id string) (*platformclientv2.Skillgroup, *platformclientv2.APIResponse, error) {
+ return p.routingApi.GetRoutingSkillgroup(id)
+}
+
+// getRoutingSkillGroupsIdByNameFn is an implementation of the function to get a Genesys Cloud routing skill groups by name
+func getRoutingSkillGroupsIdByNameFn(ctx context.Context, p *routingSkillGroupsProxy, name string) (string, *platformclientv2.APIResponse, bool, error) {
+ skillGroup, resp, err := getAllRoutingSkillGroupsFn(ctx, p, name)
+ if err != nil {
+ return "", resp, false, err
+ }
+
+ if skillGroup == nil || len(*skillGroup) == 0 {
+ return "", resp, true, fmt.Errorf("no skill groups found with name %s", name)
+ }
+
+ for _, skillGroup := range *skillGroup {
+ if *skillGroup.Name == name {
+ log.Printf("Retrieved the routing skill groups id %s by name %s", *skillGroup.Id, name)
+ return *skillGroup.Id, resp, false, nil
+ }
+ }
+
+ return "", resp, true, fmt.Errorf("unable to find routing skill groups with name %s", name)
+}
+
+// updateRoutingSkillGroupsFn is an implementation of the function to update a Genesys Cloud routing skill groups
+func updateRoutingSkillGroupsFn(ctx context.Context, p *routingSkillGroupsProxy, id string, routingSkillGroups *platformclientv2.Skillgroup) (*platformclientv2.Skillgroup, *platformclientv2.APIResponse, error) {
+ return p.routingApi.PatchRoutingSkillgroup(id, *routingSkillGroups)
+}
+
+// deleteRoutingSkillGroupsFn is an implementation function for deleting a Genesys Cloud routing skill groups
+func deleteRoutingSkillGroupsFn(ctx context.Context, p *routingSkillGroupsProxy, id string) (*platformclientv2.APIResponse, error) {
+ return p.routingApi.DeleteRoutingSkillgroup(id)
+}
+
+func createRoutingSkillGroupsMemberDivisionFn(ctx context.Context, p *routingSkillGroupsProxy, id string, reqBody platformclientv2.Skillgroupmemberdivisions) (*platformclientv2.APIResponse, error) {
+ return p.routingApi.PostRoutingSkillgroupMembersDivisions(id, reqBody)
+}
+
+func getRoutingSkillGroupsMemberDivisonFn(ctx context.Context, p *routingSkillGroupsProxy, id string) (*platformclientv2.Skillgroupmemberdivisionlist, *platformclientv2.APIResponse, error) {
+ return p.routingApi.GetRoutingSkillgroupMembersDivisions(id, "")
+}
diff --git a/genesyscloud/routing_skill_group/resource_genesyscloud_routing_skill_group.go b/genesyscloud/routing_skill_group/resource_genesyscloud_routing_skill_group.go
new file mode 100644
index 000000000..72020ec39
--- /dev/null
+++ b/genesyscloud/routing_skill_group/resource_genesyscloud_routing_skill_group.go
@@ -0,0 +1,300 @@
+package routing_skill_group
+
+import (
+ "context"
+ "encoding/json"
+ "fmt"
+ "log"
+ "terraform-provider-genesyscloud/genesyscloud/provider"
+ "terraform-provider-genesyscloud/genesyscloud/util"
+ "terraform-provider-genesyscloud/genesyscloud/util/constants"
+ "terraform-provider-genesyscloud/genesyscloud/util/resourcedata"
+ "time"
+
+ "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
+
+ "terraform-provider-genesyscloud/genesyscloud/consistency_checker"
+
+ resourceExporter "terraform-provider-genesyscloud/genesyscloud/resource_exporter"
+ lists "terraform-provider-genesyscloud/genesyscloud/util/lists"
+
+ "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"
+)
+
+func getAllRoutingSkillGroups(ctx context.Context, clientConfig *platformclientv2.Configuration) (resourceExporter.ResourceIDMetaMap, diag.Diagnostics) {
+ proxy := getRoutingSkillGroupsProxy(clientConfig)
+ resources := make(resourceExporter.ResourceIDMetaMap)
+
+ allSkillGroups, resp, err := proxy.getAllRoutingSkillGroups(ctx, "")
+ if err != nil {
+ return nil, util.BuildAPIDiagnosticError(resourceName, fmt.Sprintf("Failed to get routing skill groups: %v", err), resp)
+ }
+
+ for _, skillGroup := range *allSkillGroups {
+ resources[*skillGroup.Id] = &resourceExporter.ResourceMeta{Name: *skillGroup.Name}
+ }
+
+ return resources, nil
+}
+
+func createSkillGroups(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
+ sdkConfig := meta.(*provider.ProviderMeta).ClientConfig
+ proxy := getRoutingSkillGroupsProxy(sdkConfig)
+ name := d.Get("name").(string)
+ description := d.Get("description").(string)
+
+ createRequestBody := platformclientv2.Skillgroupwithmemberdivisions{
+ Name: &name,
+ Description: &description,
+ }
+
+ if divisionID := d.Get("division_id").(string); divisionID != "" {
+ createRequestBody.Division = &platformclientv2.Writabledivision{Id: &divisionID}
+ }
+
+ if skillConditions := d.Get("skill_conditions").(string); skillConditions != "" {
+ if err := json.Unmarshal([]byte(skillConditions), &createRequestBody.SkillConditions); err != nil {
+ return util.BuildDiagnosticError(resourceName, fmt.Sprintf("Failed to unmarshal the JSON skill conditions while creating the skills group %v", &createRequestBody.Name), err)
+ }
+ }
+
+ group, response, err := proxy.createRoutingSkillGroups(ctx, &createRequestBody)
+ if err != nil {
+ return util.BuildAPIDiagnosticError(resourceName, fmt.Sprintf("Failed to create skill groups %v error: %s", &createRequestBody.Name, err), response)
+ }
+
+ d.SetId(*group.Id)
+ log.Printf("Created skill group %v %v", &createRequestBody.Name, group.Id)
+
+ // Update member division IDs
+ if diagErr := assignMemberDivisionIds(ctx, d, meta, true); diagErr != nil {
+ return diagErr
+ }
+
+ return readSkillGroups(ctx, d, meta)
+}
+
+func readSkillGroups(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
+ sdkConfig := meta.(*provider.ProviderMeta).ClientConfig
+ proxy := getRoutingSkillGroupsProxy(sdkConfig)
+ cc := consistency_checker.NewConsistencyCheck(ctx, d, meta, ResourceRoutingSkillGroup(), constants.DefaultConsistencyChecks, resourceName)
+
+ log.Printf("Reading skills group %s", d.Id())
+
+ return util.WithRetriesForRead(ctx, d, func() *retry.RetryError {
+ skillGroup, resp, err := proxy.getRoutingSkillGroupsById(ctx, d.Id())
+ if err != nil {
+ if util.IsStatus404(resp) {
+ return retry.RetryableError(util.BuildWithRetriesApiDiagnosticError(resourceName, fmt.Sprintf("Failed to read skill groups %s | error: %s", d.Id(), err), resp))
+ }
+ return retry.RetryableError(util.BuildWithRetriesApiDiagnosticError(resourceName, fmt.Sprintf("Failed to read skill groups %s | error: %s", d.Id(), err), resp))
+ }
+
+ resourcedata.SetNillableValue(d, "name", skillGroup.Name)
+ resourcedata.SetNillableValue(d, "description", skillGroup.Description)
+ resourcedata.SetNillableReferenceWritableDivision(d, "division_id", skillGroup.Division)
+
+ skillConditionsBytes, _ := json.Marshal(skillGroup.SkillConditions)
+ skillConditions := string(skillConditionsBytes)
+ if skillConditions != "" {
+ _ = d.Set("skill_conditions", skillConditions)
+ } else {
+ _ = d.Set("skill_conditions", nil)
+ }
+
+ // Set member_division_ids avoiding plan not empty error
+ memberDivIds, diagErr := readSkillGroupMemberDivisions(ctx, d, meta)
+ if diagErr != nil {
+ return retry.NonRetryableError(fmt.Errorf("%v", diagErr))
+ }
+
+ var schemaMemberDivisionIds []string
+ if divIds, ok := d.Get("member_division_ids").([]interface{}); ok {
+ schemaMemberDivisionIds = lists.InterfaceListToStrings(divIds)
+ }
+
+ memberDivisionIds := organizeMemberDivisionIdsForRead(schemaMemberDivisionIds, memberDivIds, *skillGroup.Division.Id)
+ _ = d.Set("member_division_ids", memberDivisionIds)
+
+ log.Printf("Read skill groups name %s %s", d.Id(), *skillGroup.Name)
+ return cc.CheckState(d)
+ })
+}
+
+
+func updateSkillGroups(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
+ sdkConfig := meta.(*provider.ProviderMeta).ClientConfig
+ proxy := getRoutingSkillGroupsProxy(sdkConfig)
+ name := d.Get("name").(string)
+ description := d.Get("description").(string)
+
+ updateRequestBody := platformclientv2.Skillgroup{
+ Name: &name,
+ Description: &description,
+ }
+
+ if divisionID := d.Get("division_id").(string); divisionID != "" {
+ updateRequestBody.Division = &platformclientv2.Writabledivision{Id: &divisionID}
+ }
+
+ if SkillConditions := d.Get("skill_conditions").(string); SkillConditions != "" {
+ if err := json.Unmarshal([]byte(SkillConditions), &updateRequestBody.SkillConditions); err != nil {
+ return util.BuildDiagnosticError(resourceName, fmt.Sprintf("Failed to unmarshal the JSON skill conditions while updating the skills group %v", &updateRequestBody.Name), err)
+ }
+ }
+
+ group, resp, err := proxy.updateRoutingSkillGroups(ctx, d.Id(), &updateRequestBody)
+ if err != nil {
+ return util.BuildAPIDiagnosticError(resourceName, fmt.Sprintf("Failed to update skill groups %v error: %s", &updateRequestBody.Name, err), resp)
+ }
+
+ log.Printf("Updated skill group %v", &group.Name)
+
+ // Update member division IDs
+ if diagErr := assignMemberDivisionIds(ctx, d, meta, false); diagErr != nil {
+ return diagErr
+ }
+
+ return readSkillGroups(ctx, d, meta)
+}
+
+func deleteSkillGroups(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
+ sdkConfig := meta.(*provider.ProviderMeta).ClientConfig
+ proxy := getRoutingSkillGroupsProxy(sdkConfig)
+
+ log.Printf("Deleting skill group %s", d.Id())
+ resp, err := proxy.deleteRoutingSkillGroups(ctx, d.Id())
+ if err != nil {
+ return util.BuildAPIDiagnosticError(resourceName, fmt.Sprintf("Failed to delete skill group %s error: %s", d.Id(), err), resp)
+ }
+
+ return util.WithRetries(ctx, 30*time.Second, func() *retry.RetryError {
+ _, resp, err := proxy.getRoutingSkillGroupsById(ctx, d.Id())
+ if err != nil {
+ if util.IsStatus404(resp) {
+ log.Printf("Deleted skills group %s", d.Id())
+ return nil
+ }
+ return retry.NonRetryableError(util.BuildWithRetriesApiDiagnosticError(resourceName, fmt.Sprintf("Error deleting skill group %s | error: %s", d.Id(), err), resp))
+ }
+ return retry.RetryableError(util.BuildWithRetriesApiDiagnosticError(resourceName, fmt.Sprintf("Skill group %s still exists", d.Id()), resp))
+ })
+}
+
+func createRoutingSkillGroupsMemberDivisions(ctx context.Context, d *schema.ResourceData, meta interface{}, skillGroupDivisionIds []string, create bool) diag.Diagnostics {
+ sdkConfig := meta.(*provider.ProviderMeta).ClientConfig
+ proxy := getRoutingSkillGroupsProxy(sdkConfig)
+ memberDivIds := d.Get("member_division_ids").([]interface{})
+ var reqBody platformclientv2.Skillgroupmemberdivisions
+
+ if memberDivIds == nil {
+ return readSkillGroups(ctx, d, meta)
+ }
+ schemaDivisionIds := lists.InterfaceListToStrings(memberDivIds)
+
+ toAdd, toRemove, diagErr := createListsForSkillgroupsMembersDivisions(schemaDivisionIds, skillGroupDivisionIds, create, meta)
+ if diagErr != nil {
+ return diagErr
+ }
+
+ toRemove, diagErr = removeSkillGroupDivisionID(d, toRemove)
+ if diagErr != nil {
+ return diagErr
+ }
+
+ if len(toAdd) < 1 && len(toRemove) < 1 {
+ return readSkillGroups(ctx, d, meta)
+ }
+
+ log.Printf("Updating skill group %s member divisions", d.Id())
+
+ if len(toRemove) > 0 {
+ reqBody.RemoveDivisionIds = &toRemove
+ }
+ if len(toAdd) > 0 {
+ reqBody.AddDivisionIds = &toAdd
+ }
+
+ resp, err := proxy.createRoutingSkillGroupsMemberDivision(ctx, d.Id(), reqBody)
+ if err != nil {
+ return util.BuildAPIDiagnosticError(resourceName, fmt.Sprintf("Failed to update skill group %s member divisions error: %s", d.Id(), err), resp)
+ }
+
+ log.Printf("Updated skill group %s member divisions", d.Id())
+ return nil
+}
+
+func readSkillGroupMemberDivisions(ctx context.Context, d *schema.ResourceData, meta interface{}) ([]string, diag.Diagnostics) {
+ sdkConfig := meta.(*provider.ProviderMeta).ClientConfig
+ proxy := getRoutingSkillGroupsProxy(sdkConfig)
+
+ log.Printf("Reading skill group %s member divisions", d.Get("name").(string))
+
+ memberDivisions, resp, err := proxy.getRoutingSkillGroupsMemberDivison(ctx, d.Id())
+ if err != nil {
+ return nil, util.BuildAPIDiagnosticError(resourceName, fmt.Sprintf("Failed to get member divisions for skill group %s error: %s", d.Id(), err), resp)
+ }
+
+ skillGroupMemberDivisionIds := make([]string, 0)
+ for _, division := range *memberDivisions.Entities {
+ skillGroupMemberDivisionIds = append(skillGroupMemberDivisionIds, *division.Id)
+ }
+
+ log.Printf("Read skill group %s member divisions", d.Get("name").(string))
+
+ return skillGroupMemberDivisionIds, nil
+}
+
+func GenerateRoutingSkillGroupResourceBasic(
+ resourceID string,
+ name string,
+ description string) string {
+ return fmt.Sprintf(`resource "%s" "%s" {
+ name = "%s"
+ description="%s"
+ }
+ `, resourceName, resourceID, name, description)
+}
+
+// Todo: remove once auth divisions is refactored into its own package
+
+func getAllAuthDivisionIds(meta interface{}) ([]string, diag.Diagnostics) {
+ sdkConfig := meta.(*provider.ProviderMeta).ClientConfig
+ allIds := make([]string, 0)
+
+ divisionResourcesMap, err := getAllAuthDivisions(nil, sdkConfig)
+ if err != nil {
+ return nil, err
+ }
+
+ for key, _ := range divisionResourcesMap {
+ allIds = append(allIds, key)
+ }
+
+ return allIds, nil
+}
+
+func getAllAuthDivisions(_ context.Context, clientConfig *platformclientv2.Configuration) (resourceExporter.ResourceIDMetaMap, diag.Diagnostics) {
+ resources := make(resourceExporter.ResourceIDMetaMap)
+ authAPI := platformclientv2.NewAuthorizationApiWithConfig(clientConfig)
+
+ for pageNum := 1; ; pageNum++ {
+ const pageSize = 100
+ divisions, resp, getErr := authAPI.GetAuthorizationDivisions(pageSize, pageNum, "", nil, "", "", false, nil, "")
+ if getErr != nil {
+ return nil, util.BuildAPIDiagnosticError("genesyscloud_auth_division", fmt.Sprintf("Failed to get page of divisions error: %s", getErr), resp)
+ }
+
+ if divisions.Entities == nil || len(*divisions.Entities) == 0 {
+ break
+ }
+
+ for _, division := range *divisions.Entities {
+ resources[*division.Id] = &resourceExporter.ResourceMeta{Name: *division.Name}
+ }
+ }
+
+ return resources, nil
+}
diff --git a/genesyscloud/routing_skill_group/resource_genesyscloud_routing_skill_group_schema.go b/genesyscloud/routing_skill_group/resource_genesyscloud_routing_skill_group_schema.go
new file mode 100644
index 000000000..ab3b7cd0d
--- /dev/null
+++ b/genesyscloud/routing_skill_group/resource_genesyscloud_routing_skill_group_schema.go
@@ -0,0 +1,94 @@
+package routing_skill_group
+
+import (
+ "terraform-provider-genesyscloud/genesyscloud/provider"
+ resourceExporter "terraform-provider-genesyscloud/genesyscloud/resource_exporter"
+ registrar "terraform-provider-genesyscloud/genesyscloud/resource_register"
+ "terraform-provider-genesyscloud/genesyscloud/util"
+
+ "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
+)
+
+const resourceName = "genesyscloud_routing_skill_group"
+
+// SetRegistrar registers all the resources and exporters in the package
+func SetRegistrar(regInstance registrar.Registrar) {
+ regInstance.RegisterResource(resourceName, ResourceRoutingSkillGroup())
+ regInstance.RegisterDataSource(resourceName, DataSourceRoutingSkillGroup())
+ regInstance.RegisterExporter(resourceName, ResourceSkillGroupExporter())
+}
+
+func ResourceRoutingSkillGroup() *schema.Resource {
+ return &schema.Resource{
+ Description: `Genesys Cloud Skill Group`,
+
+ CreateContext: provider.CreateWithPooledClient(createSkillGroups),
+ ReadContext: provider.ReadWithPooledClient(readSkillGroups),
+ UpdateContext: provider.UpdateWithPooledClient(updateSkillGroups),
+ DeleteContext: provider.DeleteWithPooledClient(deleteSkillGroups),
+ Importer: &schema.ResourceImporter{
+ StateContext: schema.ImportStatePassthroughContext,
+ },
+ SchemaVersion: 1,
+ Schema: map[string]*schema.Schema{
+ "name": {
+ Description: "The group name",
+ Type: schema.TypeString,
+ Required: true,
+ },
+ "description": {
+ Description: "Description of the skill group",
+ Type: schema.TypeString,
+ Optional: true,
+ },
+ "division_id": {
+ Description: "The division to which this entity belongs",
+ Type: schema.TypeString,
+ Optional: true,
+ Computed: true,
+ },
+ "skill_conditions": {
+ Description: "JSON encoded array of rules that will be used to determine group membership.",
+ Type: schema.TypeString,
+ Optional: true,
+ Computed: true,
+ DiffSuppressFunc: util.SuppressEquivalentJsonDiffs,
+ },
+ "member_division_ids": {
+ Description: "The IDs of member divisions to add or remove for this skill group. An empty array means all divisions will be removed, '*' means all divisions will be added.",
+ Type: schema.TypeList,
+ MaxItems: 50,
+ Optional: true,
+ Elem: &schema.Schema{Type: schema.TypeString},
+ },
+ },
+ }
+}
+
+func DataSourceRoutingSkillGroup() *schema.Resource {
+ return &schema.Resource{
+ Description: "Data source for Genesys Cloud Routing Skills Groups. Select a skill group by name.",
+ ReadContext: provider.ReadWithPooledClient(dataSourceRoutingSkillGroupRead),
+ Schema: map[string]*schema.Schema{
+ "name": {
+ Description: "Skill group name.",
+ Type: schema.TypeString,
+ Required: true,
+ },
+ },
+ }
+}
+
+func ResourceSkillGroupExporter() *resourceExporter.ResourceExporter {
+ return &resourceExporter.ResourceExporter{
+ GetResourcesFunc: provider.GetAllWithPooledClient(getAllRoutingSkillGroups),
+ RefAttrs: map[string]*resourceExporter.RefAttrSettings{
+ "division_id": {RefType: "genesyscloud_auth_division"},
+ "member_division_ids": {RefType: "genesyscloud_auth_division"},
+ },
+ RemoveIfMissing: map[string][]string{
+ "division_id": {"division_id"},
+ },
+ JsonEncodeAttributes: []string{"skill_conditions"},
+ }
+}
diff --git a/genesyscloud/resource_genesyscloud_routing_skill_group_test.go b/genesyscloud/routing_skill_group/resource_genesyscloud_routing_skill_group_test.go
similarity index 85%
rename from genesyscloud/resource_genesyscloud_routing_skill_group_test.go
rename to genesyscloud/routing_skill_group/resource_genesyscloud_routing_skill_group_test.go
index 95b1bd51d..88a8cee9f 100644
--- a/genesyscloud/resource_genesyscloud_routing_skill_group_test.go
+++ b/genesyscloud/routing_skill_group/resource_genesyscloud_routing_skill_group_test.go
@@ -1,4 +1,4 @@
-package genesyscloud
+package routing_skill_group
import (
"encoding/json"
@@ -6,12 +6,14 @@ import (
"log"
"os"
"strings"
+ gcloud "terraform-provider-genesyscloud/genesyscloud"
"terraform-provider-genesyscloud/genesyscloud/provider"
"terraform-provider-genesyscloud/genesyscloud/util"
"testing"
"time"
lists "terraform-provider-genesyscloud/genesyscloud/util/lists"
+ routingSkill "terraform-provider-genesyscloud/genesyscloud/routing_skill"
"github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
@@ -219,11 +221,11 @@ func TestAccResourceRoutingSkillGroupMemberDivisionsBasic(t *testing.T) {
authDivision1Name := "TF Division " + uuid.NewString()
authDivision1Resource := "division1"
- authDivision1 := GenerateAuthDivisionBasic(authDivision1Resource, authDivision1Name)
+ authDivision1 := gcloud.GenerateAuthDivisionBasic(authDivision1Resource, authDivision1Name)
authDivision2Name := "TF Division " + uuid.NewString()
authDivision2Resource := "division2"
- authDivision2 := GenerateAuthDivisionBasic(authDivision2Resource, authDivision2Name)
+ authDivision2 := gcloud.GenerateAuthDivisionBasic(authDivision2Resource, authDivision2Name)
memberDivisionIds1 := fmt.Sprintf(`[%s]`, strings.Join([]string{"data.genesyscloud_auth_division_home.home.id"}, ", "))
@@ -412,9 +414,9 @@ func TestAccResourceRoutingSkillGroupMemberDivisionsUsersAssigned(t *testing.T)
division1ResourceId = "division_1"
division2ResourceId = "division_2"
division3ResourceId = "division_3"
- division1Name = "tf test division " + uuid.NewString()
- division2Name = "tf test division " + uuid.NewString()
- division3Name = "tf test division " + uuid.NewString()
+ division1Name = "tf test divisionB " + uuid.NewString()
+ division2Name = "tf test divisionB " + uuid.NewString()
+ division3Name = "tf test divisionB " + uuid.NewString()
memberDivisionIds = []string{
"genesyscloud_auth_division." + division1ResourceId + ".id",
@@ -423,11 +425,11 @@ func TestAccResourceRoutingSkillGroupMemberDivisionsUsersAssigned(t *testing.T)
}
)
- routingSkillResource := GenerateRoutingSkillResource(routingSkillResourceId, routingSkillName)
+ routingSkillResource := routingSkill.GenerateRoutingSkillResource(routingSkillResourceId, routingSkillName)
- division1Resource := GenerateAuthDivisionBasic(division1ResourceId, division1Name)
- division2Resource := GenerateAuthDivisionBasic(division2ResourceId, division2Name)
- division3Resource := GenerateAuthDivisionBasic(division3ResourceId, division3Name)
+ division1Resource := gcloud.GenerateAuthDivisionBasic(division1ResourceId, division1Name)
+ division2Resource := gcloud.GenerateAuthDivisionBasic(division2ResourceId, division2Name)
+ division3Resource := gcloud.GenerateAuthDivisionBasic(division3ResourceId, division3Name)
user1Resource := fmt.Sprintf(`
resource "genesyscloud_user" "%s" {
@@ -438,7 +440,7 @@ resource "genesyscloud_user" "%s" {
skill_id = genesyscloud_routing_skill.%s.id
proficiency = 2.5
}
-}
+}
`, user1ResourceId, user1Name, user1email, division1ResourceId, routingSkillResourceId)
user2Resource := fmt.Sprintf(`
@@ -450,7 +452,7 @@ resource "genesyscloud_user" "%s" {
skill_id = genesyscloud_routing_skill.%s.id
proficiency = 2.5
}
-}
+}
`, user2ResourceId, user2Name, user2email, division2ResourceId, routingSkillResourceId)
user3Resource := fmt.Sprintf(`
@@ -462,7 +464,7 @@ resource "genesyscloud_user" "%s" {
skill_id = genesyscloud_routing_skill.%s.id
proficiency = 2.5
}
-}
+}
`, user3ResourceId, user3Name, user3email, division3ResourceId, routingSkillResourceId)
skillGroupResource := fmt.Sprintf(`
@@ -491,7 +493,7 @@ resource "genesyscloud_routing_skill_group" "%s" {
)
depends_on = [genesyscloud_user.%s, genesyscloud_user.%s, genesyscloud_user.%s ]
-}
+}
`, skillGroupResourceId, skillGroupName, strings.Join(memberDivisionIds, ", "),
skillGroupDescription, routingSkillName, user1ResourceId, user2ResourceId, user3ResourceId)
@@ -512,7 +514,7 @@ resource "genesyscloud_routing_skill_group" "%s" {
user2Resource +
user3Resource,
Check: resource.ComposeTestCheckFunc(
- testVerifySkillGroupMemberCount("genesyscloud_routing_skill_group."+skillGroupResourceId, "3"),
+ testVerifySkillGroupMemberCount("genesyscloud_routing_skill_group."+skillGroupResourceId, 3),
),
},
{
@@ -523,7 +525,7 @@ resource "genesyscloud_routing_skill_group" "%s" {
Destroy: true,
},
},
- CheckDestroy: testVerifySkillGroupDestroyed,
+ CheckDestroy: testVerifySkillGroupAndUsersDestroyed,
})
}
@@ -541,23 +543,12 @@ func generateRoutingSkillGroupResource(
description="%s"
division_id=%s
skill_conditions = jsonencode(%s)
- member_division_ids = %s
+ member_division_ids = %s
}
`, resourceID, divisionResourceName, name, description, divisionID, skillCondition, memberDivisionIds)
}
-func generateRoutingSkillGroupResourceBasic(
- resourceID string,
- name string,
- description string) string {
- return fmt.Sprintf(`resource "genesyscloud_routing_skill_group" "%s" {
- name = "%s"
- description="%s"
- }
- `, resourceID, name, description)
-}
-
-func testVerifySkillGroupMemberCount(resourceName string, count string) resource.TestCheckFunc {
+func testVerifySkillGroupMemberCount(resourceName string, count int) resource.TestCheckFunc {
return func(state *terraform.State) error {
// Authorize client credentials
config, err := provider.AuthorizeSdk()
@@ -576,24 +567,13 @@ func testVerifySkillGroupMemberCount(resourceName string, count string) resource
time.Sleep(10 * time.Second)
// get skill group via GET /api/v2/routing/skillgroups/{skillGroupId}
- path := fmt.Sprintf("%s/api/v2/routing/skillgroups/%s", routingAPI.Configuration.BasePath, resourceID)
- headers := BuildHeaderParams(routingAPI)
- apiClient := &routingAPI.Configuration.APIClient
-
- response, err := apiClient.CallAPI(path, "GET", nil, headers, nil, nil, "", nil)
- if err != nil || response.Error != nil {
- return fmt.Errorf("Failed to get skill group %s: %v", resourceID, err)
- }
-
- skillGroupPayload := make(map[string]interface{}, 0)
- err = json.Unmarshal(response.RawBody, &skillGroupPayload)
+ skillGroup, resp, err := routingAPI.GetRoutingSkillgroup(resourceID)
if err != nil {
- return fmt.Errorf("Failed to unmarshal skill group %s: %s", resourceID, err)
+ return fmt.Errorf("Failed to get skill group %s: %v %s", resourceID, err, resp)
}
- memberCount := skillGroupPayload["memberCount"]
- if fmt.Sprintf("%v", memberCount) != count {
- return fmt.Errorf("Expected member count to be %s, got %v for skill group %s", count, memberCount, resourceID)
+ if *skillGroup.MemberCount != count {
+ return fmt.Errorf("Expected member count to be %v, got %v for skill group %s", count, *skillGroup.MemberCount, resourceID)
}
return nil
}
@@ -700,70 +680,52 @@ func testVerifyAllDivisionsAssigned(resourceName string, attrName string) resour
func testVerifySkillGroupDestroyed(state *terraform.State) error {
// Get default config to set config options
-
- routingAPI := platformclientv2.NewRoutingApiWithConfig(sdkConfig)
- apiClient := &routingAPI.Configuration.APIClient
-
- // TODO Once this code has been released into the public API we should fix this and use the SDK
-
- headerParams := BuildHeaderParams(routingAPI)
+ config, err := provider.AuthorizeSdk()
+ if err != nil {
+ return fmt.Errorf("unexpected error while trying to authorize client in testVerifySkillGroupDestroyed : %s", err)
+ }
+ routingAPI := platformclientv2.NewRoutingApiWithConfig(config)
for _, rs := range state.RootModule().Resources {
if rs.Type != "genesyscloud_routing_skill_group" {
continue
}
- path := routingAPI.Configuration.BasePath + "/api/v2/routing/skillgroups/" + rs.Primary.ID
- response, err := apiClient.CallAPI(path, "GET", nil, headerParams, nil, nil, "", nil)
-
- skillGroupPayload := make(map[string]interface{})
-
- if err != nil {
- if util.IsStatus404(response) {
- break
- }
-
- return fmt.Errorf("Unexpected error while trying to read skillgroup: %s", err)
- }
-
- json.Unmarshal(response.RawBody, &skillGroupPayload)
+ skillGroup, resp, err := routingAPI.GetRoutingSkillgroup(rs.Primary.ID)
- if skillGroupPayload["id"] != nil && skillGroupPayload["id"] != "" {
+ if skillGroup != nil {
return fmt.Errorf("Skill Group (%s) still exists", rs.Primary.ID)
+ } else if util.IsStatus404(resp) {
+ // Division not found as expected
+ continue
+ } else {
+ // Unexpected error
+ return fmt.Errorf("Unexpected error: %s", err)
}
-
}
// Success. All skills destroyed
return nil
}
func testVerifySkillGroupAndUsersDestroyed(state *terraform.State) error {
+ config, err := provider.AuthorizeSdk()
+ if err != nil {
+ return fmt.Errorf("unexpected error while trying to authorize client in testVerifySkillGroupDestroyed : %s", err)
+ }
+ routingAPI := platformclientv2.NewRoutingApiWithConfig(config)
+ usersAPI := platformclientv2.NewUsersApiWithConfig(config)
- routingAPI := platformclientv2.NewRoutingApiWithConfig(sdkConfig)
- apiClient := &routingAPI.Configuration.APIClient
- usersAPI := platformclientv2.NewUsersApiWithConfig(sdkConfig)
- // TODO Once this code has been released into the public API we should fix this and use the SDK
-
- headerParams := BuildHeaderParams(routingAPI)
for _, rs := range state.RootModule().Resources {
if rs.Type == "genesyscloud_routing_skill_group" {
- path := routingAPI.Configuration.BasePath + "/api/v2/routing/skillgroups/" + rs.Primary.ID
- response, err := apiClient.CallAPI(path, "GET", nil, headerParams, nil, nil, "", nil)
+ group, response, err := routingAPI.GetRoutingSkillgroup(rs.Primary.ID)
- skillGroupPayload := make(map[string]interface{})
-
- if err != nil {
- if util.IsStatus404(response) {
- break
- }
-
- return fmt.Errorf("Unexpected error while trying to read skillgroup: %s", err)
+ if group != nil {
+ return fmt.Errorf("team (%s) still exists", rs.Primary.ID)
}
-
- json.Unmarshal(response.RawBody, &skillGroupPayload)
-
- if skillGroupPayload["id"] != nil && skillGroupPayload["id"] != "" {
- return fmt.Errorf("Skill Group (%s) still exists", rs.Primary.ID)
+ if util.IsStatus404(response) {
+ continue
}
+ return fmt.Errorf("Unexpected error: %s", err)
}
+
if rs.Type == "genesyscloud_user" {
err := checkUserDeleted(rs.Primary.ID)(state)
if err != nil {
@@ -773,10 +735,8 @@ func testVerifySkillGroupAndUsersDestroyed(state *terraform.State) error {
if user != nil {
return fmt.Errorf("User Resource (%s) still exists", rs.Primary.ID)
} else if util.IsStatus404(resp) {
- // User not found as expected
continue
} else {
- // Unexpected error
return fmt.Errorf("Unexpected error: %s", err)
}
}
@@ -785,26 +745,19 @@ func testVerifySkillGroupAndUsersDestroyed(state *terraform.State) error {
return nil
}
func getAllSkillGroupMemberDivisionIds(routingAPI *platformclientv2.RoutingApi, resourceId string) ([]string, diag.Diagnostics) {
- headers := BuildHeaderParams(routingAPI)
- apiClient := &routingAPI.Configuration.APIClient
- path := fmt.Sprintf("%s/api/v2/routing/skillgroups/%s/members/divisions", routingAPI.Configuration.BasePath, resourceId)
- response, err := apiClient.CallAPI(path, "GET", nil, headers, nil, nil, "", nil)
- if err != nil || response.Error != nil {
- return nil, util.BuildAPIDiagnosticError("genesyscloud_routing_skill_group", fmt.Sprintf("Failed to update Routing Utilization %s error: %s", resourceId, err), response)
- }
+ sdkconfig, _ := provider.AuthorizeSdk()
+ api := platformclientv2.NewRoutingApiWithConfig(sdkconfig)
+
+ divisions, resp, err := api.GetRoutingSkillgroupMembersDivisions(resourceId, "")
- memberDivisionsPayload := make(map[string]interface{}, 0)
- err = json.Unmarshal(response.RawBody, &memberDivisionsPayload)
if err != nil {
- return nil, util.BuildDiagnosticError("genesyscloud_routing_skill_group", fmt.Sprintf("Failed to unmarshal member divisions"), err)
+ return nil, util.BuildAPIDiagnosticError("genesyscloud_routing_skill_group", fmt.Sprintf("Failed to update Routing Utilization %s error: %s", resourceId, err), resp)
}
apiSkillGroupMemberDivisionIds := make([]string, 0)
- entities := memberDivisionsPayload["entities"].([]interface{})
- for _, entity := range entities {
- if entityMap, ok := entity.(map[string]interface{}); ok {
- apiSkillGroupMemberDivisionIds = append(apiSkillGroupMemberDivisionIds, entityMap["id"].(string))
- }
+ for _, entity := range *divisions.Entities {
+ apiSkillGroupMemberDivisionIds = append(apiSkillGroupMemberDivisionIds, *entity.Id)
+
}
return apiSkillGroupMemberDivisionIds, nil
@@ -830,10 +783,8 @@ func checkUserDeleted(id string) resource.TestCheckFunc {
}
func isUserDeleted(id string) (bool, error) {
- mu.Lock()
- defer mu.Unlock()
-
- usersAPI := platformclientv2.NewUsersApi()
+ sdkConfig, _ := provider.AuthorizeSdk()
+ usersAPI := platformclientv2.NewUsersApiWithConfig(sdkConfig)
// Attempt to get the user
_, response, err := usersAPI.GetUser(id, nil, "", "")
diff --git a/genesyscloud/routing_skill_group/resource_genesyscloud_routing_skill_group_utils.go b/genesyscloud/routing_skill_group/resource_genesyscloud_routing_skill_group_utils.go
new file mode 100644
index 000000000..b41412800
--- /dev/null
+++ b/genesyscloud/routing_skill_group/resource_genesyscloud_routing_skill_group_utils.go
@@ -0,0 +1,121 @@
+package routing_skill_group
+
+import (
+ "context"
+ "fmt"
+ "log"
+ "terraform-provider-genesyscloud/genesyscloud/util"
+ lists "terraform-provider-genesyscloud/genesyscloud/util/lists"
+
+ "github.com/hashicorp/terraform-plugin-sdk/v2/diag"
+ "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
+)
+
+// Prepare member_division_ids list to avoid an unnecessary plan not empty error
+func organizeMemberDivisionIdsForUpdate(schemaIds, apiIds []string) ([]string, []string) {
+ toAdd := make([]string, 0)
+ toRemove := make([]string, 0)
+ // items that are in hcl and not in api-returned list - add
+ for _, id := range schemaIds {
+ if !lists.ItemInSlice(id, apiIds) {
+ toAdd = append(toAdd, id)
+ }
+ }
+ // items that are not in hcl and are in api-returned list - remove
+ for _, id := range apiIds {
+ if !lists.ItemInSlice(id, schemaIds) {
+ toRemove = append(toRemove, id)
+ }
+ }
+ return toAdd, toRemove
+}
+
+// Prepare member_division_ids list to avoid an unnecessary plan not empty error
+func organizeMemberDivisionIdsForRead(schemaList, apiList []string, divisionId string) []string {
+ if !lists.ItemInSlice(divisionId, schemaList) {
+ apiList = lists.RemoveStringFromSlice(divisionId, apiList)
+ }
+ if len(schemaList) == 1 && schemaList[0] == "*" {
+ return schemaList
+ } else {
+ // if hcl & api lists are the same but with different ordering - set with original ordering
+ if lists.AreEquivalent(schemaList, apiList) {
+ return schemaList
+ } else {
+ return apiList
+ }
+ }
+}
+
+// Remove the value of division_id, or if this field was left blank; the home division ID
+func removeSkillGroupDivisionID(d *schema.ResourceData, list []string) ([]string, diag.Diagnostics) {
+ if len(list) == 0 || list == nil {
+ return list, nil
+ }
+
+ divisionId := d.Get("division_id").(string)
+
+ if divisionId == "" {
+ id, diagErr := util.GetHomeDivisionID()
+ if diagErr != nil {
+ return nil, diagErr
+ }
+ divisionId = id
+ }
+
+ if lists.ItemInSlice(divisionId, list) {
+ list = lists.RemoveStringFromSlice(divisionId, list)
+ }
+ return list, nil
+}
+
+// Assign the member division ids to the skill group
+func assignMemberDivisionIds(ctx context.Context, d *schema.ResourceData, meta interface{}, create bool) diag.Diagnostics {
+ if create {
+ log.Printf("Creating Member Divisions for skill group %s", d.Id())
+ } else {
+ log.Printf("Updating Member Divisions for skill group %s", d.Id())
+ }
+
+ divIds, diagErr := readSkillGroupMemberDivisions(ctx, d, meta)
+ if diagErr != nil {
+ return diagErr
+ }
+
+ diagErr = createRoutingSkillGroupsMemberDivisions(ctx, d, meta, divIds, create)
+ if diagErr != nil {
+ return diagErr
+ }
+
+ return nil
+}
+
+func createListsForSkillgroupsMembersDivisions(schemaMemberDivisionIds []string, skillGroupDivisionIds []string, create bool, meta interface{}) ([]string, []string, diag.Diagnostics) {
+ toAdd := make([]string, 0)
+ toRemove := make([]string, 0)
+
+ if allMemberDivisionsSpecified(schemaMemberDivisionIds) {
+ if len(schemaMemberDivisionIds) > 1 {
+ return nil, nil, util.BuildDiagnosticError(resourceName, fmt.Sprintf(`member_division_ids should not contain more than one item when the value of an item is "*"`), fmt.Errorf(`member_division_ids should not contain more than one item when the value of an item is "*"`))
+ }
+ toAdd, err := getAllAuthDivisionIds(meta)
+ return toAdd, nil, err
+ }
+
+ if len(schemaMemberDivisionIds) > 0 {
+ if create {
+ return schemaMemberDivisionIds, nil, nil
+ }
+ toAdd, toRemove = organizeMemberDivisionIdsForUpdate(schemaMemberDivisionIds, skillGroupDivisionIds)
+ return toAdd, toRemove, nil
+ }
+
+ // Empty array - remove all
+ toRemove = append(toRemove, skillGroupDivisionIds...)
+
+ return nil, toRemove, nil
+}
+
+func allMemberDivisionsSpecified(schemaSkillGroupMemberDivisionIds []string) bool {
+ return lists.ItemInSlice("*", schemaSkillGroupMemberDivisionIds)
+}
diff --git a/genesyscloud/task_management_workbin/genesyscloud_task_management_workbin_proxy.go b/genesyscloud/task_management_workbin/genesyscloud_task_management_workbin_proxy.go
index dcce50592..906fa09bf 100644
--- a/genesyscloud/task_management_workbin/genesyscloud_task_management_workbin_proxy.go
+++ b/genesyscloud/task_management_workbin/genesyscloud_task_management_workbin_proxy.go
@@ -4,6 +4,8 @@ import (
"context"
"fmt"
+ rc "terraform-provider-genesyscloud/genesyscloud/resource_cache"
+
"github.com/mypurecloud/platform-client-sdk-go/v133/platformclientv2"
)
@@ -34,11 +36,13 @@ type taskManagementWorkbinProxy struct {
getTaskManagementWorkbinByIdAttr getTaskManagementWorkbinByIdFunc
updateTaskManagementWorkbinAttr updateTaskManagementWorkbinFunc
deleteTaskManagementWorkbinAttr deleteTaskManagementWorkbinFunc
+ workbinCache rc.CacheInterface[platformclientv2.Workbin]
}
// newTaskManagementWorkbinProxy initializes the task management workbin proxy with all of the data needed to communicate with Genesys Cloud
func newTaskManagementWorkbinProxy(clientConfig *platformclientv2.Configuration) *taskManagementWorkbinProxy {
api := platformclientv2.NewTaskManagementApiWithConfig(clientConfig)
+ workbinCache := rc.NewResourceCache[platformclientv2.Workbin]()
return &taskManagementWorkbinProxy{
clientConfig: clientConfig,
taskManagementApi: api,
@@ -48,6 +52,7 @@ func newTaskManagementWorkbinProxy(clientConfig *platformclientv2.Configuration)
getTaskManagementWorkbinByIdAttr: getTaskManagementWorkbinByIdFn,
updateTaskManagementWorkbinAttr: updateTaskManagementWorkbinFn,
deleteTaskManagementWorkbinAttr: deleteTaskManagementWorkbinFn,
+ workbinCache: workbinCache,
}
}
@@ -143,11 +148,12 @@ func getTaskManagementWorkbinIdByNameFn(ctx context.Context, p *taskManagementWo
// getTaskManagementWorkbinByIdFn is an implementation of the function to get a Genesys Cloud task management workbin by Id
func getTaskManagementWorkbinByIdFn(ctx context.Context, p *taskManagementWorkbinProxy, id string) (taskManagementWorkbin *platformclientv2.Workbin, resp *platformclientv2.APIResponse, err error) {
- workbin, resp, err := p.taskManagementApi.GetTaskmanagementWorkbin(id)
- if err != nil {
- return nil, resp, fmt.Errorf("failed to retrieve task management workbin by id %s: %s", id, err)
+ workbin := rc.GetCacheItem(p.workbinCache, id)
+ if workbin != nil {
+ return workbin, nil, nil
}
- return workbin, resp, nil
+
+ return p.taskManagementApi.GetTaskmanagementWorkbin(id)
}
// updateTaskManagementWorkbinFn is an implementation of the function to update a Genesys Cloud task management workbin
diff --git a/genesyscloud/task_management_workitem/data_source_genesyscloud_task_management_workitem_test.go b/genesyscloud/task_management_workitem/data_source_genesyscloud_task_management_workitem_test.go
index 65f4b23e1..1af837c7e 100644
--- a/genesyscloud/task_management_workitem/data_source_genesyscloud_task_management_workitem_test.go
+++ b/genesyscloud/task_management_workitem/data_source_genesyscloud_task_management_workitem_test.go
@@ -9,7 +9,8 @@ import (
workbin "terraform-provider-genesyscloud/genesyscloud/task_management_workbin"
workitemSchema "terraform-provider-genesyscloud/genesyscloud/task_management_workitem_schema"
worktype "terraform-provider-genesyscloud/genesyscloud/task_management_worktype"
-
+ worktypeStatus "terraform-provider-genesyscloud/genesyscloud/task_management_worktype_status"
+
"github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)
@@ -39,12 +40,16 @@ func TestAccDataSourceTaskManagementWorkitem(t *testing.T) {
wtResName = "tf_worktype_1"
wtName = "tf-worktype" + uuid.NewString()
wtDescription = "tf-worktype-description"
- wtOStatusName = "Open Status"
- wtOStatusDesc = "Description of open status"
- wtOStatusCategory = "Open"
- wtCStatusName = "Closed Status"
- wtCStatusDesc = "Description of closed status"
- wtCStatusCategory = "Closed"
+
+ // Worktype statuses
+ statusResourceOpen = "open-status"
+ wtOStatusName = "Open Status"
+ wtOStatusDesc = "Description of open status"
+ wtOStatusCategory = "Open"
+ statusResourceClosed = "closed-status"
+ wtCStatusName = "Closed Status"
+ wtCStatusDesc = "Description of closed status"
+ wtCStatusCategory = "Closed"
// basic workitem
workitemRes = "workitem_1"
@@ -64,22 +69,25 @@ func TestAccDataSourceTaskManagementWorkitem(t *testing.T) {
wtDescription,
fmt.Sprintf("genesyscloud_task_management_workbin.%s.id", wbResourceId),
fmt.Sprintf("genesyscloud_task_management_workitem_schema.%s.id", wsResourceId),
- // Needs both an open and closed status or workitems cannot be created for worktype.
- fmt.Sprintf(`
- statuses {
- name = "%s"
- description = "%s"
- category = "%s"
- }
- statuses {
- name = "%s"
- description = "%s"
- category = "%s"
- }
- default_status_name = "%s"
- `, wtOStatusName, wtOStatusDesc, wtOStatusCategory,
- wtCStatusName, wtCStatusDesc, wtCStatusCategory,
- wtOStatusName),
+ "",
+ ) +
+ worktypeStatus.GenerateWorktypeStatusResource(
+ statusResourceOpen,
+ fmt.Sprintf("genesyscloud_task_management_worktype.%s.id", wtResName),
+ wtOStatusName,
+ wtOStatusCategory,
+ wtOStatusDesc,
+ util.NullValue,
+ "",
+ ) +
+ worktypeStatus.GenerateWorktypeStatusResource(
+ statusResourceClosed,
+ fmt.Sprintf("genesyscloud_task_management_worktype.%s.id", wtResName),
+ wtCStatusName,
+ wtCStatusCategory,
+ wtCStatusDesc,
+ util.NullValue,
+ "",
)
)
resource.Test(t, resource.TestCase{
diff --git a/genesyscloud/task_management_workitem/genesyscloud_task_management_workitem_init_test.go b/genesyscloud/task_management_workitem/genesyscloud_task_management_workitem_init_test.go
index cad4d1e46..3f5796fd0 100644
--- a/genesyscloud/task_management_workitem/genesyscloud_task_management_workitem_init_test.go
+++ b/genesyscloud/task_management_workitem/genesyscloud_task_management_workitem_init_test.go
@@ -5,6 +5,8 @@ import (
authRole "terraform-provider-genesyscloud/genesyscloud/auth_role"
routingLanguage "terraform-provider-genesyscloud/genesyscloud/routing_language"
routingQueue "terraform-provider-genesyscloud/genesyscloud/routing_queue"
+ routingSkill "terraform-provider-genesyscloud/genesyscloud/routing_skill"
+
"terraform-provider-genesyscloud/genesyscloud/user_roles"
"testing"
@@ -15,6 +17,7 @@ import (
workbin "terraform-provider-genesyscloud/genesyscloud/task_management_workbin"
workitemSchema "terraform-provider-genesyscloud/genesyscloud/task_management_workitem_schema"
worktype "terraform-provider-genesyscloud/genesyscloud/task_management_worktype"
+ worktypeStatus "terraform-provider-genesyscloud/genesyscloud/task_management_worktype_status"
)
/*
@@ -43,10 +46,11 @@ func (r *registerTestInstance) registerTestResources() {
providerResources["genesyscloud_task_management_workbin"] = workbin.ResourceTaskManagementWorkbin()
providerResources["genesyscloud_task_management_worktype"] = worktype.ResourceTaskManagementWorktype()
providerResources["genesyscloud_routing_language"] = routingLanguage.ResourceRoutingLanguage()
+ providerResources["genesyscloud_task_management_worktype_status"] = worktypeStatus.ResourceTaskManagementWorktypeStatus()
providerResources["genesyscloud_user"] = gcloud.ResourceUser()
providerResources["genesyscloud_externalcontacts_contact"] = externalContacts.ResourceExternalContact()
providerResources["genesyscloud_routing_queue"] = routingQueue.ResourceRoutingQueue()
- providerResources["genesyscloud_routing_skill"] = gcloud.ResourceRoutingSkill()
+ providerResources["genesyscloud_routing_skill"] = routingSkill.ResourceRoutingSkill()
providerResources["genesyscloud_auth_role"] = authRole.ResourceAuthRole()
providerResources["genesyscloud_user_roles"] = user_roles.ResourceUserRoles()
}
diff --git a/genesyscloud/task_management_workitem/genesyscloud_task_management_workitem_proxy.go b/genesyscloud/task_management_workitem/genesyscloud_task_management_workitem_proxy.go
index cc3cd86d5..9ef0766dd 100644
--- a/genesyscloud/task_management_workitem/genesyscloud_task_management_workitem_proxy.go
+++ b/genesyscloud/task_management_workitem/genesyscloud_task_management_workitem_proxy.go
@@ -5,6 +5,8 @@ import (
"fmt"
"log"
+ rc "terraform-provider-genesyscloud/genesyscloud/resource_cache"
+
"github.com/mypurecloud/platform-client-sdk-go/v133/platformclientv2"
)
@@ -35,11 +37,13 @@ type taskManagementWorkitemProxy struct {
getTaskManagementWorkitemByIdAttr getTaskManagementWorkitemByIdFunc
updateTaskManagementWorkitemAttr updateTaskManagementWorkitemFunc
deleteTaskManagementWorkitemAttr deleteTaskManagementWorkitemFunc
+ workitemCache rc.CacheInterface[platformclientv2.Workitem]
}
// newTaskManagementWorkitemProxy initializes the task management workitem proxy with all of the data needed to communicate with Genesys Cloud
func newTaskManagementWorkitemProxy(clientConfig *platformclientv2.Configuration) *taskManagementWorkitemProxy {
api := platformclientv2.NewTaskManagementApiWithConfig(clientConfig)
+ workitemCache := rc.NewResourceCache[platformclientv2.Workitem]()
return &taskManagementWorkitemProxy{
clientConfig: clientConfig,
taskManagementApi: api,
@@ -49,6 +53,7 @@ func newTaskManagementWorkitemProxy(clientConfig *platformclientv2.Configuration
getTaskManagementWorkitemByIdAttr: getTaskManagementWorkitemByIdFn,
updateTaskManagementWorkitemAttr: updateTaskManagementWorkitemFn,
deleteTaskManagementWorkitemAttr: deleteTaskManagementWorkitemFn,
+ workitemCache: workitemCache,
}
}
@@ -93,13 +98,7 @@ func (p *taskManagementWorkitemProxy) deleteTaskManagementWorkitem(ctx context.C
// createTaskManagementWorkitemFn is an implementation function for creating a Genesys Cloud task management workitem
func createTaskManagementWorkitemFn(ctx context.Context, p *taskManagementWorkitemProxy, taskManagementWorkitem *platformclientv2.Workitemcreate) (*platformclientv2.Workitem, *platformclientv2.APIResponse, error) {
- log.Printf("Creating task management worktype: %s", *taskManagementWorkitem.Name)
- workitem, resp, err := p.taskManagementApi.PostTaskmanagementWorkitems(*taskManagementWorkitem)
- log.Printf("Completed call to create task management worktype %s with status code %d, correlation id %s and err %s", *taskManagementWorkitem.Name, resp.StatusCode, resp.CorrelationID, err)
- if err != nil {
- return nil, resp, fmt.Errorf("failed to create task management workitem: %s", err)
- }
- return workitem, resp, nil
+ return p.taskManagementApi.PostTaskmanagementWorkitems(*taskManagementWorkitem)
}
// getAllTaskManagementWorkitemFn is the implementation for retrieving all task management workitem in Genesys Cloud
@@ -231,27 +230,20 @@ func getTaskManagementWorkitemIdByNameFn(ctx context.Context, p *taskManagementW
// getTaskManagementWorkitemByIdFn is an implementation of the function to get a Genesys Cloud task management workitem by Id
func getTaskManagementWorkitemByIdFn(ctx context.Context, p *taskManagementWorkitemProxy, id string) (taskManagementWorkitem *platformclientv2.Workitem, resp *platformclientv2.APIResponse, err error) {
- workitem, resp, err := p.taskManagementApi.GetTaskmanagementWorkitem(id, "")
- if err != nil {
- return nil, resp, fmt.Errorf("failed to retrieve task management workitem by id %s: %s", id, err)
+ workitem := rc.GetCacheItem(p.workitemCache, id)
+ if workitem != nil {
+ return workitem, nil, nil
}
- return workitem, resp, nil
+
+ return p.taskManagementApi.GetTaskmanagementWorkitem(id, "")
}
// updateTaskManagementWorkitemFn is an implementation of the function to update a Genesys Cloud task management workitem
func updateTaskManagementWorkitemFn(ctx context.Context, p *taskManagementWorkitemProxy, id string, taskManagementWorkitem *platformclientv2.Workitemupdate) (*platformclientv2.Workitem, *platformclientv2.APIResponse, error) {
- workitem, resp, err := p.taskManagementApi.PatchTaskmanagementWorkitem(id, *taskManagementWorkitem)
- if err != nil {
- return nil, resp, fmt.Errorf("failed to update task management workitem: %s", err)
- }
- return workitem, resp, nil
+ return p.taskManagementApi.PatchTaskmanagementWorkitem(id, *taskManagementWorkitem)
}
// deleteTaskManagementWorkitemFn is an implementation function for deleting a Genesys Cloud task management workitem
func deleteTaskManagementWorkitemFn(ctx context.Context, p *taskManagementWorkitemProxy, id string) (resp *platformclientv2.APIResponse, err error) {
- resp, err = p.taskManagementApi.DeleteTaskmanagementWorkitem(id)
- if err != nil {
- return resp, fmt.Errorf("failed to delete task management workitem: %s", err)
- }
- return resp, nil
+ return p.taskManagementApi.DeleteTaskmanagementWorkitem(id)
}
diff --git a/genesyscloud/task_management_workitem/resource_genesyscloud_task_management_workitem.go b/genesyscloud/task_management_workitem/resource_genesyscloud_task_management_workitem.go
index 3abfa846d..3c8bb4bc6 100644
--- a/genesyscloud/task_management_workitem/resource_genesyscloud_task_management_workitem.go
+++ b/genesyscloud/task_management_workitem/resource_genesyscloud_task_management_workitem.go
@@ -49,7 +49,7 @@ func createTaskManagementWorkitem(ctx context.Context, d *schema.ResourceData, m
taskManagementWorkitem, err := getWorkitemCreateFromResourceData(d)
if err != nil {
- return util.BuildDiagnosticError(resourceName, fmt.Sprintf("failed to build Workitem create from resource data"), err)
+ return util.BuildDiagnosticError(resourceName, "failed to build Workitem create from resource data", err)
}
log.Printf("Creating task management workitem %s", *taskManagementWorkitem.Name)
@@ -138,7 +138,7 @@ func updateTaskManagementWorkitem(ctx context.Context, d *schema.ResourceData, m
taskManagementWorkitem, err := getWorkitemUpdateFromResourceData(d)
if err != nil {
- return util.BuildDiagnosticError(resourceName, fmt.Sprintf("failed to update Workitem create from resource data"), err)
+ return util.BuildDiagnosticError(resourceName, "failed to update Workitem create from resource data", err)
}
log.Printf("Updating task management workitem %s", *taskManagementWorkitem.Name)
diff --git a/genesyscloud/task_management_workitem/resource_genesyscloud_task_management_workitem_schema.go b/genesyscloud/task_management_workitem/resource_genesyscloud_task_management_workitem_schema.go
index 6e1c27978..a7e3423ac 100644
--- a/genesyscloud/task_management_workitem/resource_genesyscloud_task_management_workitem_schema.go
+++ b/genesyscloud/task_management_workitem/resource_genesyscloud_task_management_workitem_schema.go
@@ -1,13 +1,15 @@
package task_management_workitem
import (
- "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
- "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"terraform-provider-genesyscloud/genesyscloud/provider"
resourceExporter "terraform-provider-genesyscloud/genesyscloud/resource_exporter"
registrar "terraform-provider-genesyscloud/genesyscloud/resource_register"
+ "terraform-provider-genesyscloud/genesyscloud/task_management_worktype_status"
"terraform-provider-genesyscloud/genesyscloud/util"
"terraform-provider-genesyscloud/genesyscloud/validators"
+
+ "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
+ "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
)
/*
@@ -116,6 +118,7 @@ func ResourceTaskManagementWorkitem() *schema.Resource {
Description: `The id of the current status of the Workitem.`,
Optional: true,
Computed: true,
+ StateFunc: task_management_worktype_status.ModifyStatusIdStateValue,
Type: schema.TypeString,
},
`workbin_id`: {
@@ -198,6 +201,7 @@ func TaskManagementWorkitemExporter() *resourceExporter.ResourceExporter {
"external_contact_id": {RefType: "genesyscloud_externalcontacts_contact"},
"queue_id": {RefType: "genesyscloud_routing_queue"},
"skills_ids": {RefType: "genesyscloud_routing_skill"},
+ "status_id": {RefType: "genesyscloud_task_management_worktype_status"},
},
}
}
diff --git a/genesyscloud/task_management_workitem/resource_genesyscloud_task_management_workitem_test.go b/genesyscloud/task_management_workitem/resource_genesyscloud_task_management_workitem_test.go
index 697a3bcbf..da6e06773 100644
--- a/genesyscloud/task_management_workitem/resource_genesyscloud_task_management_workitem_test.go
+++ b/genesyscloud/task_management_workitem/resource_genesyscloud_task_management_workitem_test.go
@@ -8,6 +8,9 @@ import (
"terraform-provider-genesyscloud/genesyscloud/provider"
routingLanguage "terraform-provider-genesyscloud/genesyscloud/routing_language"
routingQueue "terraform-provider-genesyscloud/genesyscloud/routing_queue"
+ routingSkill "terraform-provider-genesyscloud/genesyscloud/routing_skill"
+
+ "terraform-provider-genesyscloud/genesyscloud/task_management_worktype_status"
"terraform-provider-genesyscloud/genesyscloud/user_roles"
"terraform-provider-genesyscloud/genesyscloud/util"
"testing"
@@ -21,6 +24,7 @@ import (
workbin "terraform-provider-genesyscloud/genesyscloud/task_management_workbin"
workitemSchema "terraform-provider-genesyscloud/genesyscloud/task_management_workitem_schema"
worktype "terraform-provider-genesyscloud/genesyscloud/task_management_worktype"
+ worktypeStatus "terraform-provider-genesyscloud/genesyscloud/task_management_worktype_status"
"terraform-provider-genesyscloud/genesyscloud/util/resourcedata"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
@@ -81,15 +85,19 @@ func TestAccResourceTaskManagementWorkitem(t *testing.T) {
wsDescription = "workitem schema created for CX as Code test case"
// worktype
- wtResName = "tf_worktype_1"
- wtName = "tf-worktype" + uuid.NewString()
- wtDescription = "tf-worktype-description"
- wtOStatusName = "Open Status"
- wtOStatusDesc = "Description of open status"
- wtOStatusCategory = "Open"
- wtCStatusName = "Closed Status"
- wtCStatusDesc = "Description of closed status"
- wtCStatusCategory = "Closed"
+ wtResName = "tf_worktype_1"
+ wtName = "tf-worktype" + uuid.NewString()
+ wtDescription = "tf-worktype-description"
+
+ // Worktype statuses
+ statusResourceOpen = "open-status"
+ wtOStatusName = "Open Status"
+ wtOStatusDesc = "Description of open status"
+ wtOStatusCategory = "Open"
+ statusResourceClosed = "closed-status"
+ wtCStatusName = "Closed Status"
+ wtCStatusDesc = "Description of closed status"
+ wtCStatusCategory = "Closed"
// language
resLang = "language_1"
@@ -148,7 +156,7 @@ func TestAccResourceTaskManagementWorkitem(t *testing.T) {
}},
}
- // String configuration of task management objects needed for the workitem: schema, workbin, workitem.
+ // String configuration of task management objects needed for the workitem: schema, workbin, worktype, worktype_status.
// They don't really change so they are defined here instead of in each step.
taskMgmtConfig = workbin.GenerateWorkbinResource(wbResourceId, wbName, wbDescription, util.NullValue) +
workbin.GenerateWorkbinResource(wb2ResourceId, wb2Name, wb2Description, util.NullValue) +
@@ -159,22 +167,25 @@ func TestAccResourceTaskManagementWorkitem(t *testing.T) {
wtDescription,
fmt.Sprintf("genesyscloud_task_management_workbin.%s.id", wbResourceId),
fmt.Sprintf("genesyscloud_task_management_workitem_schema.%s.id", wsResourceId),
- // Needs both an open and closed status or workitems cannot be created for worktype.
- fmt.Sprintf(`
- statuses {
- name = "%s"
- description = "%s"
- category = "%s"
- }
- statuses {
- name = "%s"
- description = "%s"
- category = "%s"
- }
- default_status_name = "%s"
- `, wtOStatusName, wtOStatusDesc, wtOStatusCategory,
- wtCStatusName, wtCStatusDesc, wtCStatusCategory,
- wtOStatusName),
+ "",
+ ) +
+ worktypeStatus.GenerateWorktypeStatusResource(
+ statusResourceOpen,
+ fmt.Sprintf("genesyscloud_task_management_worktype.%s.id", wtResName),
+ wtOStatusName,
+ wtOStatusCategory,
+ wtOStatusDesc,
+ util.NullValue,
+ "",
+ ) +
+ worktypeStatus.GenerateWorktypeStatusResource(
+ statusResourceClosed,
+ fmt.Sprintf("genesyscloud_task_management_worktype.%s.id", wtResName),
+ wtCStatusName,
+ wtCStatusCategory,
+ wtCStatusDesc,
+ util.NullValue,
+ "",
)
)
@@ -185,10 +196,16 @@ func TestAccResourceTaskManagementWorkitem(t *testing.T) {
// Create basic workitem
{
Config: taskMgmtConfig +
- generateWorkitemResourceBasic(workitemRes, workitem1.name, workitem1.worktype_id, ""),
+ generateWorkitemResourceBasic(
+ workitemRes,
+ workitem1.name,
+ workitem1.worktype_id,
+ fmt.Sprintf("status_id = genesyscloud_task_management_worktype_status.%s.id", statusResourceOpen),
+ ),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("genesyscloud_task_management_workitem."+workitemRes, "name", workitem1.name),
resource.TestCheckResourceAttrPair("genesyscloud_task_management_workitem."+workitemRes, "worktype_id", "genesyscloud_task_management_worktype."+wtResName, "id"),
+ task_management_worktype_status.ValidateStatusIds("genesyscloud_task_management_workitem."+workitemRes, "status_id", "genesyscloud_task_management_worktype_status."+statusResourceOpen, "id"),
),
},
// Update workitem with more fields
@@ -197,7 +214,7 @@ func TestAccResourceTaskManagementWorkitem(t *testing.T) {
gcloud.GenerateAuthDivisionHomeDataSource(homeDivRes) +
routingLanguage.GenerateRoutingLanguageResource(resLang, lang) +
routingQueue.GenerateRoutingQueueResourceBasic(resQueue, queueName) +
- gcloud.GenerateRoutingSkillResource(skillResId1, skillResName1) +
+ routingSkill.GenerateRoutingSkillResource(skillResId1, skillResName1) +
gcloud.GenerateBasicUserResource(userResId1, userEmail1, userName1) +
externalContact.GenerateBasicExternalContactResource(externalContactResId1, externalContactTitle1) +
authRole.GenerateAuthRoleResource(roleResId1, roleName1, "test role description",
@@ -209,7 +226,7 @@ func TestAccResourceTaskManagementWorkitem(t *testing.T) {
"data.genesyscloud_auth_division_home."+homeDivRes+".id",
),
) +
- generateWorkitemResource(workitemRes, workitem1Update, "depends_on = [genesyscloud_user_roles.user_role_1]"),
+ generateWorkitemResource(workitemRes, workitem1Update, ""),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("genesyscloud_task_management_workitem."+workitemRes, "name", workitem1Update.name),
resource.TestCheckResourceAttr("genesyscloud_task_management_workitem."+workitemRes, "description", workitem1Update.description),
@@ -219,6 +236,7 @@ func TestAccResourceTaskManagementWorkitem(t *testing.T) {
resource.TestCheckResourceAttr("genesyscloud_task_management_workitem."+workitemRes, "date_expires", workitem1Update.date_expires),
resource.TestCheckResourceAttr("genesyscloud_task_management_workitem."+workitemRes, "duration_seconds", fmt.Sprintf("%d", workitem1Update.duration_seconds)),
resource.TestCheckResourceAttr("genesyscloud_task_management_workitem."+workitemRes, "ttl", fmt.Sprintf("%d", workitem1Update.ttl)),
+ task_management_worktype_status.ValidateStatusIds("genesyscloud_task_management_workitem."+workitemRes, "status_id", "genesyscloud_task_management_worktype_status."+statusResourceOpen, "id"),
resource.TestCheckResourceAttrPair("genesyscloud_task_management_workitem."+workitemRes, "workbin_id", "genesyscloud_task_management_workbin."+wbResourceId, "id"),
resource.TestCheckResourceAttrPair("genesyscloud_task_management_workitem."+workitemRes, "assignee_id", "genesyscloud_user."+userResId1, "id"),
resource.TestCheckResourceAttrPair("genesyscloud_task_management_workitem."+workitemRes, "external_contact_id", "genesyscloud_externalcontacts_contact."+externalContactResId1, "id"),
@@ -398,12 +416,16 @@ func TestAccResourceTaskManagementWorkitemCustomFields(t *testing.T) {
wtResName = "tf_worktype_1"
wtName = "tf-worktype" + uuid.NewString()
wtDescription = "tf-worktype-description"
- wtOStatusName = "Open Status"
- wtOStatusDesc = "Description of open status"
- wtOStatusCategory = "Open"
- wtCStatusName = "Closed Status"
- wtCStatusDesc = "Description of closed status"
- wtCStatusCategory = "Closed"
+
+ // Worktype statuses
+ statusResourceOpen = "open-status"
+ wtOStatusName = "Open Status"
+ wtOStatusDesc = "Description of open status"
+ wtOStatusCategory = "Open"
+ statusResourceClosed = "closed-status"
+ wtCStatusName = "Closed Status"
+ wtCStatusDesc = "Description of closed status"
+ wtCStatusCategory = "Closed"
// basic workitem
workitemRes = "workitem_1"
@@ -456,22 +478,25 @@ func TestAccResourceTaskManagementWorkitemCustomFields(t *testing.T) {
wtDescription,
fmt.Sprintf("genesyscloud_task_management_workbin.%s.id", wbResourceId),
fmt.Sprintf("genesyscloud_task_management_workitem_schema.%s.id", wsResourceId),
- // Needs both an open and closed status or workitems cannot be created for worktype.
- fmt.Sprintf(`
- statuses {
- name = "%s"
- description = "%s"
- category = "%s"
- }
- statuses {
- name = "%s"
- description = "%s"
- category = "%s"
- }
- default_status_name = "%s"
- `, wtOStatusName, wtOStatusDesc, wtOStatusCategory,
- wtCStatusName, wtCStatusDesc, wtCStatusCategory,
- wtOStatusName),
+ "",
+ ) +
+ worktypeStatus.GenerateWorktypeStatusResource(
+ statusResourceOpen,
+ fmt.Sprintf("genesyscloud_task_management_worktype.%s.id", wtResName),
+ wtOStatusName,
+ wtOStatusCategory,
+ wtOStatusDesc,
+ util.NullValue,
+ "",
+ ) +
+ worktypeStatus.GenerateWorktypeStatusResource(
+ statusResourceClosed,
+ fmt.Sprintf("genesyscloud_task_management_worktype.%s.id", wtResName),
+ wtCStatusName,
+ wtCStatusCategory,
+ wtCStatusDesc,
+ util.NullValue,
+ "",
)
)
diff --git a/genesyscloud/task_management_workitem/resource_genesyscloud_task_management_workitem_utils.go b/genesyscloud/task_management_workitem/resource_genesyscloud_task_management_workitem_utils.go
index 505faf533..abc88ca7e 100644
--- a/genesyscloud/task_management_workitem/resource_genesyscloud_task_management_workitem_utils.go
+++ b/genesyscloud/task_management_workitem/resource_genesyscloud_task_management_workitem_utils.go
@@ -3,6 +3,8 @@ package task_management_workitem
import (
"encoding/json"
"fmt"
+ "strings"
+ "terraform-provider-genesyscloud/genesyscloud/task_management_worktype_status"
"terraform-provider-genesyscloud/genesyscloud/util"
"terraform-provider-genesyscloud/genesyscloud/util/resourcedata"
@@ -24,7 +26,7 @@ func getWorkitemCreateFromResourceData(d *schema.ResourceData) (*platformclientv
return nil, err
}
- return &platformclientv2.Workitemcreate{
+ workItem := platformclientv2.Workitemcreate{
Name: platformclientv2.String(d.Get("name").(string)),
TypeId: platformclientv2.String(d.Get("worktype_id").(string)),
Description: platformclientv2.String(d.Get("description").(string)),
@@ -47,7 +49,16 @@ func getWorkitemCreateFromResourceData(d *schema.ResourceData) (*platformclientv
CustomFields: customFields,
ScoredAgents: buildWorkitemScoredAgents(d.Get("scored_agents").([]interface{})),
- }, nil
+ }
+
+ // If the user makes a reference to a status that is managed by terraform the id will look like this /
+ // so we need to extract just the status id from any status references that look like this
+ if workItem.StatusId != nil && strings.Contains(*workItem.StatusId, "/") {
+ _, id := task_management_worktype_status.SplitWorktypeStatusTerraformId(*workItem.StatusId)
+ workItem.StatusId = &id
+ }
+
+ return &workItem, nil
}
// getWorkitemUpdateFromResourceData maps data from schema ResourceData object to a platformclientv2.Workitemupdate
@@ -58,7 +69,7 @@ func getWorkitemUpdateFromResourceData(d *schema.ResourceData) (*platformclientv
}
// NOTE: The only difference from Workitemcreate is that you can't change the Worktype
- return &platformclientv2.Workitemupdate{
+ workItem := platformclientv2.Workitemupdate{
Name: platformclientv2.String(d.Get("name").(string)),
Description: platformclientv2.String(d.Get("description").(string)),
@@ -80,7 +91,16 @@ func getWorkitemUpdateFromResourceData(d *schema.ResourceData) (*platformclientv
CustomFields: customFields,
ScoredAgents: buildWorkitemScoredAgents(d.Get("scored_agents").([]interface{})),
- }, nil
+ }
+
+ // If the user makes a reference to a status that is managed by terraform the id will look like this /
+ // so we need to extract just the status id from any status references that look like this
+ if workItem.StatusId != nil && strings.Contains(*workItem.StatusId, "/") {
+ _, id := task_management_worktype_status.SplitWorktypeStatusTerraformId(*workItem.StatusId)
+ workItem.StatusId = &id
+ }
+
+ return &workItem, nil
}
// buildCustomFieldsNillable builds a Genesys Cloud *[]platformclientv2.Workitemscoredagent from a JSON string
diff --git a/genesyscloud/task_management_workitem_schema/genesyscloud_task_management_workitem_schema_proxy.go b/genesyscloud/task_management_workitem_schema/genesyscloud_task_management_workitem_schema_proxy.go
index 309470b2d..47f558446 100644
--- a/genesyscloud/task_management_workitem_schema/genesyscloud_task_management_workitem_schema_proxy.go
+++ b/genesyscloud/task_management_workitem_schema/genesyscloud_task_management_workitem_schema_proxy.go
@@ -8,6 +8,8 @@ import (
"log"
"net/http"
+ rc "terraform-provider-genesyscloud/genesyscloud/resource_cache"
+
"github.com/mypurecloud/platform-client-sdk-go/v133/platformclientv2"
)
@@ -40,11 +42,14 @@ type taskManagementProxy struct {
updateTaskManagementWorkitemSchemaAttr updateTaskManagementWorkitemSchemaFunc
deleteTaskManagementWorkitemSchemaAttr deleteTaskManagementWorkitemSchemaFunc
getTaskManagementWorkitemSchemaDeletedStatusAttr getTaskManagementWorkitemSchemaDeletedStatusFunc
+ workitemSchemaCache rc.CacheInterface[platformclientv2.Dataschema]
}
// newTaskManagementProxy initializes the task management proxy with all of the data needed to communicate with Genesys Cloud
func newTaskManagementProxy(clientConfig *platformclientv2.Configuration) *taskManagementProxy {
api := platformclientv2.NewTaskManagementApiWithConfig(clientConfig)
+ workitemSchemaCache := rc.NewResourceCache[platformclientv2.Dataschema]()
+
return &taskManagementProxy{
clientConfig: clientConfig,
taskManagementApi: api,
@@ -55,6 +60,7 @@ func newTaskManagementProxy(clientConfig *platformclientv2.Configuration) *taskM
updateTaskManagementWorkitemSchemaAttr: updateTaskManagementWorkitemSchemaFn,
deleteTaskManagementWorkitemSchemaAttr: deleteTaskManagementWorkitemSchemaFn,
getTaskManagementWorkitemSchemaDeletedStatusAttr: getTaskManagementWorkitemSchemaDeletedStatusFn,
+ workitemSchemaCache: workitemSchemaCache,
}
}
@@ -152,11 +158,11 @@ func getTaskManagementWorkitemSchemasByNameFn(ctx context.Context, p *taskManage
// getTaskManagementWorkitemSchemaByIdFn is an implementation of the function to get a Genesys Cloud task management workitem schema by Id
func getTaskManagementWorkitemSchemaByIdFn(ctx context.Context, p *taskManagementProxy, id string) (schema *platformclientv2.Dataschema, resp *platformclientv2.APIResponse, err error) {
- schema, resp, err = p.taskManagementApi.GetTaskmanagementWorkitemsSchema(id)
- if err != nil {
- return nil, resp, fmt.Errorf("failed to retrieve task management workitem schema by id %s: %v", id, err)
+ workitemSchema := rc.GetCacheItem(p.workitemSchemaCache, id)
+ if workitemSchema != nil {
+ return schema, nil, nil
}
- return schema, resp, nil
+ return p.taskManagementApi.GetTaskmanagementWorkitemsSchema(id)
}
// updateTaskManagementWorkitemSchemaFn is an implementation of the function to update a Genesys Cloud task management workitem schema
diff --git a/genesyscloud/task_management_worktype/data_source_genesyscloud_task_management_unit_test.go b/genesyscloud/task_management_worktype/data_source_genesyscloud_task_management_unit_test.go
deleted file mode 100644
index 0fa5a999a..000000000
--- a/genesyscloud/task_management_worktype/data_source_genesyscloud_task_management_unit_test.go
+++ /dev/null
@@ -1,74 +0,0 @@
-package task_management_worktype
-
-import (
- "context"
- "terraform-provider-genesyscloud/genesyscloud/provider"
- "testing"
-
- "github.com/google/uuid"
- "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
- "github.com/mypurecloud/platform-client-sdk-go/v133/platformclientv2"
- "github.com/stretchr/testify/assert"
-)
-
-// TestUnitataSourceTaskManagementWorktypeStatus tests the retrieve of a status id.
-// I am writing a unit test here as we already have the basic test coverage in another test.
-func TestUnitDataSourceTaskManagementWorktypeStatus(t *testing.T) {
- name := "Insurance Claim-Test"
- defaultTtlSeconds := 2678400
- defaultPriority := 2000
- workTypeId := uuid.NewString()
- approvedStatusId := uuid.NewString()
- approvedName := "Approved"
- approvedCategory := "Closed"
- rejectedStatusId := uuid.NewString()
- rejectedName := "Rejected"
- rejectedCategory := "Closed"
-
- approvedStatus := &platformclientv2.Workitemstatus{
- Id: &approvedStatusId,
- Name: &approvedName,
- Category: &approvedCategory,
- }
-
- rejectedStatus := &platformclientv2.Workitemstatus{
- Id: &rejectedStatusId,
- Name: &rejectedName,
- Category: &rejectedCategory,
- }
-
- statuses := &[]platformclientv2.Workitemstatus{*approvedStatus, *rejectedStatus}
- workType := &platformclientv2.Worktype{
- Id: &workTypeId,
- Name: &name,
- DefaultTtlSeconds: &defaultTtlSeconds,
- DefaultPriority: &defaultPriority,
- Statuses: statuses,
- }
-
- workTypeProxy := &taskManagementWorktypeProxy{}
- workTypeProxy.getTaskManagementWorktypeByNameAttr = func(ctx context.Context, proxy *taskManagementWorktypeProxy, name string) (workItemType *platformclientv2.Worktype, retryable bool, resp *platformclientv2.APIResponse, err error) {
- return workType, false, resp, nil
- }
-
- internalProxy = workTypeProxy
- defer func() { internalProxy = nil }()
-
- ctx := context.Background()
- gcloud := &provider.ProviderMeta{ClientConfig: &platformclientv2.Configuration{}}
-
- //Grab our defined schema
- schemaDS := DataSourceTaskManagementWorktypeStatus().Schema
-
- //Setup a map of values
- dsDataMap := map[string]interface{}{
- "worktype_name": *workType.Name,
- "worktype_status_name": *approvedStatus.Name,
- }
-
- d := schema.TestResourceDataRaw(t, schemaDS, dsDataMap)
-
- diag := dataSourceTaskManagementWorktypeStatusRead(ctx, d, gcloud)
- assert.Equal(t, false, diag.HasError())
- assert.Equal(t, approvedStatusId, d.Id())
-}
diff --git a/genesyscloud/task_management_worktype/data_source_genesyscloud_task_management_worktype.go b/genesyscloud/task_management_worktype/data_source_genesyscloud_task_management_worktype.go
index 9a1feec11..a7e2077f5 100644
--- a/genesyscloud/task_management_worktype/data_source_genesyscloud_task_management_worktype.go
+++ b/genesyscloud/task_management_worktype/data_source_genesyscloud_task_management_worktype.go
@@ -21,7 +21,7 @@ import (
// dataSourceTaskManagementWorktypeRead retrieves by name the id in question
func dataSourceTaskManagementWorktypeRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
sdkConfig := meta.(*provider.ProviderMeta).ClientConfig
- proxy := getTaskManagementWorktypeProxy(sdkConfig)
+ proxy := GetTaskManagementWorktypeProxy(sdkConfig)
name := d.Get("name").(string)
@@ -40,33 +40,3 @@ func dataSourceTaskManagementWorktypeRead(ctx context.Context, d *schema.Resourc
return nil
})
}
-
-func dataSourceTaskManagementWorktypeStatusRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
- sdkConfig := meta.(*provider.ProviderMeta).ClientConfig
- proxy := getTaskManagementWorktypeProxy(sdkConfig)
-
- workTypeName := d.Get("worktype_name").(string)
- statusName := d.Get("worktype_status_name").(string)
-
- return util.WithRetries(ctx, 15*time.Second, func() *retry.RetryError {
- //First retrieve the work type id by name
- workType, retryable, resp, err := proxy.getTaskManagementWorktypeByName(ctx, workTypeName)
-
- if err != nil && !retryable {
- return retry.NonRetryableError(util.BuildWithRetriesApiDiagnosticError(resourceName, fmt.Sprintf("error searching task management worktype %s | error: %s", workTypeName, err), resp))
- }
-
- if retryable {
- return retry.RetryableError(util.BuildWithRetriesApiDiagnosticError(resourceName, fmt.Sprintf("no task management worktype found with name %s", workTypeName), resp))
- }
-
- for _, status := range *workType.Statuses {
- if *status.Name == statusName {
- d.SetId(*status.Id)
- return nil
- }
- }
-
- return retry.NonRetryableError(util.BuildWithRetriesApiDiagnosticError(resourceName, fmt.Sprintf("No records found for management worktype %s with status name %s | error: %s", workTypeName, statusName, err), resp))
- })
-}
diff --git a/genesyscloud/task_management_worktype/genesyscloud_task_management_worktype_init_test.go b/genesyscloud/task_management_worktype/genesyscloud_task_management_worktype_init_test.go
index bdb8160ee..f33fe57d6 100644
--- a/genesyscloud/task_management_worktype/genesyscloud_task_management_worktype_init_test.go
+++ b/genesyscloud/task_management_worktype/genesyscloud_task_management_worktype_init_test.go
@@ -4,6 +4,7 @@ import (
"sync"
routingQueue "terraform-provider-genesyscloud/genesyscloud/routing_queue"
"testing"
+ routingSkill "terraform-provider-genesyscloud/genesyscloud/routing_skill"
gcloud "terraform-provider-genesyscloud/genesyscloud"
routingLanguage "terraform-provider-genesyscloud/genesyscloud/routing_language"
@@ -39,7 +40,7 @@ func (r *registerTestInstance) registerTestResources() {
providerResources["genesyscloud_task_management_workitem_schema"] = workitemSchema.ResourceTaskManagementWorkitemSchema()
providerResources["genesyscloud_routing_language"] = routingLanguage.ResourceRoutingLanguage()
providerResources["genesyscloud_routing_queue"] = routingQueue.ResourceRoutingQueue()
- providerResources["genesyscloud_routing_skill"] = gcloud.ResourceRoutingSkill()
+ providerResources["genesyscloud_routing_skill"] = routingSkill.ResourceRoutingSkill()
}
// registerTestDataSources registers all data sources used in the tests.
diff --git a/genesyscloud/task_management_worktype/genesyscloud_task_management_worktype_proxy.go b/genesyscloud/task_management_worktype/genesyscloud_task_management_worktype_proxy.go
index c24b2bab2..a9d0d83e3 100644
--- a/genesyscloud/task_management_worktype/genesyscloud_task_management_worktype_proxy.go
+++ b/genesyscloud/task_management_worktype/genesyscloud_task_management_worktype_proxy.go
@@ -4,6 +4,7 @@ import (
"context"
"fmt"
"log"
+ rc "terraform-provider-genesyscloud/genesyscloud/resource_cache"
"github.com/mypurecloud/platform-client-sdk-go/v133/platformclientv2"
)
@@ -15,23 +16,19 @@ out during testing.
*/
// internalProxy holds a proxy instance that can be used throughout the package
-var internalProxy *taskManagementWorktypeProxy
+var internalProxy *TaskManagementWorktypeProxy
// Type definitions for each func on our proxy so we can easily mock them out later
-
-type createTaskManagementWorktypeFunc func(ctx context.Context, p *taskManagementWorktypeProxy, worktype *platformclientv2.Worktypecreate) (*platformclientv2.Worktype, *platformclientv2.APIResponse, error)
-type getAllTaskManagementWorktypeFunc func(ctx context.Context, p *taskManagementWorktypeProxy) (*[]platformclientv2.Worktype, *platformclientv2.APIResponse, error)
-type getTaskManagementWorktypeIdByNameFunc func(ctx context.Context, p *taskManagementWorktypeProxy, name string) (id string, retryable bool, resp *platformclientv2.APIResponse, err error)
-type getTaskManagementWorktypeByNameFunc func(ctx context.Context, p *taskManagementWorktypeProxy, name string) (workItemType *platformclientv2.Worktype, retryable bool, resp *platformclientv2.APIResponse, err error)
-type getTaskManagementWorktypeByIdFunc func(ctx context.Context, p *taskManagementWorktypeProxy, id string) (worktype *platformclientv2.Worktype, response *platformclientv2.APIResponse, err error)
-type updateTaskManagementWorktypeFunc func(ctx context.Context, p *taskManagementWorktypeProxy, id string, worktype *platformclientv2.Worktypeupdate) (*platformclientv2.Worktype, *platformclientv2.APIResponse, error)
-type deleteTaskManagementWorktypeFunc func(ctx context.Context, p *taskManagementWorktypeProxy, id string) (response *platformclientv2.APIResponse, err error)
-type createTaskManagementWorktypeStatusFunc func(ctx context.Context, p *taskManagementWorktypeProxy, worktypeId string, status *platformclientv2.Workitemstatuscreate) (*platformclientv2.Workitemstatus, *platformclientv2.APIResponse, error)
-type updateTaskManagementWorktypeStatusFunc func(ctx context.Context, p *taskManagementWorktypeProxy, worktypeId string, statusId string, statusUpdate *platformclientv2.Workitemstatusupdate) (*platformclientv2.Workitemstatus, *platformclientv2.APIResponse, error)
-type deleteTaskManagementWorktypeStatusFunc func(ctx context.Context, p *taskManagementWorktypeProxy, worktypeId string, statusId string) (response *platformclientv2.APIResponse, err error)
-
-// taskManagementWorktypeProxy contains all of the methods that call genesys cloud APIs.
-type taskManagementWorktypeProxy struct {
+type createTaskManagementWorktypeFunc func(ctx context.Context, p *TaskManagementWorktypeProxy, worktype *platformclientv2.Worktypecreate) (*platformclientv2.Worktype, *platformclientv2.APIResponse, error)
+type getAllTaskManagementWorktypeFunc func(ctx context.Context, p *TaskManagementWorktypeProxy) (*[]platformclientv2.Worktype, *platformclientv2.APIResponse, error)
+type getTaskManagementWorktypeIdByNameFunc func(ctx context.Context, p *TaskManagementWorktypeProxy, name string) (id string, retryable bool, resp *platformclientv2.APIResponse, err error)
+type getTaskManagementWorktypeByNameFunc func(ctx context.Context, p *TaskManagementWorktypeProxy, name string) (workItemType *platformclientv2.Worktype, retryable bool, resp *platformclientv2.APIResponse, err error)
+type getTaskManagementWorktypeByIdFunc func(ctx context.Context, p *TaskManagementWorktypeProxy, id string) (worktype *platformclientv2.Worktype, response *platformclientv2.APIResponse, err error)
+type updateTaskManagementWorktypeFunc func(ctx context.Context, p *TaskManagementWorktypeProxy, id string, worktype *platformclientv2.Worktypeupdate) (*platformclientv2.Worktype, *platformclientv2.APIResponse, error)
+type deleteTaskManagementWorktypeFunc func(ctx context.Context, p *TaskManagementWorktypeProxy, id string) (response *platformclientv2.APIResponse, err error)
+
+// TaskManagementWorktypeProxy contains all the methods that call genesys cloud APIs.
+type TaskManagementWorktypeProxy struct {
clientConfig *platformclientv2.Configuration
taskManagementApi *platformclientv2.TaskManagementApi
createTaskManagementWorktypeAttr createTaskManagementWorktypeFunc
@@ -41,16 +38,14 @@ type taskManagementWorktypeProxy struct {
getTaskManagementWorktypeByNameAttr getTaskManagementWorktypeByNameFunc
updateTaskManagementWorktypeAttr updateTaskManagementWorktypeFunc
deleteTaskManagementWorktypeAttr deleteTaskManagementWorktypeFunc
-
- createTaskManagementWorktypeStatusAttr createTaskManagementWorktypeStatusFunc
- updateTaskManagementWorktypeStatusAttr updateTaskManagementWorktypeStatusFunc
- deleteTaskManagementWorktypeStatusAttr deleteTaskManagementWorktypeStatusFunc
+ worktypeCache rc.CacheInterface[platformclientv2.Worktype]
}
-// newTaskManagementWorktypeProxy initializes the task management worktype proxy with all of the data needed to communicate with Genesys Cloud
-func newTaskManagementWorktypeProxy(clientConfig *platformclientv2.Configuration) *taskManagementWorktypeProxy {
+// newTaskManagementWorktypeProxy initializes the task management worktype proxy with all the data needed to communicate with Genesys Cloud
+func newTaskManagementWorktypeProxy(clientConfig *platformclientv2.Configuration) *TaskManagementWorktypeProxy {
api := platformclientv2.NewTaskManagementApiWithConfig(clientConfig)
- return &taskManagementWorktypeProxy{
+ worktypeCache := rc.NewResourceCache[platformclientv2.Worktype]()
+ return &TaskManagementWorktypeProxy{
clientConfig: clientConfig,
taskManagementApi: api,
createTaskManagementWorktypeAttr: createTaskManagementWorktypeFn,
@@ -60,16 +55,13 @@ func newTaskManagementWorktypeProxy(clientConfig *platformclientv2.Configuration
getTaskManagementWorktypeByIdAttr: getTaskManagementWorktypeByIdFn,
updateTaskManagementWorktypeAttr: updateTaskManagementWorktypeFn,
deleteTaskManagementWorktypeAttr: deleteTaskManagementWorktypeFn,
-
- createTaskManagementWorktypeStatusAttr: createTaskManagementWorktypeStatusFn,
- updateTaskManagementWorktypeStatusAttr: updateTaskManagementWorktypeStatusFn,
- deleteTaskManagementWorktypeStatusAttr: deleteTaskManagementWorktypeStatusFn,
+ worktypeCache: worktypeCache,
}
}
-// getTaskManagementWorktypeProxy acts as a singleton to for the internalProxy. It also ensures
+// GetTaskManagementWorktypeProxy 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 getTaskManagementWorktypeProxy(clientConfig *platformclientv2.Configuration) *taskManagementWorktypeProxy {
+func GetTaskManagementWorktypeProxy(clientConfig *platformclientv2.Configuration) *TaskManagementWorktypeProxy {
if internalProxy == nil {
internalProxy = newTaskManagementWorktypeProxy(clientConfig)
}
@@ -77,68 +69,47 @@ func getTaskManagementWorktypeProxy(clientConfig *platformclientv2.Configuration
}
// createTaskManagementWorktype creates a Genesys Cloud task management worktype
-func (p *taskManagementWorktypeProxy) createTaskManagementWorktype(ctx context.Context, taskManagementWorktype *platformclientv2.Worktypecreate) (*platformclientv2.Worktype, *platformclientv2.APIResponse, error) {
+func (p *TaskManagementWorktypeProxy) createTaskManagementWorktype(ctx context.Context, taskManagementWorktype *platformclientv2.Worktypecreate) (*platformclientv2.Worktype, *platformclientv2.APIResponse, error) {
return p.createTaskManagementWorktypeAttr(ctx, p, taskManagementWorktype)
}
-// getTaskManagementWorktype retrieves all Genesys Cloud task management worktype
-func (p *taskManagementWorktypeProxy) getAllTaskManagementWorktype(ctx context.Context) (*[]platformclientv2.Worktype, *platformclientv2.APIResponse, error) {
+// GetAllTaskManagementWorktype retrieves all Genesys Cloud task management worktype
+func (p *TaskManagementWorktypeProxy) GetAllTaskManagementWorktype(ctx context.Context) (*[]platformclientv2.Worktype, *platformclientv2.APIResponse, error) {
return p.getAllTaskManagementWorktypeAttr(ctx, p)
}
// getTaskManagementWorktypeIdByName returns a single Genesys Cloud task management worktype by a name
-func (p *taskManagementWorktypeProxy) getTaskManagementWorktypeIdByName(ctx context.Context, name string) (id string, retryable bool, resp *platformclientv2.APIResponse, err error) {
+func (p *TaskManagementWorktypeProxy) getTaskManagementWorktypeIdByName(ctx context.Context, name string) (id string, retryable bool, resp *platformclientv2.APIResponse, err error) {
return p.getTaskManagementWorktypeIdByNameAttr(ctx, p, name)
}
// getTaskManagementWorktypeByName returns a single Genesys Cloud task management worktype by a name
-func (p *taskManagementWorktypeProxy) getTaskManagementWorktypeByName(ctx context.Context, name string) (workItemType *platformclientv2.Worktype, retryable bool, resp *platformclientv2.APIResponse, err error) {
+func (p *TaskManagementWorktypeProxy) getTaskManagementWorktypeByName(ctx context.Context, name string) (workItemType *platformclientv2.Worktype, retryable bool, resp *platformclientv2.APIResponse, err error) {
return p.getTaskManagementWorktypeByNameAttr(ctx, p, name)
}
-// getTaskManagementWorktypeById returns a single Genesys Cloud task management worktype by Id
-func (p *taskManagementWorktypeProxy) getTaskManagementWorktypeById(ctx context.Context, id string) (taskManagementWorktype *platformclientv2.Worktype, resp *platformclientv2.APIResponse, err error) {
+// GetTaskManagementWorktypeById returns a single Genesys Cloud task management worktype by Id
+func (p *TaskManagementWorktypeProxy) GetTaskManagementWorktypeById(ctx context.Context, id string) (taskManagementWorktype *platformclientv2.Worktype, resp *platformclientv2.APIResponse, err error) {
return p.getTaskManagementWorktypeByIdAttr(ctx, p, id)
}
-// updateTaskManagementWorktype updates a Genesys Cloud task management worktype
-func (p *taskManagementWorktypeProxy) updateTaskManagementWorktype(ctx context.Context, id string, taskManagementWorktype *platformclientv2.Worktypeupdate) (*platformclientv2.Worktype, *platformclientv2.APIResponse, error) {
+// UpdateTaskManagementWorktype updates a Genesys Cloud task management worktype
+func (p *TaskManagementWorktypeProxy) UpdateTaskManagementWorktype(ctx context.Context, id string, taskManagementWorktype *platformclientv2.Worktypeupdate) (*platformclientv2.Worktype, *platformclientv2.APIResponse, error) {
return p.updateTaskManagementWorktypeAttr(ctx, p, id, taskManagementWorktype)
}
// deleteTaskManagementWorktype deletes a Genesys Cloud task management worktype by Id
-func (p *taskManagementWorktypeProxy) deleteTaskManagementWorktype(ctx context.Context, id string) (resp *platformclientv2.APIResponse, err error) {
+func (p *TaskManagementWorktypeProxy) deleteTaskManagementWorktype(ctx context.Context, id string) (resp *platformclientv2.APIResponse, err error) {
return p.deleteTaskManagementWorktypeAttr(ctx, p, id)
}
-// createTaskManagementWorktypeStatus creates a Genesys Cloud task management worktype status
-func (p *taskManagementWorktypeProxy) createTaskManagementWorktypeStatus(ctx context.Context, worktypeId string, status *platformclientv2.Workitemstatuscreate) (*platformclientv2.Workitemstatus, *platformclientv2.APIResponse, error) {
- return p.createTaskManagementWorktypeStatusAttr(ctx, p, worktypeId, status)
-}
-
-// updateTaskManagementWorktypeStatus updates a Genesys Cloud task management worktype status
-func (p *taskManagementWorktypeProxy) updateTaskManagementWorktypeStatus(ctx context.Context, worktypeId string, statusId string, statusUpdate *platformclientv2.Workitemstatusupdate) (*platformclientv2.Workitemstatus, *platformclientv2.APIResponse, error) {
- return p.updateTaskManagementWorktypeStatusAttr(ctx, p, worktypeId, statusId, statusUpdate)
-}
-
-// deleteTaskManagementWorktypeStatus deletes a Genesys Cloud task management worktype status by Id
-func (p *taskManagementWorktypeProxy) deleteTaskManagementWorktypeStatus(ctx context.Context, worktypeId string, statusId string) (response *platformclientv2.APIResponse, err error) {
- return p.deleteTaskManagementWorktypeStatusAttr(ctx, p, worktypeId, statusId)
-}
-
// createTaskManagementWorktypeFn is an implementation function for creating a Genesys Cloud task management worktype
-func createTaskManagementWorktypeFn(ctx context.Context, p *taskManagementWorktypeProxy, taskManagementWorktype *platformclientv2.Worktypecreate) (*platformclientv2.Worktype, *platformclientv2.APIResponse, error) {
- log.Printf("Creating task management worktype: %s", *taskManagementWorktype.Name)
- worktype, resp, err := p.taskManagementApi.PostTaskmanagementWorktypes(*taskManagementWorktype)
- log.Printf("Completed call to create task management worktype %s with status code %d, correlation id %s and err %s", *taskManagementWorktype.Name, resp.StatusCode, resp.CorrelationID, err)
- if err != nil {
- return nil, resp, fmt.Errorf("failed to create task management worktype: %s", err)
- }
- return worktype, resp, nil
+func createTaskManagementWorktypeFn(ctx context.Context, p *TaskManagementWorktypeProxy, taskManagementWorktype *platformclientv2.Worktypecreate) (*platformclientv2.Worktype, *platformclientv2.APIResponse, error) {
+ return p.taskManagementApi.PostTaskmanagementWorktypes(*taskManagementWorktype)
}
// getAllTaskManagementWorktypeFn is the implementation for retrieving all task management worktype in Genesys Cloud
-func getAllTaskManagementWorktypeFn(ctx context.Context, p *taskManagementWorktypeProxy) (*[]platformclientv2.Worktype, *platformclientv2.APIResponse, error) {
+func getAllTaskManagementWorktypeFn(ctx context.Context, p *TaskManagementWorktypeProxy) (*[]platformclientv2.Worktype, *platformclientv2.APIResponse, error) {
var allWorktypes []platformclientv2.Worktype
pageSize := 200
after := ""
@@ -164,8 +135,8 @@ func getAllTaskManagementWorktypeFn(ctx context.Context, p *taskManagementWorkty
return &allWorktypes, response, nil
}
-// Looksup a worktype by name
-func getWorkType(name string, p *taskManagementWorktypeProxy) (*platformclientv2.Worktype, bool, *platformclientv2.APIResponse, error) {
+// getWorkType looks up a worktype by name
+func getWorkType(name string, p *TaskManagementWorktypeProxy) (*platformclientv2.Worktype, bool, *platformclientv2.APIResponse, error) {
pageSize := 100
filterType := "String"
@@ -205,7 +176,7 @@ func getWorkType(name string, p *taskManagementWorktypeProxy) (*platformclientv2
}
// getTaskManagementWorktypeIdByNameFn is an implementation of the function to get a Genesys Cloud task management worktype by name
-func getTaskManagementWorktypeIdByNameFn(ctx context.Context, p *taskManagementWorktypeProxy, name string) (id string, retryable bool, resp *platformclientv2.APIResponse, err error) {
+func getTaskManagementWorktypeIdByNameFn(ctx context.Context, p *TaskManagementWorktypeProxy, name string) (id string, retryable bool, resp *platformclientv2.APIResponse, err error) {
worktype, retry, resp, err := getWorkType(name, p)
if err != nil {
return "", retry, resp, err
@@ -216,7 +187,7 @@ func getTaskManagementWorktypeIdByNameFn(ctx context.Context, p *taskManagementW
}
// getTaskManagementWorktypeByNameFn Retrieves the full worktype item rather than just the id
-func getTaskManagementWorktypeByNameFn(ctx context.Context, p *taskManagementWorktypeProxy, name string) (workItemType *platformclientv2.Worktype, retryable bool, resp *platformclientv2.APIResponse, err error) {
+func getTaskManagementWorktypeByNameFn(ctx context.Context, p *TaskManagementWorktypeProxy, name string) (workItemType *platformclientv2.Worktype, retryable bool, resp *platformclientv2.APIResponse, err error) {
worktype, retry, resp, err := getWorkType(name, p)
if err != nil {
return nil, retry, resp, err
@@ -227,55 +198,21 @@ func getTaskManagementWorktypeByNameFn(ctx context.Context, p *taskManagementWor
}
// getTaskManagementWorktypeByIdFn is an implementation of the function to get a Genesys Cloud task management worktype by Id
-func getTaskManagementWorktypeByIdFn(ctx context.Context, p *taskManagementWorktypeProxy, id string) (taskManagementWorktype *platformclientv2.Worktype, resp *platformclientv2.APIResponse, err error) {
- worktype, resp, err := p.taskManagementApi.GetTaskmanagementWorktype(id, []string{})
- if err != nil {
- return nil, resp, fmt.Errorf("failed to retrieve task management worktype by id %s: %s", id, err)
+func getTaskManagementWorktypeByIdFn(ctx context.Context, p *TaskManagementWorktypeProxy, id string) (taskManagementWorktype *platformclientv2.Worktype, resp *platformclientv2.APIResponse, err error) {
+ worktype := rc.GetCacheItem(p.worktypeCache, id)
+ if worktype != nil {
+ return worktype, nil, nil
}
- return worktype, resp, nil
+
+ return p.taskManagementApi.GetTaskmanagementWorktype(id, []string{})
}
// updateTaskManagementWorktypeFn is an implementation of the function to update a Genesys Cloud task management worktype
-func updateTaskManagementWorktypeFn(ctx context.Context, p *taskManagementWorktypeProxy, id string, worktypeUpdate *platformclientv2.Worktypeupdate) (*platformclientv2.Worktype, *platformclientv2.APIResponse, error) {
- worktype, resp, err := p.taskManagementApi.PatchTaskmanagementWorktype(id, *worktypeUpdate)
- if err != nil {
- return nil, resp, fmt.Errorf("failed to update task management worktype %s: %v", id, err)
- }
- return worktype, resp, nil
+func updateTaskManagementWorktypeFn(ctx context.Context, p *TaskManagementWorktypeProxy, id string, worktypeUpdate *platformclientv2.Worktypeupdate) (*platformclientv2.Worktype, *platformclientv2.APIResponse, error) {
+ return p.taskManagementApi.PatchTaskmanagementWorktype(id, *worktypeUpdate)
}
// deleteTaskManagementWorktypeFn is an implementation function for deleting a Genesys Cloud task management worktype
-func deleteTaskManagementWorktypeFn(ctx context.Context, p *taskManagementWorktypeProxy, id string) (resp *platformclientv2.APIResponse, err error) {
- resp, err = p.taskManagementApi.DeleteTaskmanagementWorktype(id)
- if err != nil {
- return resp, fmt.Errorf("failed to delete task management worktype %s: %v", id, err)
- }
- return resp, nil
-}
-
-// createTaskManagementWorktypeStatusFn is an implementation function for creating a Genesys Cloud task management worktype status
-func createTaskManagementWorktypeStatusFn(ctx context.Context, p *taskManagementWorktypeProxy, worktypeId string, status *platformclientv2.Workitemstatuscreate) (*platformclientv2.Workitemstatus, *platformclientv2.APIResponse, error) {
- wtStatus, resp, err := p.taskManagementApi.PostTaskmanagementWorktypeStatuses(worktypeId, *status)
- if err != nil {
- return nil, resp, fmt.Errorf("failed to create task management worktype status: %s. For worktype: %s", err, worktypeId)
- }
- return wtStatus, resp, nil
-}
-
-// updateTaskManagementWorktypeStatusFn is an implementation of the function to update a Genesys Cloud task management worktype status
-func updateTaskManagementWorktypeStatusFn(ctx context.Context, p *taskManagementWorktypeProxy, worktypeId string, statusId string, statusUpdate *platformclientv2.Workitemstatusupdate) (*platformclientv2.Workitemstatus, *platformclientv2.APIResponse, error) {
- wtStatus, resp, err := p.taskManagementApi.PatchTaskmanagementWorktypeStatus(worktypeId, statusId, *statusUpdate)
- if err != nil {
- return nil, resp, fmt.Errorf("failed to update task management worktype status: %s. For worktype: %s", err, worktypeId)
- }
- return wtStatus, resp, nil
-}
-
-// deleteTaskManagementWorktypeStatusFn is an implementation function for deleting a Genesys Cloud task management worktype status
-func deleteTaskManagementWorktypeStatusFn(ctx context.Context, p *taskManagementWorktypeProxy, worktypeId string, statusId string) (response *platformclientv2.APIResponse, err error) {
- resp, err := p.taskManagementApi.DeleteTaskmanagementWorktypeStatus(worktypeId, statusId)
- if err != nil {
- return resp, fmt.Errorf("failed to delete task management worktype status %s: %v", statusId, err)
- }
- return resp, nil
+func deleteTaskManagementWorktypeFn(ctx context.Context, p *TaskManagementWorktypeProxy, id string) (resp *platformclientv2.APIResponse, err error) {
+ return p.taskManagementApi.DeleteTaskmanagementWorktype(id)
}
diff --git a/genesyscloud/task_management_worktype/resource_genesyscloud_task_management_worktype.go b/genesyscloud/task_management_worktype/resource_genesyscloud_task_management_worktype.go
index a322ff5c5..cae48d89b 100644
--- a/genesyscloud/task_management_worktype/resource_genesyscloud_task_management_worktype.go
+++ b/genesyscloud/task_management_worktype/resource_genesyscloud_task_management_worktype.go
@@ -10,14 +10,12 @@ import (
"terraform-provider-genesyscloud/genesyscloud/util/constants"
"time"
- "github.com/google/uuid"
"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/lists"
"terraform-provider-genesyscloud/genesyscloud/util/resourcedata"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
@@ -29,10 +27,10 @@ The resource_genesyscloud_task_management_worktype.go contains all of the method
// getAllAuthTaskManagementWorktype retrieves all of the task management worktype via Terraform in the Genesys Cloud and is used for the exporter
func getAllAuthTaskManagementWorktypes(ctx context.Context, clientConfig *platformclientv2.Configuration) (resourceExporter.ResourceIDMetaMap, diag.Diagnostics) {
- proxy := getTaskManagementWorktypeProxy(clientConfig)
+ proxy := GetTaskManagementWorktypeProxy(clientConfig)
resources := make(resourceExporter.ResourceIDMetaMap)
- worktypes, resp, err := proxy.getAllTaskManagementWorktype(ctx)
+ worktypes, resp, err := proxy.GetAllTaskManagementWorktype(ctx)
if err != nil {
return nil, util.BuildAPIDiagnosticError(resourceName, fmt.Sprintf("Failed to get task management worktype error: %s", err), resp)
}
@@ -46,7 +44,7 @@ func getAllAuthTaskManagementWorktypes(ctx context.Context, clientConfig *platfo
// createTaskManagementWorktype is used by the task_management_worktype resource to create Genesys cloud task management worktype
func createTaskManagementWorktype(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
sdkConfig := meta.(*provider.ProviderMeta).ClientConfig
- proxy := getTaskManagementWorktypeProxy(sdkConfig)
+ proxy := GetTaskManagementWorktypeProxy(sdkConfig)
taskManagementWorktype := getWorktypecreateFromResourceData(d)
@@ -60,40 +58,19 @@ func createTaskManagementWorktype(ctx context.Context, d *schema.ResourceData, m
log.Printf("Created the base task management worktype %s", *worktype.Id)
d.SetId(*worktype.Id)
- // Create and update (for referencing other status) the worktype statuses
- log.Printf("Creating the task management worktype statuses of %s", *worktype.Id)
- statuses := d.Get("statuses").(*schema.Set).List()
- if _, err := createWorktypeStatuses(ctx, proxy, *worktype.Id, statuses); err != nil {
- return util.BuildDiagnosticError(resourceName, fmt.Sprintf("failed to create task management worktype statuses"), err)
- }
- log.Printf("Updating the destination statuses of the statuses of worktype %s", *worktype.Id)
- if _, err := updateWorktypeStatuses(ctx, proxy, *worktype.Id, statuses, true); err != nil {
- return util.BuildDiagnosticError(resourceName, fmt.Sprintf("failed to update task management worktype statuses"), err)
- }
-
- // Update the worktype if 'default_status_name' is set
- if d.HasChange("default_status_name") {
- time.Sleep(5 * time.Second)
- err := updateDefaultStatusName(ctx, proxy, d, *worktype.Id)
- if err != nil {
- return util.BuildDiagnosticError(resourceName, fmt.Sprintf("failed to update default status name of worktype"), err)
- }
- }
-
- log.Printf("Created the task management worktype statuses of %s", *worktype.Id)
return readTaskManagementWorktype(ctx, d, meta)
}
// readTaskManagementWorktype is used by the task_management_worktype resource to read a task management worktype from genesys cloud
func readTaskManagementWorktype(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
sdkConfig := meta.(*provider.ProviderMeta).ClientConfig
- proxy := getTaskManagementWorktypeProxy(sdkConfig)
+ proxy := GetTaskManagementWorktypeProxy(sdkConfig)
cc := consistency_checker.NewConsistencyCheck(ctx, d, meta, ResourceTaskManagementWorktype(), constants.DefaultConsistencyChecks, resourceName)
log.Printf("Reading task management worktype %s", d.Id())
return util.WithRetriesForRead(ctx, d, func() *retry.RetryError {
- worktype, resp, getErr := proxy.getTaskManagementWorktypeById(ctx, d.Id())
+ worktype, resp, getErr := proxy.GetTaskManagementWorktypeById(ctx, d.Id())
if getErr != nil {
if util.IsStatus404(resp) {
return retry.RetryableError(util.BuildWithRetriesApiDiagnosticError(resourceName, fmt.Sprintf("failed to read task management worktype %s | error: %s", d.Id(), getErr), resp))
@@ -109,14 +86,6 @@ func readTaskManagementWorktype(ctx context.Context, d *schema.ResourceData, met
resourcedata.SetNillableValue(d, "default_workbin_id", worktype.DefaultWorkbin.Id)
}
- // Default status can be an empty object
- if worktype.DefaultStatus != nil && worktype.DefaultStatus.Id != nil {
- if statusName := getStatusNameFromId(*worktype.DefaultStatus.Id, worktype.Statuses); statusName != nil {
- d.Set("default_status_name", statusName)
- }
- }
- resourcedata.SetNillableValueWithInterfaceArrayWithFunc(d, "statuses", worktype.Statuses, flattenWorkitemStatuses)
-
resourcedata.SetNillableValue(d, "default_duration_seconds", worktype.DefaultDurationSeconds)
resourcedata.SetNillableValue(d, "default_expiration_seconds", worktype.DefaultExpirationSeconds)
resourcedata.SetNillableValue(d, "default_due_duration_seconds", worktype.DefaultDueDurationSeconds)
@@ -146,121 +115,18 @@ func readTaskManagementWorktype(ctx context.Context, d *schema.ResourceData, met
// updateTaskManagementWorktype is used by the task_management_worktype resource to update a task management worktype in Genesys Cloud
func updateTaskManagementWorktype(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
sdkConfig := meta.(*provider.ProviderMeta).ClientConfig
- proxy := getTaskManagementWorktypeProxy(sdkConfig)
+ proxy := GetTaskManagementWorktypeProxy(sdkConfig)
// Update the base configuration of the Worktype
- taskManagementWorktype := getWorktypeupdateFromResourceData(d, nil)
- if d.HasChangesExcept("statuses", "default_status_name") {
- worktype, resp, err := proxy.updateTaskManagementWorktype(ctx, d.Id(), &taskManagementWorktype)
- if err != nil {
- return util.BuildAPIDiagnosticError(resourceName, fmt.Sprintf("Failed to update task management worktype %s error: %s", *taskManagementWorktype.Name, err), resp)
- }
- log.Printf("Updated base configuration of task management worktype %s", *worktype.Id)
- }
+ taskManagementWorktype := getWorktypeupdateFromResourceData(d)
- // Get the current state of the worktype because we will cross-check if any of the existing ones
- // need to be deleted
- oldWorktype, resp, err := proxy.getTaskManagementWorktypeById(ctx, d.Id())
+ log.Printf("Updating worktype %s %s", d.Id(), *taskManagementWorktype.Name)
+ _, resp, err := proxy.UpdateTaskManagementWorktype(ctx, d.Id(), &taskManagementWorktype)
if err != nil {
- return util.BuildAPIDiagnosticError(resourceName, fmt.Sprintf("Failed to get task management worktype %s error: %s", d.Id(), err), resp)
- }
- oldStatusIds := []string{}
- for _, oldStatus := range *oldWorktype.Statuses {
- oldStatusIds = append(oldStatusIds, *oldStatus.Id)
- }
-
- // We'll use this to keep track of the actual status ids as a result of the worktype update.
- // Any ids not here will be deleted eventually as the last step.
- statusIdsToStay := []string{}
-
- statuses := d.Get("statuses").(*schema.Set).List()
-
- // If the status in the state still has an id that means there is no update to it and so should not be included
- // in the API update (GC API gives error if update is called but actually no diff).
- forUpdateOrCreation := make([]interface{}, 0)
- for _, status := range statuses {
- statusMap := status.(map[string]interface{})
- if statusMap["id"] == "" {
- forUpdateOrCreation = append(forUpdateOrCreation, status)
- } else {
- statusIdsToStay = append(statusIdsToStay, statusMap["id"].(string))
- }
- }
- forCreation, forUpdate := getStatusesForUpdateAndCreation(forUpdateOrCreation, oldWorktype.Statuses)
-
- // Create new statuses
- log.Printf("Creating the task management worktype statuses of %s", d.Id())
- if _, err := createWorktypeStatuses(ctx, proxy, d.Id(), forCreation); err != nil {
- return util.BuildDiagnosticError(resourceName, fmt.Sprintf("failed to create task management worktype statuses"), err)
- }
-
- // Update the newly created statuses with status refs
- log.Printf("Updating the newly created statuses of worktype %s", d.Id())
- createdStatuses, err := updateWorktypeStatuses(ctx, proxy, d.Id(), forCreation, true)
- if err != nil {
- return util.BuildDiagnosticError(resourceName, fmt.Sprintf("failed to update task management worktype statuses"), err)
- }
- for _, updateStat := range *createdStatuses {
- statusIdsToStay = append(statusIdsToStay, *updateStat.Id)
- }
-
- // Update the other already existing statuses for reference or other property updates
- log.Printf("Updating the destination statuses of the statuses of worktype %s", d.Id())
- updatedStatuses, err := updateWorktypeStatuses(ctx, proxy, d.Id(), forUpdate, false)
- if err != nil {
- return util.BuildDiagnosticError(resourceName, fmt.Sprintf("failed to update task management worktype statuses"), err)
- }
- for _, updateStat := range *updatedStatuses {
- statusIdsToStay = append(statusIdsToStay, *updateStat.Id)
- }
-
- // Delete statuses that are no longer defined in the configuration
- log.Printf("Cleaning up statuses of worktype %s", d.Id())
- forDeletionIds := lists.SliceDifference(oldStatusIds, statusIdsToStay)
-
- // Go through and clear the status references first to avoid dependency errors on deletion
- log.Printf("Clearing references of statuses for deletion of worktype %s", d.Id())
- for _, forDeletionId := range forDeletionIds {
- updateForCleaning := platformclientv2.Workitemstatusupdate{}
-
- // // Force these properties as 'null' for the API request
- updateForCleaning.SetField("DestinationStatusIds", &[]string{})
- updateForCleaning.SetField("DefaultDestinationStatusId", nil)
- updateForCleaning.SetField("StatusTransitionDelaySeconds", nil)
- updateForCleaning.SetField("StatusTransitionTime", nil)
-
- // We put a random description so we can ensure there is a 'change' in the status.
- // Else we'll get a 400 error if the status has no destination status /default status to begin with
- // This is simpler than checking the status fields if there are any changes.
- // Since this status is for deletion anyway we shouldn't care about this managed update.
- description := "this status is set for deletion by CX as Code " + uuid.NewString()
- updateForCleaning.SetField("Description", &description)
-
- if _, resp, err := proxy.updateTaskManagementWorktypeStatus(ctx, d.Id(), forDeletionId, &updateForCleaning); err != nil {
- return util.BuildAPIDiagnosticError(resourceName, fmt.Sprintf("Failed to clean up references of task management worktype status %s error: %s", d.Id(), err), resp)
- }
- }
-
- // Actually delete the status
- log.Printf("Deleting unused statuses of worktype %s", d.Id())
- for _, forDeletionId := range forDeletionIds {
- if resp, err := proxy.deleteTaskManagementWorktypeStatus(ctx, d.Id(), forDeletionId); err != nil {
- return util.BuildAPIDiagnosticError(resourceName, fmt.Sprintf("Failed to delete task management worktype status %s error: %s", forDeletionId, err), resp)
- }
- }
-
- // Update the worktype if 'default_status_name' is changed
- // We do this last so that the statuses are surely updated first
- if d.HasChange("default_status_name") {
- log.Printf("Updating default status of worktype %s", d.Id())
- time.Sleep(5 * time.Second)
- err := updateDefaultStatusName(ctx, proxy, d, d.Id())
- if err != nil {
- return util.BuildDiagnosticError(resourceName, fmt.Sprintf("failed to update default status name of worktype"), err)
- }
+ return util.BuildAPIDiagnosticError(resourceName, fmt.Sprintf("Failed to update task management worktype %s error: %s", *taskManagementWorktype.Name, err), resp)
}
- log.Printf("Finished updating worktype %s", d.Id())
+ log.Printf("Updated worktype %s %s", d.Id(), *taskManagementWorktype.Name)
return readTaskManagementWorktype(ctx, d, meta)
}
@@ -268,7 +134,7 @@ func updateTaskManagementWorktype(ctx context.Context, d *schema.ResourceData, m
// deleteTaskManagementWorktype is used by the task_management_worktype resource to delete a task management worktype from Genesys cloud
func deleteTaskManagementWorktype(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
sdkConfig := meta.(*provider.ProviderMeta).ClientConfig
- proxy := getTaskManagementWorktypeProxy(sdkConfig)
+ proxy := GetTaskManagementWorktypeProxy(sdkConfig)
resp, err := proxy.deleteTaskManagementWorktype(ctx, d.Id())
if err != nil {
@@ -276,7 +142,7 @@ func deleteTaskManagementWorktype(ctx context.Context, d *schema.ResourceData, m
}
return util.WithRetries(ctx, 180*time.Second, func() *retry.RetryError {
- _, resp, err := proxy.getTaskManagementWorktypeById(ctx, d.Id())
+ _, resp, err := proxy.GetTaskManagementWorktypeById(ctx, d.Id())
if err != nil {
if util.IsStatus404(resp) {
diff --git a/genesyscloud/task_management_worktype/resource_genesyscloud_task_management_worktype_schema.go b/genesyscloud/task_management_worktype/resource_genesyscloud_task_management_worktype_schema.go
index 35ea54fce..5edfa61e0 100644
--- a/genesyscloud/task_management_worktype/resource_genesyscloud_task_management_worktype_schema.go
+++ b/genesyscloud/task_management_worktype/resource_genesyscloud_task_management_worktype_schema.go
@@ -2,12 +2,10 @@ package task_management_worktype
import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
+ "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"terraform-provider-genesyscloud/genesyscloud/provider"
resourceExporter "terraform-provider-genesyscloud/genesyscloud/resource_exporter"
registrar "terraform-provider-genesyscloud/genesyscloud/resource_register"
- "terraform-provider-genesyscloud/genesyscloud/validators"
-
- "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
)
/*
@@ -19,69 +17,16 @@ resource_genesycloud_task_management_worktype_schema.go holds four functions wit
4. The resource exporter configuration for the task_management_worktype exporter.
*/
const resourceName = "genesyscloud_task_management_worktype"
-const worktypeStatusDataSourceName = "genesyscloud_task_management_worktype_status"
// SetRegistrar registers all of the resources, datasources and exporters in the package
func SetRegistrar(regInstance registrar.Registrar) {
regInstance.RegisterResource(resourceName, ResourceTaskManagementWorktype())
regInstance.RegisterDataSource(resourceName, DataSourceTaskManagementWorktype())
- regInstance.RegisterDataSource(worktypeStatusDataSourceName, DataSourceTaskManagementWorktypeStatus())
regInstance.RegisterExporter(resourceName, TaskManagementWorktypeExporter())
}
// ResourceTaskManagementWorktype registers the genesyscloud_task_management_worktype resource with Terraform
func ResourceTaskManagementWorktype() *schema.Resource {
- workitemStatusResource := &schema.Resource{
- Schema: map[string]*schema.Schema{
- `id`: {
- Description: `Read-only identifier of the workitem status`,
- Computed: true,
- Type: schema.TypeString,
- },
- `name`: {
- Description: `Name of the status`,
- Required: true,
- Type: schema.TypeString,
- },
- `description`: {
- Description: `The description of the Status.`,
- Optional: true,
- Type: schema.TypeString,
- },
- `category`: {
- Description: `The Category of the Status.`,
- Required: true,
- Type: schema.TypeString,
- ValidateFunc: validation.StringInSlice([]string{"Open", "InProgress", "Waiting", "Closed"}, false),
- },
- `destination_status_names`: {
- Description: `The names of the Statuses the Status can transition to. If null, the status can transition to any other status.`,
- Optional: true,
- Type: schema.TypeList,
- Elem: &schema.Schema{Type: schema.TypeString},
- },
- `default_destination_status_name`: {
- Description: `Name of the default destination status to which this Status will transition to if auto status transition enabled.`,
- Optional: true,
- Type: schema.TypeString,
- },
- `status_transition_delay_seconds`: {
- Description: `Delay in seconds for auto status transition`,
- Optional: true,
- Computed: true,
- Type: schema.TypeInt,
- ValidateFunc: validation.IntAtLeast(60),
- },
- `status_transition_time`: {
- Description: `Time (HH:MM:SS format) at which auto status transition will occur after statusTransitionDelaySeconds delay. To set Time, the statusTransitionDelaySeconds must be equal to or greater than 86400 i.e. a day`,
- Optional: true,
- Computed: true,
- Type: schema.TypeString,
- ValidateDiagFunc: validators.ValidateTime,
- },
- },
- }
-
return &schema.Resource{
Description: `Genesys Cloud task management worktype`,
@@ -110,17 +55,6 @@ func ResourceTaskManagementWorktype() *schema.Resource {
Computed: true,
Type: schema.TypeString,
},
- `statuses`: {
- Description: `The list of possible statuses for Workitems created from the Worktype.`,
- Optional: true,
- Type: schema.TypeSet,
- Elem: workitemStatusResource,
- },
- `default_status_name`: {
- Description: `The name of the default status for Workitems created from the Worktype. This status should be defined in 'statuses'.`,
- Optional: true,
- Type: schema.TypeString,
- },
`default_workbin_id`: {
Description: `The default Workbin for Workitems created from the Worktype.`,
Required: true,
@@ -205,7 +139,6 @@ func TaskManagementWorktypeExporter() *resourceExporter.ResourceExporter {
"default_skills_ids": {RefType: "genesyscloud_routing_skill"},
"schema_id": {RefType: "genesyscloud_task_management_workitem_schema"},
},
- ExcludedAttributes: []string{"statuses.id"},
}
}
@@ -226,26 +159,3 @@ func DataSourceTaskManagementWorktype() *schema.Resource {
},
}
}
-
-// DataSourceTaskManagementWorktypeStatus registers the genesyscloud_task_management_worktype_status data source
-func DataSourceTaskManagementWorktypeStatus() *schema.Resource {
- return &schema.Resource{
- Description: `Genesys Cloud task management worktype_status data source. Select a status by worktype name and status name`,
- ReadContext: provider.ReadWithPooledClient(dataSourceTaskManagementWorktypeStatusRead),
- Importer: &schema.ResourceImporter{
- StateContext: schema.ImportStatePassthroughContext,
- },
- Schema: map[string]*schema.Schema{
- "worktype_name": {
- Description: `Task management worktype name`,
- Type: schema.TypeString,
- Required: true,
- },
- "worktype_status_name": {
- Description: `Task management worktype status name`,
- Type: schema.TypeString,
- Required: true,
- },
- },
- }
-}
diff --git a/genesyscloud/task_management_worktype/resource_genesyscloud_task_management_worktype_test.go b/genesyscloud/task_management_worktype/resource_genesyscloud_task_management_worktype_test.go
index 12a109adb..2b5d166bf 100644
--- a/genesyscloud/task_management_worktype/resource_genesyscloud_task_management_worktype_test.go
+++ b/genesyscloud/task_management_worktype/resource_genesyscloud_task_management_worktype_test.go
@@ -2,19 +2,17 @@ package task_management_worktype
import (
"fmt"
- "regexp"
- "strconv"
- "strings"
"terraform-provider-genesyscloud/genesyscloud/provider"
routingLanguage "terraform-provider-genesyscloud/genesyscloud/routing_language"
routingQueue "terraform-provider-genesyscloud/genesyscloud/routing_queue"
+ routingSkill "terraform-provider-genesyscloud/genesyscloud/routing_skill"
+
"terraform-provider-genesyscloud/genesyscloud/util"
"testing"
"github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
- gcloud "terraform-provider-genesyscloud/genesyscloud"
workbin "terraform-provider-genesyscloud/genesyscloud/task_management_workbin"
workitemSchema "terraform-provider-genesyscloud/genesyscloud/task_management_workitem_schema"
@@ -27,7 +25,7 @@ The resource_genesyscloud_task_management_worktype_test.go contains all of the t
tests for task_management_worktype.
*/
-// Basic test with create and update excluding workitem statusses
+// Basic test with create and update
func TestAccResourceTaskManagementWorktype(t *testing.T) {
t.Parallel()
var (
@@ -66,10 +64,6 @@ func TestAccResourceTaskManagementWorktype(t *testing.T) {
divisionId: fmt.Sprintf("data.genesyscloud_auth_division_home.%s.id", divData),
defaultWorkbinId: fmt.Sprintf("genesyscloud_task_management_workbin.%s.id", wbResourceId),
- // No statuses
- statuses: []worktypeStatusConfig{},
- defaultStatusName: "",
-
defaultDurationS: 86400,
defaultExpirationS: 86400,
defaultDueDurationS: 86400,
@@ -105,14 +99,14 @@ func TestAccResourceTaskManagementWorktype(t *testing.T) {
resource.TestCheckResourceAttrPair(resourceName+"."+wtRes.resID, "schema_id", fmt.Sprintf("genesyscloud_task_management_workitem_schema.%s", wsResourceId), "id"),
),
},
- // All optional properties update (except statuses)
+ // All optional properties update
{
Config: workbin.GenerateWorkbinResource(wbResourceId, wbName, wbDescription, util.NullValue) +
workitemSchema.GenerateWorkitemSchemaResourceBasic(wsResourceId, wsName, wsDescription) +
routingQueue.GenerateRoutingQueueResourceBasic(queueResId, queueName) +
routingLanguage.GenerateRoutingLanguageResource(langResId, langName) +
- gcloud.GenerateRoutingSkillResource(skillResId1, skillResName1) +
- gcloud.GenerateRoutingSkillResource(skillResId2, skillResName2) +
+ routingSkill.GenerateRoutingSkillResource(skillResId1, skillResName1) +
+ routingSkill.GenerateRoutingSkillResource(skillResId2, skillResName2) +
generateWorktypeResource(wtRes) +
fmt.Sprintf("\n data \"genesyscloud_auth_division_home\" \"%s\" {}\n", divData),
Check: resource.ComposeTestCheckFunc(
@@ -143,188 +137,6 @@ func TestAccResourceTaskManagementWorktype(t *testing.T) {
})
}
-func TestAccResourceTaskManagementWorktypeStatus(t *testing.T) {
- t.Parallel()
- var (
- // Workbin
- wbResourceId = "workbin_1"
- wbName = "wb_" + uuid.NewString()
- wbDescription = "workbin created for CX as Code test case"
-
- // Schema
- wsResourceId = "schema_1"
- wsName = "ws_" + uuid.NewString()
- wsDescription = "workitem schema created for CX as Code test case"
-
- // Worktype
- wtRes = worktypeConfig{
- resID: "worktype_1",
- name: "tf_worktype_" + uuid.NewString(),
- description: "worktype created for CX as Code test case",
- defaultWorkbinId: fmt.Sprintf("genesyscloud_task_management_workbin.%s.id", wbResourceId),
- schemaId: fmt.Sprintf("genesyscloud_task_management_workitem_schema.%s.id", wsResourceId),
-
- statuses: []worktypeStatusConfig{
- {
- name: "Open Status",
- description: "Description of open status",
- category: "Open",
- },
- {
- name: "Close Status",
- description: "Description of close status",
- category: "Closed",
- },
- },
- defaultStatusName: "Open Status",
- }
-
- // Updated statuses
- statusUpdates = worktypeConfig{
- statuses: []worktypeStatusConfig{
- {
- name: "Open Status",
- description: "Description of open status. Updated",
- defaultDestinationStatusName: "WIP",
- destinationStatusNames: []string{"WIP", "Waiting Status"},
- statusTransitionTime: "10:09:08",
- transitionDelay: 86500,
- category: "Open",
- },
- {
- name: "WIP",
- description: "Description of in progress status. Updated",
- category: "InProgress",
- },
- {
- name: "Waiting Status",
- description: "Description of waiting status. Updated",
- category: "Waiting",
- },
- {
- name: "Close Status",
- description: "Description of close status. Updated",
- category: "Closed",
- },
- },
- }
-
- // Updated statuses 2
- statusUpdates2 = worktypeConfig{
- statuses: []worktypeStatusConfig{
- {
- name: "Open Status",
- description: "Description of open status. Updated 2",
- defaultDestinationStatusName: "Close Status",
- transitionDelay: 300,
-
- category: "Open",
- },
- {
- name: "Close Status",
- description: "Description of close status. Updated 2",
- category: "Closed",
- },
- },
- }
- )
-
- resource.Test(t, resource.TestCase{
- PreCheck: func() { util.TestAccPreCheck(t) },
- ProviderFactories: provider.GetProviderFactories(providerResources, providerDataSources),
- Steps: []resource.TestStep{
- // Initial basic statuses
- {
- Config: workbin.GenerateWorkbinResource(wbResourceId, wbName, wbDescription, util.NullValue) +
- workitemSchema.GenerateWorkitemSchemaResourceBasic(wsResourceId, wsName, wsDescription) +
- GenerateWorktypeResourceBasic(wtRes.resID, wtRes.name, wtRes.description, wtRes.defaultWorkbinId, wtRes.schemaId, generateWorktypeAllStatuses(wtRes)),
- Check: resource.ComposeTestCheckFunc(
- resource.TestCheckResourceAttr(resourceName+"."+wtRes.resID, "name", wtRes.name),
- resource.TestCheckResourceAttr(resourceName+"."+wtRes.resID, "description", wtRes.description),
- resource.TestCheckResourceAttrPair(resourceName+"."+wtRes.resID, "default_workbin_id", fmt.Sprintf("genesyscloud_task_management_workbin.%s", wbResourceId), "id"),
- resource.TestCheckResourceAttrPair(resourceName+"."+wtRes.resID, "schema_id", fmt.Sprintf("genesyscloud_task_management_workitem_schema.%s", wsResourceId), "id"),
-
- resource.TestCheckResourceAttr(resourceName+"."+wtRes.resID, "statuses.#", fmt.Sprintf("%v", len(wtRes.statuses))),
- resource.TestMatchTypeSetElemNestedAttrs(resourceName+"."+wtRes.resID, "statuses.*", map[string]*regexp.Regexp{
- "name": regexp.MustCompile(wtRes.statuses[0].name),
- "description": regexp.MustCompile(wtRes.statuses[0].description),
- "category": regexp.MustCompile(wtRes.statuses[0].category),
- }),
- resource.TestMatchTypeSetElemNestedAttrs(resourceName+"."+wtRes.resID, "statuses.*", map[string]*regexp.Regexp{
- "name": regexp.MustCompile(wtRes.statuses[1].name),
- "description": regexp.MustCompile(wtRes.statuses[1].description),
- "category": regexp.MustCompile(wtRes.statuses[1].category),
- }),
- ),
- },
- // Add statuses and destination references
- {
- Config: workbin.GenerateWorkbinResource(wbResourceId, wbName, wbDescription, util.NullValue) +
- workitemSchema.GenerateWorkitemSchemaResourceBasic(wsResourceId, wsName, wsDescription) +
- GenerateWorktypeResourceBasic(wtRes.resID, wtRes.name, wtRes.description, wtRes.defaultWorkbinId, wtRes.schemaId, generateWorktypeAllStatuses(statusUpdates)),
- Check: resource.ComposeTestCheckFunc(
- resource.TestCheckResourceAttr(resourceName+"."+wtRes.resID, "name", wtRes.name),
- resource.TestCheckResourceAttr(resourceName+"."+wtRes.resID, "description", wtRes.description),
- resource.TestCheckResourceAttrPair(resourceName+"."+wtRes.resID, "default_workbin_id", fmt.Sprintf("genesyscloud_task_management_workbin.%s", wbResourceId), "id"),
- resource.TestCheckResourceAttrPair(resourceName+"."+wtRes.resID, "schema_id", fmt.Sprintf("genesyscloud_task_management_workitem_schema.%s", wsResourceId), "id"),
-
- resource.TestCheckResourceAttr(resourceName+"."+wtRes.resID, "statuses.#", fmt.Sprintf("%v", len(statusUpdates.statuses))),
- resource.TestMatchTypeSetElemNestedAttrs(resourceName+"."+wtRes.resID, "statuses.*", map[string]*regexp.Regexp{
- "name": regexp.MustCompile(statusUpdates.statuses[0].name),
- "description": regexp.MustCompile(statusUpdates.statuses[0].description),
- "category": regexp.MustCompile(statusUpdates.statuses[0].category),
- "default_destination_status_name": regexp.MustCompile(statusUpdates.statuses[0].defaultDestinationStatusName),
- "status_transition_delay_seconds": regexp.MustCompile(fmt.Sprintf("%v", statusUpdates.statuses[0].transitionDelay)),
- "status_transition_time": regexp.MustCompile(fmt.Sprintf("%v", statusUpdates.statuses[0].statusTransitionTime)),
- "destination_status_names.0": regexp.MustCompile(statusUpdates.statuses[0].destinationStatusNames[0]),
- "destination_status_names.1": regexp.MustCompile(statusUpdates.statuses[0].destinationStatusNames[1]),
- }),
- resource.TestMatchTypeSetElemNestedAttrs(resourceName+"."+wtRes.resID, "statuses.*", map[string]*regexp.Regexp{
- "name": regexp.MustCompile(statusUpdates.statuses[1].name),
- "description": regexp.MustCompile(statusUpdates.statuses[1].description),
- "category": regexp.MustCompile(statusUpdates.statuses[1].category),
- }),
- resource.TestMatchTypeSetElemNestedAttrs(resourceName+"."+wtRes.resID, "statuses.*", map[string]*regexp.Regexp{
- "name": regexp.MustCompile(statusUpdates.statuses[2].name),
- "description": regexp.MustCompile(statusUpdates.statuses[2].description),
- "category": regexp.MustCompile(statusUpdates.statuses[2].category),
- }),
- resource.TestMatchTypeSetElemNestedAttrs(resourceName+"."+wtRes.resID, "statuses.*", map[string]*regexp.Regexp{
- "name": regexp.MustCompile(statusUpdates.statuses[3].name),
- "description": regexp.MustCompile(statusUpdates.statuses[3].description),
- "category": regexp.MustCompile(statusUpdates.statuses[3].category),
- }),
- ),
- },
- // Removing statuses and update
- {
- Config: workbin.GenerateWorkbinResource(wbResourceId, wbName, wbDescription, util.NullValue) +
- workitemSchema.GenerateWorkitemSchemaResourceBasic(wsResourceId, wsName, wsDescription) +
- GenerateWorktypeResourceBasic(wtRes.resID, wtRes.name, wtRes.description, wtRes.defaultWorkbinId, wtRes.schemaId, generateWorktypeAllStatuses(statusUpdates2)),
- Check: resource.ComposeTestCheckFunc(
- resource.TestCheckResourceAttr(resourceName+"."+wtRes.resID, "name", wtRes.name),
- resource.TestCheckResourceAttr(resourceName+"."+wtRes.resID, "description", wtRes.description),
- resource.TestCheckResourceAttrPair(resourceName+"."+wtRes.resID, "default_workbin_id", fmt.Sprintf("genesyscloud_task_management_workbin.%s", wbResourceId), "id"),
- resource.TestCheckResourceAttrPair(resourceName+"."+wtRes.resID, "schema_id", fmt.Sprintf("genesyscloud_task_management_workitem_schema.%s", wsResourceId), "id"),
-
- resource.TestCheckResourceAttr(resourceName+"."+wtRes.resID, "statuses.#", fmt.Sprintf("%v", len(statusUpdates2.statuses))),
- resource.TestMatchTypeSetElemNestedAttrs(resourceName+"."+wtRes.resID, "statuses.*", map[string]*regexp.Regexp{
- "name": regexp.MustCompile(statusUpdates2.statuses[0].name),
- "description": regexp.MustCompile(statusUpdates2.statuses[0].description),
- "category": regexp.MustCompile(statusUpdates2.statuses[0].category),
- }),
- resource.TestMatchTypeSetElemNestedAttrs(resourceName+"."+wtRes.resID, "statuses.*", map[string]*regexp.Regexp{
- "name": regexp.MustCompile(statusUpdates2.statuses[1].name),
- "description": regexp.MustCompile(statusUpdates2.statuses[1].description),
- "category": regexp.MustCompile(statusUpdates2.statuses[1].category),
- }),
- ),
- },
- },
- CheckDestroy: testVerifyTaskManagementWorktypeDestroyed,
- })
-}
-
func testVerifyTaskManagementWorktypeDestroyed(state *terraform.State) error {
taskMgmtApi := platformclientv2.NewTaskManagementApi()
for _, rs := range state.RootModule().Resources {
@@ -348,8 +160,6 @@ func testVerifyTaskManagementWorktypeDestroyed(state *terraform.State) error {
}
func generateWorktypeResource(wt worktypeConfig) string {
- statuses := generateWorktypeAllStatuses(wt)
-
tfConfig := fmt.Sprintf(`resource "%s" "%s" {
name = "%s"
description = "%s"
@@ -369,7 +179,6 @@ func generateWorktypeResource(wt worktypeConfig) string {
assignment_enabled = %v
schema_version = %v
- %s
}
`, resourceName,
wt.resID,
@@ -388,41 +197,6 @@ func generateWorktypeResource(wt worktypeConfig) string {
util.GenerateStringArray(wt.defaultSkillIds...),
wt.assignmentEnabled,
wt.schemaVersion,
- statuses,
)
return tfConfig
}
-
-func generateWorktypeAllStatuses(wt worktypeConfig) string {
- statuses := []string{}
-
- for _, s := range wt.statuses {
- statuses = append(statuses, generateWorktypeStatus(s))
- }
-
- return strings.Join(statuses, "\n")
-}
-
-func generateWorktypeStatus(wtStatus worktypeStatusConfig) string {
- additional := []string{}
- if len(wtStatus.destinationStatusNames) > 0 {
- additional = append(additional, util.GenerateMapProperty("destination_status_names", util.GenerateStringArrayEnquote(wtStatus.destinationStatusNames...)))
- }
- if wtStatus.defaultDestinationStatusName != "" {
- additional = append(additional, util.GenerateMapProperty("default_destination_status_name", strconv.Quote(wtStatus.defaultDestinationStatusName)))
- }
- if wtStatus.transitionDelay != 0 {
- additional = append(additional, util.GenerateMapProperty("status_transition_delay_seconds", strconv.Itoa(wtStatus.transitionDelay)))
- }
- if wtStatus.statusTransitionTime != "" {
- additional = append(additional, util.GenerateMapProperty("status_transition_time", strconv.Quote(wtStatus.statusTransitionTime)))
- }
-
- return fmt.Sprintf(`statuses {
- name = "%s"
- description = "%s"
- category = "%s"
- %s
- }
- `, wtStatus.name, wtStatus.description, wtStatus.category, strings.Join(additional, "\n"))
-}
diff --git a/genesyscloud/task_management_worktype/resource_genesyscloud_task_management_worktype_unit_test.go b/genesyscloud/task_management_worktype/resource_genesyscloud_task_management_worktype_unit_test.go
index 4af168184..84be41f9e 100644
--- a/genesyscloud/task_management_worktype/resource_genesyscloud_task_management_worktype_unit_test.go
+++ b/genesyscloud/task_management_worktype/resource_genesyscloud_task_management_worktype_unit_test.go
@@ -1,6 +1,5 @@
package task_management_worktype
-// build
import (
"context"
"fmt"
@@ -27,38 +26,6 @@ func TestUnitResourceWorktypeCreate(t *testing.T) {
divisionId: uuid.NewString(),
defaultWorkbinId: uuid.NewString(),
- statuses: []worktypeStatusConfig{
- {
- id: uuid.NewString(),
- name: "Open Status",
- description: "Description of open status. Updated",
- defaultDestinationStatusName: "WIP",
- destinationStatusNames: []string{"WIP", "Waiting Status"},
- transitionDelay: 120,
- statusTransitionTime: "12:11:10",
- category: "Open",
- },
- {
- id: uuid.NewString(),
- name: "WIP",
- description: "Description of in progress status. Updated",
- category: "InProgress",
- },
- {
- id: uuid.NewString(),
- name: "Waiting Status",
- description: "Description of waiting status. Updated",
- category: "Waiting",
- },
- {
- id: uuid.NewString(),
- name: "Close Status",
- description: "Description of close status. Updated",
- category: "Closed",
- },
- },
- defaultStatusName: "Open Status",
-
defaultDurationS: 86400,
defaultExpirationS: 86400,
defaultDueDurationS: 86400,
@@ -74,9 +41,9 @@ func TestUnitResourceWorktypeCreate(t *testing.T) {
schemaVersion: 1,
}
- taskProxy := &taskManagementWorktypeProxy{}
+ taskProxy := &TaskManagementWorktypeProxy{}
- taskProxy.createTaskManagementWorktypeAttr = func(ctx context.Context, p *taskManagementWorktypeProxy, create *platformclientv2.Worktypecreate) (*platformclientv2.Worktype, *platformclientv2.APIResponse, error) {
+ taskProxy.createTaskManagementWorktypeAttr = func(ctx context.Context, p *TaskManagementWorktypeProxy, create *platformclientv2.Worktypecreate) (*platformclientv2.Worktype, *platformclientv2.APIResponse, error) {
assert.Equal(t, wt.name, *create.Name, "wt.Name check failed in create createTaskManagementWorktypeAttr")
assert.Equal(t, wt.description, *create.Description, "wt.Description check failed in create createTaskManagementWorktypeAttr")
assert.Equal(t, wt.divisionId, *create.DivisionId, "wt.divisionId check failed in create createTaskManagementWorktypeAttr")
@@ -121,32 +88,7 @@ func TestUnitResourceWorktypeCreate(t *testing.T) {
}, nil, nil
}
- taskProxy.createTaskManagementWorktypeStatusAttr = func(ctx context.Context, p *taskManagementWorktypeProxy, worktypeId string, status *platformclientv2.Workitemstatuscreate) (*platformclientv2.Workitemstatus, *platformclientv2.APIResponse, error) {
- return &platformclientv2.Workitemstatus{
- Id: &worktypeId,
- Name: status.Name,
- Category: status.Category,
- Description: status.Description,
- StatusTransitionDelaySeconds: status.StatusTransitionDelaySeconds,
- StatusTransitionTime: status.StatusTransitionTime,
- }, nil, nil
- }
-
- taskProxy.updateTaskManagementWorktypeStatusAttr = func(ctx context.Context, p *taskManagementWorktypeProxy, worktypeId string, statusId string, statusUpdate *platformclientv2.Workitemstatusupdate) (*platformclientv2.Workitemstatus, *platformclientv2.APIResponse, error) {
- return &platformclientv2.Workitemstatus{
- Id: &statusId,
- Name: statusUpdate.Name,
- DestinationStatuses: buildDestinationStatuses(statusUpdate.DestinationStatusIds),
- Description: statusUpdate.Description,
- DefaultDestinationStatus: &platformclientv2.Workitemstatusreference{
- Id: statusUpdate.DefaultDestinationStatusId,
- },
- StatusTransitionDelaySeconds: statusUpdate.StatusTransitionDelaySeconds,
- StatusTransitionTime: statusUpdate.StatusTransitionTime,
- }, nil, nil
- }
-
- taskProxy.getTaskManagementWorktypeByIdAttr = func(ctx context.Context, p *taskManagementWorktypeProxy, id string) (*platformclientv2.Worktype, *platformclientv2.APIResponse, error) {
+ taskProxy.getTaskManagementWorktypeByIdAttr = func(ctx context.Context, p *TaskManagementWorktypeProxy, id string) (*platformclientv2.Worktype, *platformclientv2.APIResponse, error) {
assert.Equal(t, tId, id)
// The expected final form of the worktype
@@ -183,50 +125,6 @@ func TestUnitResourceWorktypeCreate(t *testing.T) {
Id: &wt.schemaId,
Version: &wt.schemaVersion,
},
-
- Statuses: &[]platformclientv2.Workitemstatus{
- {
- Id: &wt.statuses[0].id,
- Name: &wt.statuses[0].name,
- Description: &wt.statuses[0].description,
- DefaultDestinationStatus: &platformclientv2.Workitemstatusreference{
- Id: wt.getStatusIdFromName(wt.statuses[0].defaultDestinationStatusName),
- },
- DestinationStatuses: &[]platformclientv2.Workitemstatusreference{
- {
- Id: wt.getStatusIdFromName(wt.statuses[0].destinationStatusNames[0]),
- },
- {
- Id: wt.getStatusIdFromName(wt.statuses[0].destinationStatusNames[1]),
- },
- },
- StatusTransitionDelaySeconds: &wt.statuses[0].transitionDelay,
- StatusTransitionTime: &wt.statuses[0].statusTransitionTime,
- Category: &wt.statuses[0].category,
- },
- {
- Id: &wt.statuses[1].id,
- Name: &wt.statuses[1].name,
- Description: &wt.statuses[1].description,
- Category: &wt.statuses[1].category,
- },
- {
- Id: &wt.statuses[2].id,
- Name: &wt.statuses[2].name,
- Description: &wt.statuses[2].description,
- Category: &wt.statuses[2].category,
- },
- {
- Id: &wt.statuses[3].id,
- Name: &wt.statuses[3].name,
- Description: &wt.statuses[3].description,
- Category: &wt.statuses[3].category,
- },
- },
-
- DefaultStatus: &platformclientv2.Workitemstatusreference{
- Id: wt.getStatusIdFromName(wt.defaultStatusName),
- },
}
apiResponse := &platformclientv2.APIResponse{StatusCode: http.StatusOK}
@@ -251,7 +149,7 @@ func TestUnitResourceWorktypeCreate(t *testing.T) {
d.SetId(tId)
diag := createTaskManagementWorktype(ctx, d, gcloud)
- assert.Equal(t, false, diag.HasError())
+ assert.Equal(t, false, diag.HasError(), diag)
assert.Equal(t, tId, d.Id())
}
@@ -265,38 +163,6 @@ func TestUnitResourceWorktypeRead(t *testing.T) {
divisionId: uuid.NewString(),
defaultWorkbinId: uuid.NewString(),
- statuses: []worktypeStatusConfig{
- {
- id: uuid.NewString(),
- name: "Open Status",
- description: "Description of open status. Updated",
- defaultDestinationStatusName: "WIP",
- destinationStatusNames: []string{"WIP", "Waiting Status"},
- transitionDelay: 120,
- statusTransitionTime: "12:11:10",
- category: "Open",
- },
- {
- id: uuid.NewString(),
- name: "WIP",
- description: "Description of in progress status. Updated",
- category: "InProgress",
- },
- {
- id: uuid.NewString(),
- name: "Waiting Status",
- description: "Description of waiting status. Updated",
- category: "Waiting",
- },
- {
- id: uuid.NewString(),
- name: "Close Status",
- description: "Description of close status. Updated",
- category: "Closed",
- },
- },
- defaultStatusName: "Open Status",
-
defaultDurationS: 86400,
defaultExpirationS: 86400,
defaultDueDurationS: 86400,
@@ -312,9 +178,9 @@ func TestUnitResourceWorktypeRead(t *testing.T) {
schemaVersion: 1,
}
- taskProxy := &taskManagementWorktypeProxy{}
+ taskProxy := &TaskManagementWorktypeProxy{}
- taskProxy.getTaskManagementWorktypeByIdAttr = func(ctx context.Context, p *taskManagementWorktypeProxy, id string) (*platformclientv2.Worktype, *platformclientv2.APIResponse, error) {
+ taskProxy.getTaskManagementWorktypeByIdAttr = func(ctx context.Context, p *TaskManagementWorktypeProxy, id string) (*platformclientv2.Worktype, *platformclientv2.APIResponse, error) {
assert.Equal(t, tId, id)
// The expected final form of the worktype
@@ -351,50 +217,6 @@ func TestUnitResourceWorktypeRead(t *testing.T) {
Id: &wt.schemaId,
Version: &wt.schemaVersion,
},
-
- Statuses: &[]platformclientv2.Workitemstatus{
- {
- Id: &wt.statuses[0].id,
- Name: &wt.statuses[0].name,
- Description: &wt.statuses[0].description,
- DefaultDestinationStatus: &platformclientv2.Workitemstatusreference{
- Id: wt.getStatusIdFromName(wt.statuses[0].defaultDestinationStatusName),
- },
- DestinationStatuses: &[]platformclientv2.Workitemstatusreference{
- {
- Id: wt.getStatusIdFromName(wt.statuses[0].destinationStatusNames[0]),
- },
- {
- Id: wt.getStatusIdFromName(wt.statuses[0].destinationStatusNames[1]),
- },
- },
- StatusTransitionDelaySeconds: &wt.statuses[0].transitionDelay,
- StatusTransitionTime: &wt.statuses[0].statusTransitionTime,
- Category: &wt.statuses[0].category,
- },
- {
- Id: &wt.statuses[1].id,
- Name: &wt.statuses[1].name,
- Description: &wt.statuses[1].description,
- Category: &wt.statuses[1].category,
- },
- {
- Id: &wt.statuses[2].id,
- Name: &wt.statuses[2].name,
- Description: &wt.statuses[2].description,
- Category: &wt.statuses[2].category,
- },
- {
- Id: &wt.statuses[3].id,
- Name: &wt.statuses[3].name,
- Description: &wt.statuses[3].description,
- Category: &wt.statuses[3].category,
- },
- },
-
- DefaultStatus: &platformclientv2.Workitemstatusreference{
- Id: wt.getStatusIdFromName(wt.defaultStatusName),
- },
}
apiResponse := &platformclientv2.APIResponse{StatusCode: http.StatusOK}
@@ -419,14 +241,12 @@ func TestUnitResourceWorktypeRead(t *testing.T) {
diag := readTaskManagementWorktype(ctx, d, gcloud)
- assert.Equal(t, false, diag.HasError())
+ assert.Equal(t, false, diag.HasError(), diag)
assert.Equal(t, tId, d.Id())
assert.Equal(t, wt.name, d.Get("name").(string))
assert.Equal(t, wt.description, d.Get("description").(string))
assert.Equal(t, wt.divisionId, d.Get("division_id").(string))
assert.Equal(t, wt.defaultWorkbinId, d.Get("default_workbin_id").(string))
- assert.Equal(t, len(wt.statuses), d.Get("statuses").(*schema.Set).Len())
- assert.Equal(t, wt.defaultStatusName, d.Get("default_status_name").(string))
assert.Equal(t, wt.defaultDurationS, d.Get("default_duration_seconds").(int))
assert.Equal(t, wt.defaultExpirationS, d.Get("default_expiration_seconds").(int))
assert.Equal(t, wt.defaultDueDurationS, d.Get("default_due_duration_seconds").(int))
@@ -450,38 +270,6 @@ func TestUnitResourceWorktypeUpdate(t *testing.T) {
divisionId: uuid.NewString(),
defaultWorkbinId: uuid.NewString(),
- statuses: []worktypeStatusConfig{
- {
- id: uuid.NewString(),
- name: "Open Status",
- description: "Description of open status. Updated",
- defaultDestinationStatusName: "WIP",
- destinationStatusNames: []string{"WIP", "Waiting Status"},
- transitionDelay: 120,
- statusTransitionTime: "12:11:10",
- category: "Open",
- },
- {
- id: uuid.NewString(),
- name: "WIP",
- description: "Description of in progress status. Updated",
- category: "InProgress",
- },
- {
- id: uuid.NewString(),
- name: "Waiting Status",
- description: "Description of waiting status. Updated",
- category: "Waiting",
- },
- {
- id: uuid.NewString(),
- name: "Close Status",
- description: "Description of close status. Updated",
- category: "Closed",
- },
- },
- defaultStatusName: "Open Status",
-
defaultDurationS: 86400,
defaultExpirationS: 86400,
defaultDueDurationS: 86400,
@@ -497,9 +285,9 @@ func TestUnitResourceWorktypeUpdate(t *testing.T) {
schemaVersion: 1,
}
- taskProxy := &taskManagementWorktypeProxy{}
+ taskProxy := &TaskManagementWorktypeProxy{}
- taskProxy.updateTaskManagementWorktypeAttr = func(ctx context.Context, p *taskManagementWorktypeProxy, id string, update *platformclientv2.Worktypeupdate) (*platformclientv2.Worktype, *platformclientv2.APIResponse, error) {
+ taskProxy.updateTaskManagementWorktypeAttr = func(ctx context.Context, p *TaskManagementWorktypeProxy, id string, update *platformclientv2.Worktypeupdate) (*platformclientv2.Worktype, *platformclientv2.APIResponse, error) {
assert.Equal(t, tId, id)
assert.Equal(t, wt.name, *update.Name, "wt.Name check failed in create createTaskManagementWorktypeAttr")
@@ -531,34 +319,8 @@ func TestUnitResourceWorktypeUpdate(t *testing.T) {
}, nil, nil
}
- taskProxy.createTaskManagementWorktypeStatusAttr = func(ctx context.Context, p *taskManagementWorktypeProxy, worktypeId string, status *platformclientv2.Workitemstatuscreate) (*platformclientv2.Workitemstatus, *platformclientv2.APIResponse, error) {
- return &platformclientv2.Workitemstatus{
- Id: &worktypeId,
- Name: status.Name,
- Category: status.Category,
- Description: status.Description,
- StatusTransitionDelaySeconds: status.StatusTransitionDelaySeconds,
- StatusTransitionTime: status.StatusTransitionTime,
- }, nil, nil
- }
-
- taskProxy.updateTaskManagementWorktypeStatusAttr = func(ctx context.Context, p *taskManagementWorktypeProxy, worktypeId string, statusId string, statusUpdate *platformclientv2.Workitemstatusupdate) (*platformclientv2.Workitemstatus, *platformclientv2.APIResponse, error) {
- return &platformclientv2.Workitemstatus{
- Id: &statusId,
- Name: statusUpdate.Name,
- DestinationStatuses: buildDestinationStatuses(statusUpdate.DestinationStatusIds),
- Description: statusUpdate.Description,
- DefaultDestinationStatus: &platformclientv2.Workitemstatusreference{
- Id: statusUpdate.DefaultDestinationStatusId,
- },
- StatusTransitionDelaySeconds: statusUpdate.StatusTransitionDelaySeconds,
- StatusTransitionTime: statusUpdate.StatusTransitionTime,
- }, nil, nil
- }
-
// The final complete worktype for read
- // This is where we'll be asserting the statuses
- taskProxy.getTaskManagementWorktypeByIdAttr = func(ctx context.Context, p *taskManagementWorktypeProxy, id string) (*platformclientv2.Worktype, *platformclientv2.APIResponse, error) {
+ taskProxy.getTaskManagementWorktypeByIdAttr = func(ctx context.Context, p *TaskManagementWorktypeProxy, id string) (*platformclientv2.Worktype, *platformclientv2.APIResponse, error) {
assert.Equal(t, tId, id)
// The expected final form of the worktype
@@ -595,50 +357,6 @@ func TestUnitResourceWorktypeUpdate(t *testing.T) {
Id: &wt.schemaId,
Version: &wt.schemaVersion,
},
-
- Statuses: &[]platformclientv2.Workitemstatus{
- {
- Id: &wt.statuses[0].id,
- Name: &wt.statuses[0].name,
- Description: &wt.statuses[0].description,
- DefaultDestinationStatus: &platformclientv2.Workitemstatusreference{
- Id: wt.getStatusIdFromName(wt.statuses[0].defaultDestinationStatusName),
- },
- DestinationStatuses: &[]platformclientv2.Workitemstatusreference{
- {
- Id: wt.getStatusIdFromName(wt.statuses[0].destinationStatusNames[0]),
- },
- {
- Id: wt.getStatusIdFromName(wt.statuses[0].destinationStatusNames[1]),
- },
- },
- StatusTransitionDelaySeconds: &wt.statuses[0].transitionDelay,
- StatusTransitionTime: &wt.statuses[0].statusTransitionTime,
- Category: &wt.statuses[0].category,
- },
- {
- Id: &wt.statuses[1].id,
- Name: &wt.statuses[1].name,
- Description: &wt.statuses[1].description,
- Category: &wt.statuses[1].category,
- },
- {
- Id: &wt.statuses[2].id,
- Name: &wt.statuses[2].name,
- Description: &wt.statuses[2].description,
- Category: &wt.statuses[2].category,
- },
- {
- Id: &wt.statuses[3].id,
- Name: &wt.statuses[3].name,
- Description: &wt.statuses[3].description,
- Category: &wt.statuses[3].category,
- },
- },
-
- DefaultStatus: &platformclientv2.Workitemstatusreference{
- Id: wt.getStatusIdFromName(wt.defaultStatusName),
- },
}
apiResponse := &platformclientv2.APIResponse{StatusCode: http.StatusOK}
@@ -663,7 +381,7 @@ func TestUnitResourceWorktypeUpdate(t *testing.T) {
d.SetId(tId)
diag := updateTaskManagementWorktype(ctx, d, gcloud)
- assert.Equal(t, false, diag.HasError())
+ assert.Equal(t, false, diag.HasError(), diag)
assert.Equal(t, tId, d.Id())
}
@@ -676,16 +394,16 @@ func TestUnitResourceWorktypeDelete(t *testing.T) {
schemaId: uuid.NewString(),
}
- taskProxy := &taskManagementWorktypeProxy{}
+ taskProxy := &TaskManagementWorktypeProxy{}
- taskProxy.deleteTaskManagementWorktypeAttr = func(ctx context.Context, p *taskManagementWorktypeProxy, id string) (*platformclientv2.APIResponse, error) {
+ taskProxy.deleteTaskManagementWorktypeAttr = func(ctx context.Context, p *TaskManagementWorktypeProxy, id string) (*platformclientv2.APIResponse, error) {
assert.Equal(t, tId, id)
apiResponse := &platformclientv2.APIResponse{StatusCode: http.StatusNoContent}
return apiResponse, nil
}
- taskProxy.getTaskManagementWorktypeByIdAttr = func(ctx context.Context, p *taskManagementWorktypeProxy, id string) (worktype *platformclientv2.Worktype, response *platformclientv2.APIResponse, err error) {
+ taskProxy.getTaskManagementWorktypeByIdAttr = func(ctx context.Context, p *TaskManagementWorktypeProxy, id string) (worktype *platformclientv2.Worktype, response *platformclientv2.APIResponse, err error) {
assert.Equal(t, tId, id)
apiResponse := &platformclientv2.APIResponse{
@@ -714,7 +432,7 @@ func TestUnitResourceWorktypeDelete(t *testing.T) {
d.SetId(tId)
diag := deleteTaskManagementWorktype(ctx, d, gcloud)
- assert.Nil(t, diag)
+ assert.Nil(t, diag, diag)
assert.Equal(t, tId, d.Id())
}
@@ -724,7 +442,6 @@ func buildWorktypeResourceMap(tId string, wt *worktypeConfig) map[string]interfa
"name": wt.name,
"description": wt.description,
"division_id": wt.divisionId,
- "statuses": buildWorktypeStatusesList(&wt.statuses),
"default_workbin_id": wt.defaultWorkbinId,
"default_duration_seconds": wt.defaultDurationS,
"default_expiration_seconds": wt.defaultExpirationS,
@@ -741,37 +458,3 @@ func buildWorktypeResourceMap(tId string, wt *worktypeConfig) map[string]interfa
return resourceDataMap
}
-
-func buildWorktypeStatusesList(statuses *[]worktypeStatusConfig) []interface{} {
- statusList := []interface{}{}
- for _, s := range *statuses {
- statusList = append(statusList, buildWorktypeStatusResourceMap(&s))
- }
-
- return statusList
-}
-
-func buildWorktypeStatusResourceMap(status *worktypeStatusConfig) map[string]interface{} {
- return map[string]interface{}{
- "id": status.id,
- "name": status.name,
- "description": status.description,
- "category": status.category,
- "destination_status_names": lists.StringListToInterfaceList(status.destinationStatusNames),
- "default_destination_status_name": status.defaultDestinationStatusName,
- "status_transition_delay_seconds": status.transitionDelay,
- "status_transition_time": status.statusTransitionTime,
- }
-}
-
-func buildDestinationStatuses(statusIds *[]string) *[]platformclientv2.Workitemstatusreference {
- ret := []platformclientv2.Workitemstatusreference{}
-
- for _, sid := range *statusIds {
- ret = append(ret, platformclientv2.Workitemstatusreference{
- Id: &sid,
- })
- }
-
- return &ret
-}
diff --git a/genesyscloud/task_management_worktype/resource_genesyscloud_task_management_worktype_utils.go b/genesyscloud/task_management_worktype/resource_genesyscloud_task_management_worktype_utils.go
index 45a292407..4ff102461 100644
--- a/genesyscloud/task_management_worktype/resource_genesyscloud_task_management_worktype_utils.go
+++ b/genesyscloud/task_management_worktype/resource_genesyscloud_task_management_worktype_utils.go
@@ -1,7 +1,6 @@
package task_management_worktype
import (
- "context"
"fmt"
"terraform-provider-genesyscloud/genesyscloud/util/lists"
"terraform-provider-genesyscloud/genesyscloud/util/resourcedata"
@@ -16,13 +15,11 @@ and unmarshal data into formats consumable by Terraform and/or Genesys Cloud.
*/
type worktypeConfig struct {
- resID string
- name string
- description string
- divisionId string
- statuses []worktypeStatusConfig
- defaultStatusName string
- defaultWorkbinId string
+ resID string
+ name string
+ description string
+ divisionId string
+ defaultWorkbinId string
defaultDurationS int
defaultExpirationS int
@@ -39,24 +36,13 @@ type worktypeConfig struct {
schemaVersion int
}
-type worktypeStatusConfig struct {
- id string
- name string
- description string
- category string
- destinationStatusNames []string
- defaultDestinationStatusName string
- transitionDelay int
- statusTransitionTime string
-}
-
// getWorktypeCreateFromResourceData maps data from schema ResourceData object to a platformclientv2.Worktypecreate
func getWorktypecreateFromResourceData(d *schema.ResourceData) platformclientv2.Worktypecreate {
worktype := platformclientv2.Worktypecreate{
Name: platformclientv2.String(d.Get("name").(string)),
DivisionId: platformclientv2.String(d.Get("division_id").(string)),
Description: platformclientv2.String(d.Get("description").(string)),
- DisableDefaultStatusCreation: platformclientv2.Bool(true),
+ DisableDefaultStatusCreation: platformclientv2.Bool(false),
DefaultWorkbinId: platformclientv2.String(d.Get("default_workbin_id").(string)),
SchemaId: platformclientv2.String(d.Get("schema_id").(string)),
SchemaVersion: resourcedata.GetNillableValue[int](d, "schema_version"),
@@ -78,8 +64,7 @@ func getWorktypecreateFromResourceData(d *schema.ResourceData) platformclientv2.
}
// getWorktypeupdateFromResourceData maps data from schema ResourceData object to a platformclientv2.Worktypeupdate
-func getWorktypeupdateFromResourceData(d *schema.ResourceData, statuses *[]platformclientv2.Workitemstatus) platformclientv2.Worktypeupdate {
-
+func getWorktypeupdateFromResourceData(d *schema.ResourceData) platformclientv2.Worktypeupdate {
worktype := platformclientv2.Worktypeupdate{}
worktype.SetField("Name", platformclientv2.String(d.Get("name").(string)))
if d.HasChange("description") {
@@ -133,214 +118,6 @@ func getWorktypeupdateFromResourceData(d *schema.ResourceData, statuses *[]platf
return worktype
}
-// getWorktypeupdateFromResourceData maps data from schema ResourceData object to a platformclientv2.Worktypeupdate
-func getWorktypeupdateFromResourceDataStatus(d *schema.ResourceData, statuses *[]platformclientv2.Workitemstatus) platformclientv2.Worktypeupdate {
-
- worktype := platformclientv2.Worktypeupdate{}
- worktype.SetField("Name", platformclientv2.String(d.Get("name").(string)))
- if d.HasChange("default_status_name") {
- worktype.SetField("DefaultStatusId", getStatusIdFromName(d.Get("default_status_name").(string), statuses))
- }
- return worktype
-}
-
-// getStatusFromName gets a platformclientv2.Workitemstatus from a *[]platformclientv2.Workitemstatu by name
-func getStatusFromName(statusName string, statuses *[]platformclientv2.Workitemstatus) *platformclientv2.Workitemstatus {
- if statuses == nil {
- return nil
- }
-
- for _, apiStatus := range *statuses {
- if statusName == *apiStatus.Name {
- return &apiStatus
- }
- }
-
- return nil
-}
-
-// getStatusIdFromName gets a status id from a *[]platformclientv2.Workitemstatu by status name
-func getStatusIdFromName(statusName string, statuses *[]platformclientv2.Workitemstatus) *string {
- if statuses == nil {
- return nil
- }
-
- for _, apiStatus := range *statuses {
- if statusName == *apiStatus.Name {
- return apiStatus.Id
- }
- }
-
- return nil
-}
-
-// getStatusIdFromName gets the status name from a *[]platformclientv2.Workitemstatus by status id
-func getStatusNameFromId(statusId string, statuses *[]platformclientv2.Workitemstatus) *string {
- if statuses == nil {
- return nil
- }
-
- for _, apiStatus := range *statuses {
- if statusId == *apiStatus.Id {
- return apiStatus.Name
- }
- }
-
- return nil
-}
-
-// buildWorkitemStatusCreates maps an []interface{} into a Genesys Cloud *[]platformclientv2.Workitemstatuscreate
-func buildWorkitemStatusCreates(workitemStatuses []interface{}) *[]platformclientv2.Workitemstatuscreate {
- workitemStatusesSlice := make([]platformclientv2.Workitemstatuscreate, 0)
-
- for _, workitemStatus := range workitemStatuses {
- var sdkWorkitemStatus platformclientv2.Workitemstatuscreate
- workitemStatusMap, ok := workitemStatus.(map[string]interface{})
- if !ok {
- continue
- }
-
- resourcedata.BuildSDKStringValueIfNotNil(&sdkWorkitemStatus.Name, workitemStatusMap, "name")
- resourcedata.BuildSDKStringValueIfNotNil(&sdkWorkitemStatus.Category, workitemStatusMap, "category")
- resourcedata.BuildSDKStringValueIfNotNil(&sdkWorkitemStatus.Description, workitemStatusMap, "description")
- resourcedata.BuildSDKStringValueIfNotNil(&sdkWorkitemStatus.StatusTransitionTime, workitemStatusMap, "status_transition_time")
- if statusTransitionDelaySec, ok := workitemStatusMap["status_transition_delay_seconds"]; ok && statusTransitionDelaySec.(int) > 0 {
- sdkWorkitemStatus.StatusTransitionDelaySeconds = platformclientv2.Int(statusTransitionDelaySec.(int))
- }
-
- workitemStatusesSlice = append(workitemStatusesSlice, sdkWorkitemStatus)
- }
-
- return &workitemStatusesSlice
-}
-
-// buildWorkitemStatusUpdates maps an []interface{} into a Genesys Cloud *[]platformclientv2.Workitemstatusupdate
-// workitemStatuses is the terraform resource object attribute while apiStatuses is the existing Genesys Cloud
-// statuses to be used as reference for the 'destination status ids'
-func buildWorkitemStatusUpdates(workitemStatuses []interface{}, apiStatuses *[]platformclientv2.Workitemstatus) *[]platformclientv2.Workitemstatusupdate {
- workitemStatussSlice := make([]platformclientv2.Workitemstatusupdate, 0)
-
- // Inner func get the status id from a status name.
- getStatusIdFromNameFn := func(statusName string) *string {
- return getStatusIdFromName(statusName, apiStatuses)
- }
-
- // Inner func for use in building the destination status ids from the status names defined
- buildStatusIdFn := func(statusNames []interface{}) *[]string {
- statusIds := []string{}
- for _, name := range statusNames {
- if statusId := getStatusIdFromName(name.(string), apiStatuses); statusId != nil {
- statusIds = append(statusIds, *statusId)
- }
- }
-
- return &statusIds
- }
-
- for _, workitemStatus := range workitemStatuses {
- sdkWorkitemStatus := platformclientv2.Workitemstatusupdate{}
- workitemStatusMap, ok := workitemStatus.(map[string]interface{})
- if !ok {
- continue
- }
-
- // For the following if some attributes are not provided in terraform file we
- // explicitly set the SDK attribute to nil to nullify its value in the API
-
- if name, ok := workitemStatusMap["name"]; ok {
- sdkWorkitemStatus.SetField("Name", platformclientv2.String(name.(string)))
- }
-
- if description, ok := workitemStatusMap["description"]; ok {
- sdkWorkitemStatus.SetField("Description", platformclientv2.String(description.(string)))
- }
-
- if statusTransitionTime, ok := workitemStatusMap["status_transition_time"]; ok {
- sdkWorkitemStatus.SetField("StatusTransitionTime", platformclientv2.String(statusTransitionTime.(string)))
- } else {
- sdkWorkitemStatus.SetField("StatusTransitionTime", nil)
- }
-
- if statusTransitionDelaySec, ok := workitemStatusMap["status_transition_delay_seconds"]; ok && statusTransitionDelaySec.(int) > 0 {
- sdkWorkitemStatus.SetField("StatusTransitionDelaySeconds", platformclientv2.Int(statusTransitionDelaySec.(int)))
- } else {
- sdkWorkitemStatus.SetField("StatusTransitionDelaySeconds", nil)
- }
-
- if destinationStatuses, ok := workitemStatusMap["destination_status_names"]; ok {
- statusIds := buildStatusIdFn(destinationStatuses.([]interface{}))
- sdkWorkitemStatus.SetField("DestinationStatusIds", statusIds)
- } else {
- sdkWorkitemStatus.SetField("DestinationStatusIds", nil)
- }
-
- if defaultDestination, ok := workitemStatusMap["default_destination_status_name"]; ok {
- defaultDestStatusId := getStatusIdFromNameFn(defaultDestination.(string))
- sdkWorkitemStatus.SetField("DefaultDestinationStatusId", defaultDestStatusId)
- } else {
- sdkWorkitemStatus.SetField("DefaultDestinationStatusId", nil)
- }
-
- workitemStatussSlice = append(workitemStatussSlice, sdkWorkitemStatus)
- }
-
- return &workitemStatussSlice
-}
-
-// flattenWorkitemStatusReferences maps a Genesys Cloud *[]platformclientv2.Workitemstatusreference into a []interface{}
-// Sadly the API only returns the ID in the ref object (even if the name is defined in the API model), so we still need the
-// existingStatuses parameter to get the name for resolving back into resource data
-func flattenWorkitemStatusReferences(workitemStatusReferences *[]platformclientv2.Workitemstatusreference, existingStatuses *[]platformclientv2.Workitemstatus) []interface{} {
- if len(*workitemStatusReferences) == 0 {
- return nil
- }
-
- var workitemStatusReferenceList []interface{}
- for _, workitemStatusReference := range *workitemStatusReferences {
- for _, existingStatus := range *existingStatuses {
- if *workitemStatusReference.Id == *existingStatus.Id {
- workitemStatusReferenceList = append(workitemStatusReferenceList, existingStatus.Name)
- }
- }
- }
-
- return workitemStatusReferenceList
-}
-
-// flattenWorkitemStatuss maps a Genesys Cloud *[]platformclientv2.Workitemstatus into a []interface{}
-func flattenWorkitemStatuses(workitemStatuses *[]platformclientv2.Workitemstatus) []interface{} {
- if len(*workitemStatuses) == 0 {
- return nil
- }
-
- // Containing function for flattening because we need to use
- // worktype statuses as reference for the method
- flattenStatusRefsWithExisting := func(refs *[]platformclientv2.Workitemstatusreference) []interface{} {
- return flattenWorkitemStatusReferences(refs, workitemStatuses)
- }
-
- var workitemStatusList []interface{}
- for _, workitemStatus := range *workitemStatuses {
- workitemStatusMap := make(map[string]interface{})
-
- resourcedata.SetMapValueIfNotNil(workitemStatusMap, "id", workitemStatus.Id)
- resourcedata.SetMapValueIfNotNil(workitemStatusMap, "name", workitemStatus.Name)
- resourcedata.SetMapValueIfNotNil(workitemStatusMap, "category", workitemStatus.Category)
- resourcedata.SetMapValueIfNotNil(workitemStatusMap, "description", workitemStatus.Description)
- resourcedata.SetMapValueIfNotNil(workitemStatusMap, "status_transition_delay_seconds", workitemStatus.StatusTransitionDelaySeconds)
- resourcedata.SetMapValueIfNotNil(workitemStatusMap, "status_transition_time", workitemStatus.StatusTransitionTime)
-
- resourcedata.SetMapInterfaceArrayWithFuncIfNotNil(workitemStatusMap, "destination_status_names", workitemStatus.DestinationStatuses, flattenStatusRefsWithExisting)
- if workitemStatus.DefaultDestinationStatus != nil {
- resourcedata.SetMapValueIfNotNil(workitemStatusMap, "default_destination_status_name", getStatusNameFromId(*workitemStatus.DefaultDestinationStatus.Id, workitemStatuses))
- }
-
- workitemStatusList = append(workitemStatusList, workitemStatusMap)
- }
-
- return workitemStatusList
-}
-
// flattenRoutingSkillReferences maps a Genesys Cloud *[]platformclientv2.Routingskillreference into a []interface{}
func flattenRoutingSkillReferences(routingSkillReferences *[]platformclientv2.Routingskillreference) []interface{} {
if len(*routingSkillReferences) == 0 {
@@ -355,132 +132,6 @@ func flattenRoutingSkillReferences(routingSkillReferences *[]platformclientv2.Ro
return routingSkillReferenceList
}
-// getStatusesForUpdateAndCreation takes a resource data list []interface{} of statuses and determines if they
-// are to be created or just updated. Returns the two lists.
-func getStatusesForUpdateAndCreation(statuses []interface{}, existingStatuses *[]platformclientv2.Workitemstatus) (forCreation []interface{}, forUpdate []interface{}) {
- forCreation = make([]interface{}, 0)
- forUpdate = make([]interface{}, 0)
-
- // We will consider it the same status and update in-place if the name and the category matches.
- // else, a new status will be created.
- for _, status := range statuses {
- statusMap := status.(map[string]interface{})
- statusName, ok := statusMap["name"]
- if !ok {
- continue
- }
- statusCat, ok := statusMap["category"]
- if !ok {
- continue
- }
- toCreateNewStatus := true
-
- // If the status matches an existing name and same category then we'll consider
- // it the same and not create a new one.
- for _, existingStatus := range *existingStatuses {
- if *existingStatus.Name == statusName && *existingStatus.Category == statusCat {
- toCreateNewStatus = false
- break
- }
- }
-
- if toCreateNewStatus {
- forCreation = append(forCreation, status)
- } else {
- forUpdate = append(forUpdate, status)
- }
- }
-
- return forCreation, forUpdate
-}
-
-// createWorktypeStatuses creates new statuses as defined in the config. This is just the initial
-// creation as some statuses also need to be updated separately to build the destination status references.
-func createWorktypeStatuses(ctx context.Context, proxy *taskManagementWorktypeProxy, worktypeId string, statuses []interface{}) (*[]platformclientv2.Workitemstatus, error) {
- ret := []platformclientv2.Workitemstatus{}
-
- sdkWorkitemStatusCreates := buildWorkitemStatusCreates(statuses)
- for _, statusCreate := range *sdkWorkitemStatusCreates {
- status, resp, err := proxy.createTaskManagementWorktypeStatus(ctx, worktypeId, &statusCreate)
- if err != nil {
- return nil, fmt.Errorf("failed to create worktype status %s: %v %v", *statusCreate.Name, err, resp)
- }
-
- ret = append(ret, *status)
- }
-
- return &ret, nil
-}
-
-// updateWorktypeStatuses updates the statuses of a worktype. There are two modes depending if the passed statuses
-// is newly created or not. For newly created, we just check if there's any need to resolve references since they still
-// have none. For existing statuses, they should be passed as already validated (has change - because API will return error
-// if there's no change to the status), the method will not check it.
-func updateWorktypeStatuses(ctx context.Context, proxy *taskManagementWorktypeProxy, worktypeId string, statuses []interface{}, isNewlyCreated bool) (*[]platformclientv2.Workitemstatus, error) {
- ret := []platformclientv2.Workitemstatus{}
-
- // Get all the worktype statuses so we'll have the new statuses for referencing
- worktype, resp, err := proxy.getTaskManagementWorktypeById(ctx, worktypeId)
- if err != nil {
- return nil, fmt.Errorf("failed to get task management worktype %s: %v %v", worktypeId, err, resp)
- }
-
- // Update the worktype statuses as they need to build the "destination status" references
- sdkWorkitemStatusUpdates := buildWorkitemStatusUpdates(statuses, worktype.Statuses)
- for _, statusUpdate := range *sdkWorkitemStatusUpdates {
- existingStatus := getStatusFromName(*statusUpdate.Name, worktype.Statuses)
- if existingStatus.Id == nil {
- return nil, fmt.Errorf("failed to update a status %s. Not found in the worktype %s: %v", *statusUpdate.Name, *worktype.Name, err)
- }
-
- // API does not allow updating a status with no actual change.
- // For newly created statuses, update portion is only for resolving status references, so skip statuses where
- // "destination statuses" and "default destination id" are not set.
- if isNewlyCreated &&
- (statusUpdate.DefaultDestinationStatusId == nil || *statusUpdate.DefaultDestinationStatusId == "") &&
- (statusUpdate.DestinationStatusIds == nil || len(*statusUpdate.DestinationStatusIds) == 0) {
- continue
- }
-
- status, resp, err := proxy.updateTaskManagementWorktypeStatus(ctx, *worktype.Id, *existingStatus.Id, &statusUpdate)
- if err != nil {
- return nil, fmt.Errorf("failed to update worktype status %s: %v %v", *statusUpdate.Name, err, resp)
- }
-
- ret = append(ret, *status)
- }
-
- return &ret, nil
-}
-
-// updateDefaultStatusName updates a worktype's default status name. This should be called after
-// the statuses and their references have been finalized.
-func updateDefaultStatusName(ctx context.Context, proxy *taskManagementWorktypeProxy, d *schema.ResourceData, worktypeId string) error {
- worktype, resp, err := proxy.getTaskManagementWorktypeById(ctx, worktypeId)
- if err != nil {
- return fmt.Errorf("failed to get task management worktype: %s", err)
- }
-
- taskManagementWorktype := getWorktypeupdateFromResourceDataStatus(d, worktype.Statuses)
- _, resp, err = proxy.updateTaskManagementWorktype(ctx, *worktype.Id, &taskManagementWorktype)
- if err != nil {
- return fmt.Errorf("failed to update worktype's default status name %s %v", err, resp)
- }
-
- return nil
-}
-
-// getStatusIdFromName gets the status id from name for the test util struct worktypeConfig
-func (wt *worktypeConfig) getStatusIdFromName(name string) *string {
- for _, s := range wt.statuses {
- if s.name == name {
- return &s.id
- }
- }
-
- return nil
-}
-
// GenerateWorktypeResourceBasic generates a terraform config string for a basic worktype
func GenerateWorktypeResourceBasic(resId, name, description, workbinResourceId, schemaResourceId, attrs string) string {
return fmt.Sprintf(`resource "%s" "%s" {
diff --git a/genesyscloud/task_management_worktype_status/data_source_genesyscloud_task_management_worktype_status.go b/genesyscloud/task_management_worktype_status/data_source_genesyscloud_task_management_worktype_status.go
new file mode 100644
index 000000000..0f0c985c7
--- /dev/null
+++ b/genesyscloud/task_management_worktype_status/data_source_genesyscloud_task_management_worktype_status.go
@@ -0,0 +1,43 @@
+package task_management_worktype_status
+
+import (
+ "context"
+ "fmt"
+ "github.com/hashicorp/terraform-plugin-sdk/v2/diag"
+ "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
+ "time"
+
+ "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
+
+ "terraform-provider-genesyscloud/genesyscloud/provider"
+ "terraform-provider-genesyscloud/genesyscloud/util"
+)
+
+/*
+ The data_source_genesyscloud_task_management_worktype_status.go contains the data source implementation
+ for the resource.
+*/
+
+// dataSourceTaskManagementWorktypeStatusRead retrieves by name the id in question
+func dataSourceTaskManagementWorktypeStatusRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
+ sdkConfig := meta.(*provider.ProviderMeta).ClientConfig
+ proxy := getTaskManagementWorktypeStatusProxy(sdkConfig)
+
+ worktypeId := d.Get("worktype_id").(string)
+ name := d.Get("name").(string)
+
+ return util.WithRetries(ctx, 15*time.Second, func() *retry.RetryError {
+ worktypeStatusId, resp, retryable, err := proxy.getTaskManagementWorktypeStatusIdByName(ctx, worktypeId, name)
+
+ if err != nil && !retryable {
+ return retry.NonRetryableError(util.BuildWithRetriesApiDiagnosticError(resourceName, fmt.Sprintf("Error searching task management worktype %s status %s | error: %s", worktypeId, name, err), resp))
+ }
+
+ if retryable {
+ return retry.RetryableError(util.BuildWithRetriesApiDiagnosticError(resourceName, fmt.Sprintf("No task management worktype %s status found with name %s", worktypeId, name), resp))
+ }
+
+ d.SetId(worktypeStatusId)
+ return nil
+ })
+}
diff --git a/genesyscloud/task_management_worktype_status/data_source_genesyscloud_task_management_worktype_status_test.go b/genesyscloud/task_management_worktype_status/data_source_genesyscloud_task_management_worktype_status_test.go
new file mode 100644
index 000000000..528a17dbf
--- /dev/null
+++ b/genesyscloud/task_management_worktype_status/data_source_genesyscloud_task_management_worktype_status_test.go
@@ -0,0 +1,94 @@
+package task_management_worktype_status
+
+import (
+ "fmt"
+ "github.com/google/uuid"
+ "terraform-provider-genesyscloud/genesyscloud/provider"
+ workbin "terraform-provider-genesyscloud/genesyscloud/task_management_workbin"
+ workitemSchema "terraform-provider-genesyscloud/genesyscloud/task_management_workitem_schema"
+ workType "terraform-provider-genesyscloud/genesyscloud/task_management_worktype"
+ "terraform-provider-genesyscloud/genesyscloud/util"
+ "testing"
+
+ "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
+)
+
+/*
+Test Class for the task management worktype status Data Source
+*/
+
+func TestAccDataSourceTaskManagementWorktypeStatus(t *testing.T) {
+ t.Parallel()
+ var (
+ // Workbin
+ wbResourceId = "workbin_1"
+ wbName = "wb_" + uuid.NewString()
+ wbDescription = "workbin created for CX as Code test case"
+
+ // Schema
+ wsResourceId = "schema_1"
+ wsName = "ws_" + uuid.NewString()
+ wsDescription = "workitem schema created for CX as Code test case"
+
+ // Worktype
+ wtResourceId = "worktype_id"
+ wtName = "wt_" + uuid.NewString()
+ wtDescription = "test worktype description"
+
+ // Status Resource
+ statusResourceId = "status_resource"
+ statusName = "status-" + uuid.NewString()
+ statusCategory = "Open"
+
+ // Status Data Source
+ statusDataSourceId = "status_data"
+ )
+
+ resource.Test(t, resource.TestCase{
+ PreCheck: func() { util.TestAccPreCheck(t) },
+ ProviderFactories: provider.GetProviderFactories(providerResources, providerDataSources),
+ Steps: []resource.TestStep{
+ {
+ Config: workbin.GenerateWorkbinResource(wbResourceId, wbName, wbDescription, util.NullValue) +
+ workitemSchema.GenerateWorkitemSchemaResourceBasic(wsResourceId, wsName, wsDescription) +
+ workType.GenerateWorktypeResourceBasic(
+ wtResourceId,
+ wtName,
+ wtDescription,
+ fmt.Sprintf("genesyscloud_task_management_workbin.%s.id", wbResourceId),
+ fmt.Sprintf("genesyscloud_task_management_workitem_schema.%s.id", wsResourceId),
+ "",
+ ) +
+ GenerateWorktypeStatusResource(
+ statusResourceId,
+ fmt.Sprintf("genesyscloud_task_management_worktype.%s.id", wtResourceId),
+ statusName,
+ statusCategory,
+ "",
+ util.NullValue,
+ "",
+ ) +
+ generateWorktypeStatusDataSource(
+ statusDataSourceId,
+ fmt.Sprintf("genesyscloud_task_management_worktype.%s.id", wtResourceId),
+ statusName,
+ resourceName+"."+statusResourceId,
+ ),
+ Check: resource.ComposeTestCheckFunc(
+ ValidateStatusIds(
+ fmt.Sprintf("data.%s.%s", resourceName, statusDataSourceId), "id", fmt.Sprintf("%s.%s", resourceName, statusResourceId), "id",
+ ),
+ ),
+ },
+ },
+ })
+}
+
+func generateWorktypeStatusDataSource(dataSourceId string, worktypeId string, name string, dependsOnResource string) string {
+ return fmt.Sprintf(`data "%s" "%s" {
+ worktype_id = %s
+ name = "%s"
+ depends_on=[%s]
+ }
+ `, resourceName, dataSourceId, worktypeId, name, dependsOnResource)
+}
diff --git a/genesyscloud/task_management_worktype_status/genesyscloud_task_management_worktype_status_init_test.go b/genesyscloud/task_management_worktype_status/genesyscloud_task_management_worktype_status_init_test.go
new file mode 100644
index 000000000..09724771b
--- /dev/null
+++ b/genesyscloud/task_management_worktype_status/genesyscloud_task_management_worktype_status_init_test.go
@@ -0,0 +1,66 @@
+package task_management_worktype_status
+
+import (
+ "sync"
+ workbin "terraform-provider-genesyscloud/genesyscloud/task_management_workbin"
+ workitemSchema "terraform-provider-genesyscloud/genesyscloud/task_management_workitem_schema"
+ worktype "terraform-provider-genesyscloud/genesyscloud/task_management_worktype"
+ "testing"
+
+ "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
+)
+
+/*
+ The genesyscloud_task_management_worktype_status_init_test.go file is used to initialize the data sources and resources
+ used in testing the task_management_worktype_status 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] = ResourceTaskManagementWorktypeStatus()
+ providerResources["genesyscloud_task_management_worktype"] = worktype.ResourceTaskManagementWorktype()
+ providerResources["genesyscloud_task_management_workbin"] = workbin.ResourceTaskManagementWorkbin()
+ providerResources["genesyscloud_task_management_workitem_schema"] = workitemSchema.ResourceTaskManagementWorkitemSchema()
+}
+
+// registerTestDataSources registers all data sources used in the tests.
+func (r *registerTestInstance) registerTestDataSources() {
+ r.datasourceMapMutex.Lock()
+ defer r.datasourceMapMutex.Unlock()
+
+ providerDataSources[resourceName] = DataSourceTaskManagementWorktypeStatus()
+}
+
+// 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 task_management_worktype_status package
+ initTestResources()
+
+ // Run the test suite for the task_management_worktype_status package
+ m.Run()
+}
diff --git a/genesyscloud/task_management_worktype_status/genesyscloud_task_management_worktype_status_proxy.go b/genesyscloud/task_management_worktype_status/genesyscloud_task_management_worktype_status_proxy.go
new file mode 100644
index 000000000..a1f77d7c6
--- /dev/null
+++ b/genesyscloud/task_management_worktype_status/genesyscloud_task_management_worktype_status_proxy.go
@@ -0,0 +1,158 @@
+package task_management_worktype_status
+
+import (
+ "context"
+ "fmt"
+ "github.com/mypurecloud/platform-client-sdk-go/v133/platformclientv2"
+ taskManagementWorktype "terraform-provider-genesyscloud/genesyscloud/task_management_worktype"
+)
+
+/*
+The genesyscloud_task_management_worktype_status_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 *taskManagementWorktypeStatusProxy
+
+// Type definitions for each func on our proxy so we can easily mock them out later
+type createTaskManagementWorktypeStatusFunc func(ctx context.Context, p *taskManagementWorktypeStatusProxy, worktypeId string, workitemStatus *platformclientv2.Workitemstatuscreate) (*platformclientv2.Workitemstatus, *platformclientv2.APIResponse, error)
+type getAllTaskManagementWorktypeStatusFunc func(ctx context.Context, p *taskManagementWorktypeStatusProxy, worktypeId string) (*[]platformclientv2.Workitemstatus, *platformclientv2.APIResponse, error)
+type getTaskManagementWorktypeStatusIdByNameFunc func(ctx context.Context, p *taskManagementWorktypeStatusProxy, worktypeId string, name string) (string, *platformclientv2.APIResponse, bool, error)
+type getTaskManagementWorktypeStatusByIdFunc func(ctx context.Context, p *taskManagementWorktypeStatusProxy, worktypeId string, statusId string) (*platformclientv2.Workitemstatus, *platformclientv2.APIResponse, error)
+type updateTaskManagementWorktypeStatusFunc func(ctx context.Context, p *taskManagementWorktypeStatusProxy, worktypeId string, statusId string, workitemStatus *platformclientv2.Workitemstatusupdate) (*platformclientv2.Workitemstatus, *platformclientv2.APIResponse, error)
+type deleteTaskManagementWorktypeStatusFunc func(ctx context.Context, p *taskManagementWorktypeStatusProxy, worktypeId string, statusId string) (*platformclientv2.APIResponse, error)
+type getTaskManagementWorktypeFunc func(ctx context.Context, p *taskManagementWorktypeStatusProxy, worktypeId string) (*platformclientv2.Worktype, *platformclientv2.APIResponse, error)
+
+// taskManagementWorktypeStatusProxy contains all the methods that call genesys cloud APIs.
+type taskManagementWorktypeStatusProxy struct {
+ clientConfig *platformclientv2.Configuration
+ taskManagementApi *platformclientv2.TaskManagementApi
+ worktypeProxy *taskManagementWorktype.TaskManagementWorktypeProxy
+ createTaskManagementWorktypeStatusAttr createTaskManagementWorktypeStatusFunc
+ getAllTaskManagementWorktypeStatusAttr getAllTaskManagementWorktypeStatusFunc
+ getTaskManagementWorktypeStatusIdByNameAttr getTaskManagementWorktypeStatusIdByNameFunc
+ getTaskManagementWorktypeStatusByIdAttr getTaskManagementWorktypeStatusByIdFunc
+ updateTaskManagementWorktypeStatusAttr updateTaskManagementWorktypeStatusFunc
+ deleteTaskManagementWorktypeStatusAttr deleteTaskManagementWorktypeStatusFunc
+ getTaskManagementWorktypeAttr getTaskManagementWorktypeFunc
+}
+
+// newTaskManagementWorktypeStatusProxy initializes the task management worktype status proxy with all of the data needed to communicate with Genesys Cloud
+func newTaskManagementWorktypeStatusProxy(clientConfig *platformclientv2.Configuration) *taskManagementWorktypeStatusProxy {
+ api := platformclientv2.NewTaskManagementApiWithConfig(clientConfig)
+ taskmanagementProxy := taskManagementWorktype.GetTaskManagementWorktypeProxy(clientConfig)
+ return &taskManagementWorktypeStatusProxy{
+ clientConfig: clientConfig,
+ taskManagementApi: api,
+ worktypeProxy: taskmanagementProxy,
+ createTaskManagementWorktypeStatusAttr: createTaskManagementWorktypeStatusFn,
+ getAllTaskManagementWorktypeStatusAttr: getAllTaskManagementWorktypeStatusFn,
+ getTaskManagementWorktypeStatusIdByNameAttr: getTaskManagementWorktypeStatusIdByNameFn,
+ getTaskManagementWorktypeStatusByIdAttr: getTaskManagementWorktypeStatusByIdFn,
+ updateTaskManagementWorktypeStatusAttr: updateTaskManagementWorktypeStatusFn,
+ deleteTaskManagementWorktypeStatusAttr: deleteTaskManagementWorktypeStatusFn,
+ getTaskManagementWorktypeAttr: getTaskManagementWorktypeFn,
+ }
+}
+
+// getTaskManagementWorktypeStatusProxy 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 getTaskManagementWorktypeStatusProxy(clientConfig *platformclientv2.Configuration) *taskManagementWorktypeStatusProxy {
+ if internalProxy == nil {
+ internalProxy = newTaskManagementWorktypeStatusProxy(clientConfig)
+ }
+
+ return internalProxy
+}
+
+// createTaskManagementWorktypeStatus creates a Genesys Cloud task management worktype status
+func (p *taskManagementWorktypeStatusProxy) createTaskManagementWorktypeStatus(ctx context.Context, worktypeId string, taskManagementWorktypeStatus *platformclientv2.Workitemstatuscreate) (*platformclientv2.Workitemstatus, *platformclientv2.APIResponse, error) {
+ return p.createTaskManagementWorktypeStatusAttr(ctx, p, worktypeId, taskManagementWorktypeStatus)
+}
+
+// getTaskManagementWorktypeStatus retrieves all Genesys Cloud task management worktype status
+func (p *taskManagementWorktypeStatusProxy) getAllTaskManagementWorktypeStatus(ctx context.Context, worktypeId string) (*[]platformclientv2.Workitemstatus, *platformclientv2.APIResponse, error) {
+ return p.getAllTaskManagementWorktypeStatusAttr(ctx, p, worktypeId)
+}
+
+// getTaskManagementWorktypeStatusIdByName returns a single Genesys Cloud task management worktype status by a name
+func (p *taskManagementWorktypeStatusProxy) getTaskManagementWorktypeStatusIdByName(ctx context.Context, worktypeId string, name string) (string, *platformclientv2.APIResponse, bool, error) {
+ return p.getTaskManagementWorktypeStatusIdByNameAttr(ctx, p, worktypeId, name)
+}
+
+// getTaskManagementWorktypeStatusById returns a single Genesys Cloud task management worktype status by Id
+func (p *taskManagementWorktypeStatusProxy) getTaskManagementWorktypeStatusById(ctx context.Context, worktypeId string, statusId string) (*platformclientv2.Workitemstatus, *platformclientv2.APIResponse, error) {
+ return p.getTaskManagementWorktypeStatusByIdAttr(ctx, p, worktypeId, statusId)
+}
+
+// updateTaskManagementWorktypeStatus updates a Genesys Cloud task management worktype status
+func (p *taskManagementWorktypeStatusProxy) updateTaskManagementWorktypeStatus(ctx context.Context, worktypeId string, statusId string, taskManagementWorktypeStatus *platformclientv2.Workitemstatusupdate) (*platformclientv2.Workitemstatus, *platformclientv2.APIResponse, error) {
+ return p.updateTaskManagementWorktypeStatusAttr(ctx, p, worktypeId, statusId, taskManagementWorktypeStatus)
+}
+
+// deleteTaskManagementWorktypeStatus deletes a Genesys Cloud task management worktype status by Id
+func (p *taskManagementWorktypeStatusProxy) deleteTaskManagementWorktypeStatus(ctx context.Context, worktypeId string, statusId string) (*platformclientv2.APIResponse, error) {
+ return p.deleteTaskManagementWorktypeStatusAttr(ctx, p, worktypeId, statusId)
+}
+
+// getTaskManagementWorktype returns a single Genesys Cloud task management worktype
+func (p *taskManagementWorktypeStatusProxy) getTaskManagementWorktype(ctx context.Context, worktypeId string) (*platformclientv2.Worktype, *platformclientv2.APIResponse, error) {
+ return p.getTaskManagementWorktypeAttr(ctx, p, worktypeId)
+}
+
+// createTaskManagementWorktypeStatusFn is an implementation function for creating a Genesys Cloud task management worktype status
+func createTaskManagementWorktypeStatusFn(ctx context.Context, p *taskManagementWorktypeStatusProxy, worktypeId string, taskManagementWorktypeStatus *platformclientv2.Workitemstatuscreate) (*platformclientv2.Workitemstatus, *platformclientv2.APIResponse, error) {
+ return p.taskManagementApi.PostTaskmanagementWorktypeStatuses(worktypeId, *taskManagementWorktypeStatus)
+}
+
+// getAllTaskManagementWorktypeStatusFn is the implementation for retrieving all task management worktype status in Genesys Cloud
+func getAllTaskManagementWorktypeStatusFn(ctx context.Context, p *taskManagementWorktypeStatusProxy, worktypeId string) (*[]platformclientv2.Workitemstatus, *platformclientv2.APIResponse, error) {
+ statuses, resp, err := p.taskManagementApi.GetTaskmanagementWorktypeStatuses(worktypeId)
+ if err != nil {
+ return nil, resp, err
+ }
+
+ return statuses.Entities, resp, nil
+}
+
+// getTaskManagementWorktypeStatusIdByNameFn is an implementation of the function to get a Genesys Cloud task management worktype status by name
+func getTaskManagementWorktypeStatusIdByNameFn(ctx context.Context, p *taskManagementWorktypeStatusProxy, worktypeId string, name string) (string, *platformclientv2.APIResponse, bool, error) {
+ statuses, resp, err := getAllTaskManagementWorktypeStatusFn(ctx, p, worktypeId)
+ if err != nil {
+ return "", resp, false, err
+ }
+
+ if statuses == nil || len(*statuses) == 0 {
+ return "", resp, true, err
+ }
+
+ for _, workitemStatus := range *statuses {
+ if *workitemStatus.Name == name {
+ return *workitemStatus.Id, resp, false, nil
+ }
+ }
+
+ return "", resp, true, fmt.Errorf("Unable to find task management worktype status with name %s", name)
+}
+
+// getTaskManagementWorktypeStatusByIdFn is an implementation of the function to get a Genesys Cloud task management worktype status by Id
+func getTaskManagementWorktypeStatusByIdFn(ctx context.Context, p *taskManagementWorktypeStatusProxy, worktypeId string, statusId string) (*platformclientv2.Workitemstatus, *platformclientv2.APIResponse, error) {
+ return p.taskManagementApi.GetTaskmanagementWorktypeStatus(worktypeId, statusId)
+}
+
+// updateTaskManagementWorktypeStatusFn is an implementation of the function to update a Genesys Cloud task management worktype status
+func updateTaskManagementWorktypeStatusFn(ctx context.Context, p *taskManagementWorktypeStatusProxy, worktypeId string, statusId string, taskManagementWorktypeStatus *platformclientv2.Workitemstatusupdate) (*platformclientv2.Workitemstatus, *platformclientv2.APIResponse, error) {
+ return p.taskManagementApi.PatchTaskmanagementWorktypeStatus(worktypeId, statusId, *taskManagementWorktypeStatus)
+}
+
+// deleteTaskManagementWorktypeStatusFn is an implementation function for deleting a Genesys Cloud task management worktype status
+func deleteTaskManagementWorktypeStatusFn(ctx context.Context, p *taskManagementWorktypeStatusProxy, worktypeId string, statusId string) (*platformclientv2.APIResponse, error) {
+ return p.taskManagementApi.DeleteTaskmanagementWorktypeStatus(worktypeId, statusId)
+}
+
+// getTaskManagementWorktypeFn is an implementation of the function to get a Genesys Cloud task management worktype
+func getTaskManagementWorktypeFn(ctx context.Context, p *taskManagementWorktypeStatusProxy, worktypeId string) (*platformclientv2.Worktype, *platformclientv2.APIResponse, error) {
+ return p.taskManagementApi.GetTaskmanagementWorktype(worktypeId, nil)
+}
diff --git a/genesyscloud/task_management_worktype_status/resource_genesyscloud_task_management_worktype_status.go b/genesyscloud/task_management_worktype_status/resource_genesyscloud_task_management_worktype_status.go
new file mode 100644
index 000000000..4a608e7f4
--- /dev/null
+++ b/genesyscloud/task_management_worktype_status/resource_genesyscloud_task_management_worktype_status.go
@@ -0,0 +1,284 @@
+package task_management_worktype_status
+
+import (
+ "context"
+ "fmt"
+ "log"
+ "strings"
+ "terraform-provider-genesyscloud/genesyscloud/consistency_checker"
+ resourceExporter "terraform-provider-genesyscloud/genesyscloud/resource_exporter"
+ "terraform-provider-genesyscloud/genesyscloud/util/constants"
+ "terraform-provider-genesyscloud/genesyscloud/util/lists"
+ "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/provider"
+ "terraform-provider-genesyscloud/genesyscloud/util"
+ "terraform-provider-genesyscloud/genesyscloud/util/resourcedata"
+
+ "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
+)
+
+/*
+The resource_genesyscloud_task_management_worktype_status.go contains all of the methods that perform the core logic for a resource.
+*/
+
+// getAllAuthTaskManagementWorktypeStatus retrieves all of the task management worktype status via Terraform in the Genesys Cloud and is used for the exporter
+func getAllAuthTaskManagementWorktypeStatuss(ctx context.Context, clientConfig *platformclientv2.Configuration) (resourceExporter.ResourceIDMetaMap, diag.Diagnostics) {
+ proxy := getTaskManagementWorktypeStatusProxy(clientConfig)
+ resources := make(resourceExporter.ResourceIDMetaMap)
+
+ worktypes, resp, err := proxy.worktypeProxy.GetAllTaskManagementWorktype(ctx)
+ if err != nil {
+ return nil, util.BuildAPIDiagnosticError(resourceName, fmt.Sprintf("Failed to get task management worktypes: %v", err), resp)
+ }
+
+ for _, worktype := range *worktypes {
+ worktypeStatuses, resp, err := proxy.getAllTaskManagementWorktypeStatus(ctx, *worktype.Id)
+ if err != nil {
+ return nil, util.BuildAPIDiagnosticError(resourceName, fmt.Sprintf("Failed to get task management worktype statuses: %v", err), resp)
+ }
+
+ for _, status := range *worktypeStatuses {
+ resources[*worktype.Id+"/"+*status.Id] = &resourceExporter.ResourceMeta{Name: *status.Name}
+ }
+ }
+
+ return resources, nil
+}
+
+// createTaskManagementWorktypeStatus is used by the task_management_worktype_status resource to create Genesys cloud task management worktype status
+func createTaskManagementWorktypeStatus(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
+ sdkConfig := meta.(*provider.ProviderMeta).ClientConfig
+ proxy := getTaskManagementWorktypeStatusProxy(sdkConfig)
+ worktypeId := d.Get("worktype_id").(string)
+
+ taskManagementWorktypeStatus := platformclientv2.Workitemstatuscreate{
+ Name: platformclientv2.String(d.Get("name").(string)),
+ Category: platformclientv2.String(d.Get("category").(string)),
+ Description: resourcedata.GetNillableValue[string](d, "description"),
+ DestinationStatusIds: lists.BuildSdkStringListFromInterfaceArray(d, "default_destination_status_id"),
+ DefaultDestinationStatusId: resourcedata.GetNillableValue[string](d, "default_destination_status_id"),
+ StatusTransitionDelaySeconds: resourcedata.GetNillableValue[int](d, "status_transition_delay_seconds"),
+ StatusTransitionTime: resourcedata.GetNillableValue[string](d, "status_transition_time"),
+ }
+
+ err := validateSchema(d)
+ if err != nil {
+ errorMsg := fmt.Sprintf("Failed to create task management worktype %s status %s: %s", worktypeId, *taskManagementWorktypeStatus.Name, err)
+ return util.BuildDiagnosticError(resourceName, errorMsg, fmt.Errorf(errorMsg))
+ }
+
+ log.Printf("Creating task management worktype %s status %s", worktypeId, *taskManagementWorktypeStatus.Name)
+ var (
+ workitemStatus *platformclientv2.Workitemstatus
+ resp *platformclientv2.APIResponse
+ )
+ diagErr := util.WithRetries(ctx, 60*time.Second, func() *retry.RetryError {
+ workitemStatus, resp, err = proxy.createTaskManagementWorktypeStatus(ctx, worktypeId, &taskManagementWorktypeStatus)
+ if err != nil {
+ // The api can throw a 400 if we operate on statuses asynchronously. Retry if we encounter this
+ if util.IsStatus400(resp) && strings.Contains(resp.ErrorMessage, "Database transaction was cancelled"){
+ return retry.RetryableError(util.BuildWithRetriesApiDiagnosticError(resourceName, fmt.Sprintf("Failed to create task management worktype %s status %s: %s", worktypeId, *taskManagementWorktypeStatus.Name, err), resp))
+ }
+ return retry.NonRetryableError(util.BuildWithRetriesApiDiagnosticError(resourceName, fmt.Sprintf("Failed to update task management worktype %s status %s: %s", worktypeId, *taskManagementWorktypeStatus.Name, err), resp))
+ }
+ return nil
+ })
+ if diagErr != nil {
+ return diagErr
+ }
+
+ d.SetId(worktypeId + "/" + *workitemStatus.Id)
+
+ // Check if we need to set this status as the default status on the worktype
+ if d.Get("default").(bool) {
+ log.Printf("Setting status %s as default for worktype %s", *workitemStatus.Id, worktypeId)
+ if diagErr := updateWorktypeDefaultStatus(ctx, proxy, worktypeId, *workitemStatus.Id); diagErr != nil {
+ return diagErr
+ }
+ log.Printf("Status %s set as default for worktype %s", *workitemStatus.Id, worktypeId)
+ }
+
+ log.Printf("Created task management worktype %s status %s %s", worktypeId, *workitemStatus.Id, *workitemStatus.Name)
+ return readTaskManagementWorktypeStatus(ctx, d, meta)
+}
+
+// readTaskManagementWorktypeStatus is used by the task_management_worktype_status resource to read an task management worktype status from genesys cloud
+func readTaskManagementWorktypeStatus(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
+ sdkConfig := meta.(*provider.ProviderMeta).ClientConfig
+ proxy := getTaskManagementWorktypeStatusProxy(sdkConfig)
+ cc := consistency_checker.NewConsistencyCheck(ctx, d, meta, ResourceTaskManagementWorktypeStatus(), constants.DefaultConsistencyChecks, resourceName)
+ worktypeId, statusId := SplitWorktypeStatusTerraformId(d.Id())
+
+ log.Printf("Reading task management worktype %s status %s", worktypeId, statusId)
+
+ return util.WithRetriesForRead(ctx, d, func() *retry.RetryError {
+ workitemStatus, resp, getErr := proxy.getTaskManagementWorktypeStatusById(ctx, worktypeId, statusId)
+ if getErr != nil {
+ if util.IsStatus404(resp) {
+ return retry.RetryableError(util.BuildWithRetriesApiDiagnosticError(resourceName, fmt.Sprintf("Failed to read task management worktype %s status %s: %s", worktypeId, statusId, getErr), resp))
+ }
+ return retry.NonRetryableError(util.BuildWithRetriesApiDiagnosticError(resourceName, fmt.Sprintf("Failed to read task management worktype %s status %s: %s", worktypeId, statusId, getErr), resp))
+ }
+
+ resourcedata.SetNillableValue(d, "worktype_id", workitemStatus.Worktype.Id)
+ resourcedata.SetNillableValue(d, "name", workitemStatus.Name)
+ resourcedata.SetNillableValue(d, "category", workitemStatus.Category)
+ if workitemStatus.DestinationStatuses != nil {
+ destinationStatuses := make([]interface{}, len(*workitemStatus.DestinationStatuses))
+ for i, v := range *workitemStatus.DestinationStatuses {
+ destinationStatuses[i] = *v.Id
+ }
+ _ = d.Set("destination_status_ids", destinationStatuses)
+ }
+ resourcedata.SetNillableValue(d, "description", workitemStatus.Description)
+ if workitemStatus.DefaultDestinationStatus != nil && workitemStatus.DefaultDestinationStatus.Id != nil {
+ _ = d.Set("default_destination_status_id", *workitemStatus.DefaultDestinationStatus.Id)
+ } else {
+ _ = d.Set("default_destination_status_id", "")
+ }
+ resourcedata.SetNillableValue(d, "status_transition_delay_seconds", workitemStatus.StatusTransitionDelaySeconds)
+ resourcedata.SetNillableValue(d, "status_transition_time", workitemStatus.StatusTransitionTime)
+
+ // Check if this status is the default on the worktype
+ worktype, resp, err := proxy.worktypeProxy.GetTaskManagementWorktypeById(ctx, worktypeId)
+ if err != nil {
+ return retry.RetryableError(util.BuildWithRetriesApiDiagnosticError(resourceName, fmt.Sprintf("failed to read worktype %s", worktypeId), resp))
+ }
+
+ _ = d.Set("default", false)
+ if worktype.DefaultStatus != nil && worktype.DefaultStatus.Id != nil && *worktype.DefaultStatus.Id == statusId {
+ _ = d.Set("default", true)
+ }
+
+ log.Printf("Read task management worktype %s status %s %s", worktypeId, statusId, *workitemStatus.Name)
+ return cc.CheckState(d)
+ })
+}
+
+// updateTaskManagementWorktypeStatus is used by the task_management_worktype_status resource to update an task management worktype status in Genesys Cloud
+func updateTaskManagementWorktypeStatus(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
+ sdkConfig := meta.(*provider.ProviderMeta).ClientConfig
+ proxy := getTaskManagementWorktypeStatusProxy(sdkConfig)
+ worktypeId, statusId := SplitWorktypeStatusTerraformId(d.Id())
+
+ err := validateSchema(d)
+ if err != nil {
+ errorMsg := fmt.Sprintf("Failed to update task management worktype %s status %s: %s", worktypeId, statusId, err)
+ return util.BuildDiagnosticError(resourceName, errorMsg, fmt.Errorf(errorMsg))
+ }
+
+ taskManagementWorktypeStatus := platformclientv2.Workitemstatusupdate{
+ Name: platformclientv2.String(d.Get("name").(string)),
+ Description: resourcedata.GetNillableValue[string](d, "description"),
+ DestinationStatusIds: lists.BuildSdkStringListFromInterfaceArray(d, "destination_status_ids"),
+ DefaultDestinationStatusId: resourcedata.GetNillableValue[string](d, "default_destination_status_id"),
+ StatusTransitionDelaySeconds: resourcedata.GetNillableValue[int](d, "status_transition_delay_seconds"),
+ StatusTransitionTime: resourcedata.GetNillableValue[string](d, "status_transition_time"),
+ }
+
+ // If the user makes a reference to a status that is managed by terraform the id will look like this /
+ // so we need to extract just the status id from any status references that look like this
+ if taskManagementWorktypeStatus.DestinationStatusIds != nil && len(*taskManagementWorktypeStatus.DestinationStatusIds) > 0 {
+ for i, destinationStatusId := range *taskManagementWorktypeStatus.DestinationStatusIds {
+ if strings.Contains(destinationStatusId, "/") {
+ _, id := SplitWorktypeStatusTerraformId(destinationStatusId)
+ (*taskManagementWorktypeStatus.DestinationStatusIds)[i] = id
+ }
+ }
+ }
+
+ if taskManagementWorktypeStatus.DefaultDestinationStatusId != nil && strings.Contains(*taskManagementWorktypeStatus.DefaultDestinationStatusId, "/") {
+ _, id := SplitWorktypeStatusTerraformId(*taskManagementWorktypeStatus.DefaultDestinationStatusId)
+ taskManagementWorktypeStatus.DefaultDestinationStatusId = &id
+ }
+
+ log.Printf("Updating task management worktype %s status %s %s", worktypeId, statusId, *taskManagementWorktypeStatus.Name)
+
+ var (
+ workitemStatus *platformclientv2.Workitemstatus
+ resp *platformclientv2.APIResponse
+ )
+ diagErr := util.WithRetries(ctx, 60*time.Second, func() *retry.RetryError {
+ workitemStatus, resp, err = proxy.updateTaskManagementWorktypeStatus(ctx, worktypeId, statusId, &taskManagementWorktypeStatus)
+ if err != nil {
+ // The api can throw a 400 if we operate on statuses asynchronously. Retry if we encounter this
+ if util.IsStatus400(resp) && strings.Contains(resp.ErrorMessage, "Database transaction was cancelled"){
+ return retry.RetryableError(util.BuildWithRetriesApiDiagnosticError(resourceName, fmt.Sprintf("Failed to update task management worktype %s status %s: %s", worktypeId, statusId, err), resp))
+ }
+ return retry.NonRetryableError(util.BuildWithRetriesApiDiagnosticError(resourceName, fmt.Sprintf("Failed to update task management worktype %s status %s: %s", worktypeId, statusId, err), resp))
+ }
+ return nil
+ })
+ if diagErr != nil {
+ return diagErr
+ }
+
+ // Check if we need to set this status as the default status on the worktype
+ if d.Get("default").(bool) {
+ log.Printf("Setting status %s as default for worktype %s", statusId, worktypeId)
+ if diagErr := updateWorktypeDefaultStatus(ctx, proxy, worktypeId, *workitemStatus.Id); diagErr != nil {
+ return diagErr
+ }
+ log.Printf("Status %s set as default for worktype %s", statusId, worktypeId)
+ }
+
+ log.Printf("Updated task management worktype %s status %s %s", worktypeId, *workitemStatus.Id, *workitemStatus.Id)
+ return readTaskManagementWorktypeStatus(ctx, d, meta)
+}
+
+// deleteTaskManagementWorktypeStatus is used by the task_management_worktype_status resource to delete an task management worktype status from Genesys cloud
+func deleteTaskManagementWorktypeStatus(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
+ sdkConfig := meta.(*provider.ProviderMeta).ClientConfig
+ proxy := getTaskManagementWorktypeStatusProxy(sdkConfig)
+ worktypeId, statusId := SplitWorktypeStatusTerraformId(d.Id())
+
+ // Check if worktype exists before trying to check the status. If the worktype is gone then so it the status
+ _, resp, err := proxy.getTaskManagementWorktypeStatusById(ctx, worktypeId, statusId)
+ if err != nil {
+ if util.IsStatus404(resp) {
+ log.Printf("Task management worktype %s already deleted", worktypeId)
+ return nil
+ }
+ }
+
+ // Can't delete the status if it's the default on the worktype
+ if d.Get("default").(bool) {
+ log.Printf("Unable to delete default status %s for worktype %s", statusId, worktypeId)
+ return nil
+ }
+
+ log.Printf("Deleting task management worktype %s status %s", worktypeId, statusId)
+
+ diagErr := util.WithRetries(ctx, 60*time.Second, func() *retry.RetryError {
+ resp, err = proxy.deleteTaskManagementWorktypeStatus(ctx, worktypeId, statusId)
+ if err != nil {
+ // The api can throw a 400 if we operate on statuses asynchronously. Retry if we encounter this
+ if util.IsStatus400(resp) && strings.Contains(resp.ErrorMessage, "Database transaction was cancelled"){
+ return retry.RetryableError(util.BuildWithRetriesApiDiagnosticError(resourceName, fmt.Sprintf("Failed to delete task management worktype %s status %s: %s", worktypeId, statusId, err), resp))
+ }
+ return retry.NonRetryableError(util.BuildWithRetriesApiDiagnosticError(resourceName, fmt.Sprintf("Failed to delete task management worktype %s status %s: %s", worktypeId, statusId, err), resp))
+ }
+ return nil
+ })
+ if diagErr != nil {
+ return diagErr
+ }
+
+ return util.WithRetries(ctx, 180*time.Second, func() *retry.RetryError {
+ _, resp, err = proxy.getTaskManagementWorktypeStatusById(ctx, worktypeId, statusId)
+ if err != nil {
+ if util.IsStatus404(resp) {
+ log.Printf("Deleted task management worktype %s status %s", worktypeId, statusId)
+ return nil
+ }
+ return retry.NonRetryableError(util.BuildWithRetriesApiDiagnosticError(resourceName, fmt.Sprintf("Error deleting task management worktype %s status %s: %s", worktypeId, statusId, err), resp))
+ }
+
+ return retry.RetryableError(util.BuildWithRetriesApiDiagnosticError(resourceName, fmt.Sprintf("task management worktype %s status %s still exists", worktypeId, statusId), resp))
+ })
+}
diff --git a/genesyscloud/task_management_worktype_status/resource_genesyscloud_task_management_worktype_status_schema.go b/genesyscloud/task_management_worktype_status/resource_genesyscloud_task_management_worktype_status_schema.go
new file mode 100644
index 000000000..a8b4145b2
--- /dev/null
+++ b/genesyscloud/task_management_worktype_status/resource_genesyscloud_task_management_worktype_status_schema.go
@@ -0,0 +1,134 @@
+package task_management_worktype_status
+
+import (
+ "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
+ "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
+ "terraform-provider-genesyscloud/genesyscloud/provider"
+ resourceExporter "terraform-provider-genesyscloud/genesyscloud/resource_exporter"
+ registrar "terraform-provider-genesyscloud/genesyscloud/resource_register"
+)
+
+/*
+resource_genesycloud_task_management_worktype_status_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 task_management_worktype_status resource.
+3. The datasource schema definitions for the task_management_worktype_status datasource.
+4. The resource exporter configuration for the task_management_worktype_status exporter.
+*/
+const resourceName = "genesyscloud_task_management_worktype_status"
+
+// SetRegistrar registers all of the resources, datasources and exporters in the package
+func SetRegistrar(regInstance registrar.Registrar) {
+ regInstance.RegisterResource(resourceName, ResourceTaskManagementWorktypeStatus())
+ regInstance.RegisterDataSource(resourceName, DataSourceTaskManagementWorktypeStatus())
+ regInstance.RegisterExporter(resourceName, TaskManagementWorktypeStatusExporter())
+}
+
+// ResourceTaskManagementWorktypeStatus registers the genesyscloud_task_management_worktype_status resource with Terraform
+func ResourceTaskManagementWorktypeStatus() *schema.Resource {
+ return &schema.Resource{
+ Description: `Genesys Cloud task management worktype status`,
+
+ CreateContext: provider.CreateWithPooledClient(createTaskManagementWorktypeStatus),
+ ReadContext: provider.ReadWithPooledClient(readTaskManagementWorktypeStatus),
+ UpdateContext: provider.UpdateWithPooledClient(updateTaskManagementWorktypeStatus),
+ DeleteContext: provider.DeleteWithPooledClient(deleteTaskManagementWorktypeStatus),
+ Importer: &schema.ResourceImporter{
+ StateContext: schema.ImportStatePassthroughContext,
+ },
+ SchemaVersion: 1,
+ Schema: map[string]*schema.Schema{
+ "worktype_id": {
+ Description: `The id of the worktype this status belongs to. Changing this attribute will cause the status to be dropped and recreated.`,
+ Type: schema.TypeString,
+ Required: true,
+ ForceNew: true,
+ },
+ `name`: {
+ Description: `Name of the status.`,
+ Required: true,
+ Type: schema.TypeString,
+ ValidateFunc: validation.StringLenBetween(3, 256),
+ },
+ `category`: {
+ Description: `The Category of the Status. Changing the category will cause the resource to be dropped and recreated with a new id.`,
+ Required: true,
+ Type: schema.TypeString,
+ ValidateFunc: validation.StringInSlice([]string{"Open", "Waiting", "Closed", "Unknown"}, false),
+ ForceNew: true,
+ },
+ `description`: {
+ Description: `The description of the Status.`,
+ Optional: true,
+ Type: schema.TypeString,
+ ValidateFunc: validation.StringLenBetween(0, 4096),
+ },
+ `destination_status_ids`: {
+ Description: `A list of destination Statuses where a Workitem with this Status can transition to. If the list is empty Workitems with this Status can transition to all other Statuses defined on the Worktype. A Status can have a maximum of 24 destinations.`,
+ Optional: true,
+ Type: schema.TypeList,
+ Elem: &schema.Schema{
+ Type: schema.TypeString,
+ StateFunc: ModifyStatusIdStateValue,
+ },
+ MaxItems: 24,
+ },
+ `default_destination_status_id`: {
+ Description: `Default destination status to which this Status will transition to if auto status transition enabled.`,
+ Optional: true,
+ StateFunc: ModifyStatusIdStateValue,
+ Type: schema.TypeString,
+ },
+ `status_transition_delay_seconds`: {
+ Description: `Delay in seconds for auto status transition. Required if default_destination_status_id is provided.`,
+ Optional: true,
+ Type: schema.TypeInt,
+ ValidateFunc: validation.IntAtLeast(60),
+ },
+ `status_transition_time`: {
+ Description: `Time is represented as an ISO-8601 string without a timezone. For example: HH:mm:ss`,
+ Optional: true,
+ Type: schema.TypeString,
+ },
+ `default`: {
+ Description: `This status is the default status for Workitems created from this Worktype. Only one status can be set as the default status at a time.`,
+ Optional: true,
+ Type: schema.TypeBool,
+ },
+ },
+ }
+}
+
+// TaskManagementWorktypeStatusExporter returns the resourceExporter object used to hold the genesyscloud_task_management_worktype_status exporter's config
+func TaskManagementWorktypeStatusExporter() *resourceExporter.ResourceExporter {
+ return &resourceExporter.ResourceExporter{
+ GetResourcesFunc: provider.GetAllWithPooledClient(getAllAuthTaskManagementWorktypeStatuss),
+ RefAttrs: map[string]*resourceExporter.RefAttrSettings{
+ "worktype_id": {RefType: "genesyscloud_task_management_worktype"},
+ },
+ }
+}
+
+// DataSourceTaskManagementWorktypeStatus registers the genesyscloud_task_management_worktype_status data source
+func DataSourceTaskManagementWorktypeStatus() *schema.Resource {
+ return &schema.Resource{
+ Description: `Genesys Cloud task management worktype status data source. Select an task management worktype status by name`,
+ ReadContext: provider.ReadWithPooledClient(dataSourceTaskManagementWorktypeStatusRead),
+ Importer: &schema.ResourceImporter{
+ StateContext: schema.ImportStatePassthroughContext,
+ },
+ Schema: map[string]*schema.Schema{
+ "worktype_id": {
+ Description: `The id of the worktype the status belongs to`,
+ Type: schema.TypeString,
+ Required: true,
+ },
+ "name": {
+ Description: `Task management worktype status name`,
+ Type: schema.TypeString,
+ Required: true,
+ },
+ },
+ }
+}
diff --git a/genesyscloud/task_management_worktype_status/resource_genesyscloud_task_management_worktype_status_test.go b/genesyscloud/task_management_worktype_status/resource_genesyscloud_task_management_worktype_status_test.go
new file mode 100644
index 000000000..c7644a6dc
--- /dev/null
+++ b/genesyscloud/task_management_worktype_status/resource_genesyscloud_task_management_worktype_status_test.go
@@ -0,0 +1,174 @@
+package task_management_worktype_status
+
+import (
+ "fmt"
+ "github.com/google/uuid"
+ "github.com/mypurecloud/platform-client-sdk-go/v133/platformclientv2"
+ "strings"
+ "terraform-provider-genesyscloud/genesyscloud/provider"
+ workbin "terraform-provider-genesyscloud/genesyscloud/task_management_workbin"
+ workitemSchema "terraform-provider-genesyscloud/genesyscloud/task_management_workitem_schema"
+ workType "terraform-provider-genesyscloud/genesyscloud/task_management_worktype"
+ "terraform-provider-genesyscloud/genesyscloud/util"
+ "testing"
+
+ "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
+
+ "github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
+)
+
+/*
+The resource_genesyscloud_task_management_worktype_status_test.go contains all of the test cases for running the resource
+tests for task_management_worktype_status.
+*/
+
+func TestAccResourceTaskManagementWorktypeStatus(t *testing.T) {
+ t.Parallel()
+ var (
+ // Workbin
+ wbResourceId = "workbin_1"
+ wbName = "wb_" + uuid.NewString()
+ wbDescription = "workbin created for CX as Code test case"
+
+ // Schema
+ wsResourceId = "schema_1"
+ wsName = "ws_" + uuid.NewString()
+ wsDescription = "workitem schema created for CX as Code test case"
+
+ // Worktype
+ wtResourceId = "worktype_id"
+ wtName = "wt_" + uuid.NewString()
+ wtDescription = "test worktype description"
+
+ // Status 1
+ statusResource1 = "status1"
+ status1Name1 = "status1-" + uuid.NewString()
+ status1Category = "Open"
+ status1Name2 = "status1-" + uuid.NewString()
+ status1Description = "test description"
+
+ // Status 2
+ statusResource2 = "status2"
+ status2Name = "status2-" + uuid.NewString()
+ status2Category = "Closed"
+ )
+
+ resource.Test(t, resource.TestCase{
+ PreCheck: func() { util.TestAccPreCheck(t) },
+ ProviderFactories: provider.GetProviderFactories(providerResources, providerDataSources),
+ Steps: []resource.TestStep{
+ {
+ // Create worktype status
+ Config: workbin.GenerateWorkbinResource(wbResourceId, wbName, wbDescription, util.NullValue) +
+ workitemSchema.GenerateWorkitemSchemaResourceBasic(wsResourceId, wsName, wsDescription) +
+ workType.GenerateWorktypeResourceBasic(
+ wtResourceId,
+ wtName,
+ wtDescription,
+ fmt.Sprintf("genesyscloud_task_management_workbin.%s.id", wbResourceId),
+ fmt.Sprintf("genesyscloud_task_management_workitem_schema.%s.id", wsResourceId),
+ "",
+ ) +
+ GenerateWorktypeStatusResource(
+ statusResource1,
+ fmt.Sprintf("genesyscloud_task_management_worktype.%s.id", wtResourceId),
+ status1Name1,
+ status1Category,
+ "",
+ util.NullValue,
+ "",
+ "default = true",
+ ),
+ Check: resource.ComposeTestCheckFunc(
+ resource.TestCheckResourceAttrPair(resourceName+"."+statusResource1, "worktype_id", fmt.Sprintf("genesyscloud_task_management_worktype.%s", wtResourceId), "id"),
+ resource.TestCheckResourceAttr(resourceName+"."+statusResource1, "name", status1Name1),
+ resource.TestCheckResourceAttr(resourceName+"."+statusResource1, "category", status1Category),
+ resource.TestCheckResourceAttr(resourceName+"."+statusResource1, "status_transition_delay_seconds", "0"),
+ resource.TestCheckResourceAttr(resourceName+"."+statusResource1, "default", util.TrueValue),
+ ),
+ },
+ {
+ // Update worktype status and add another status so we can test destination_status_ids and default_destination_status_id
+ Config: workbin.GenerateWorkbinResource(wbResourceId, wbName, wbDescription, util.NullValue) +
+ workitemSchema.GenerateWorkitemSchemaResourceBasic(wsResourceId, wsName, wsDescription) +
+ workType.GenerateWorktypeResourceBasic(
+ wtResourceId,
+ wtName,
+ wtDescription,
+ fmt.Sprintf("genesyscloud_task_management_workbin.%s.id", wbResourceId),
+ fmt.Sprintf("genesyscloud_task_management_workitem_schema.%s.id", wsResourceId),
+ "",
+ ) +
+ GenerateWorktypeStatusResource(
+ statusResource1,
+ fmt.Sprintf("genesyscloud_task_management_worktype.%s.id", wtResourceId),
+ status1Name2,
+ status1Category,
+ status1Description,
+ fmt.Sprintf("genesyscloud_task_management_worktype_status.%s.id", statusResource2),
+ "12:04:21",
+ generateDestinationStatusIdsArray([]string{fmt.Sprintf("genesyscloud_task_management_worktype_status.%s.id", statusResource2)}),
+ fmt.Sprintf("status_transition_delay_seconds = %d", 90000),
+ "default = false",
+ ) +
+ // This status is used as a reference in the first status
+ GenerateWorktypeStatusResource(
+ statusResource2,
+ fmt.Sprintf("genesyscloud_task_management_worktype.%s.id", wtResourceId),
+ status2Name,
+ status2Category,
+ "",
+ util.NullValue,
+ "",
+ "default = true",
+ ),
+ Check: resource.ComposeTestCheckFunc(
+ resource.TestCheckResourceAttrPair(resourceName+"."+statusResource1, "worktype_id", fmt.Sprintf("genesyscloud_task_management_worktype.%s", wtResourceId), "id"),
+ resource.TestCheckResourceAttr(resourceName+"."+statusResource1, "name", status1Name2),
+ resource.TestCheckResourceAttr(resourceName+"."+statusResource1, "category", status1Category),
+ resource.TestCheckResourceAttr(resourceName+"."+statusResource1, "description", status1Description),
+ ValidateStatusIds(resourceName+"."+statusResource1, "destination_status_ids.0", fmt.Sprintf("%s.%s", resourceName, statusResource2), "id"),
+ ValidateStatusIds(resourceName+"."+statusResource1, "default_destination_status_id", fmt.Sprintf("%s.%s", resourceName, statusResource2), "id"),
+ resource.TestCheckResourceAttr(resourceName+"."+statusResource1, "status_transition_delay_seconds", "90000"),
+ resource.TestCheckResourceAttr(resourceName+"."+statusResource1, "status_transition_time", "12:04:21"),
+ resource.TestCheckResourceAttr(resourceName+"."+statusResource1, "default", util.FalseValue),
+ resource.TestCheckResourceAttr(resourceName+"."+statusResource2, "default", util.TrueValue),
+ ),
+ },
+ {
+ // Import/Read
+ ResourceName: "genesyscloud_task_management_worktype_status." + statusResource1,
+ ImportState: true,
+ ImportStateVerify: true,
+ },
+ },
+ CheckDestroy: testVerifyTaskManagementWorktypeStatusDestroyed,
+ })
+}
+
+func testVerifyTaskManagementWorktypeStatusDestroyed(state *terraform.State) error {
+ taskManagementApi := platformclientv2.NewTaskManagementApi()
+ for _, res := range state.RootModule().Resources {
+ if res.Type != resourceName {
+ continue
+ }
+
+ worktypeId, statusId := SplitWorktypeStatusTerraformId(res.Primary.ID)
+ worktypeStatus, resp, err := taskManagementApi.GetTaskmanagementWorktypeStatus(worktypeId, statusId)
+ if worktypeStatus != nil {
+ return fmt.Errorf("task management worktype status (%s) still exists", res.Primary.ID)
+ } else if util.IsStatus404(resp) {
+ // Worktype no found, as expected
+ continue
+ } else {
+ return fmt.Errorf("unexpected error: %s", err)
+ }
+ }
+
+ // All worktype statuses deleted
+ return nil
+}
+
+func generateDestinationStatusIdsArray(destinationIds []string) string {
+ return fmt.Sprintf(`destination_status_ids = [%s]`, strings.Join(destinationIds, ", "))
+}
diff --git a/genesyscloud/task_management_worktype_status/resource_genesyscloud_task_management_worktype_status_util.go b/genesyscloud/task_management_worktype_status/resource_genesyscloud_task_management_worktype_status_util.go
new file mode 100644
index 000000000..edabc6ca9
--- /dev/null
+++ b/genesyscloud/task_management_worktype_status/resource_genesyscloud_task_management_worktype_status_util.go
@@ -0,0 +1,114 @@
+package task_management_worktype_status
+
+import (
+ "context"
+ "fmt"
+ "github.com/hashicorp/terraform-plugin-sdk/v2/diag"
+ "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
+ "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
+ "github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
+ "github.com/mypurecloud/platform-client-sdk-go/v133/platformclientv2"
+ "strings"
+ "terraform-provider-genesyscloud/genesyscloud/util"
+)
+
+// ModifyStatusIdStateValue will change the statusId before it is saved in the state file.
+// The worktype_status resource saves the status id as /.
+// We only want to save the statusId in the state as the api will only return the status id
+// and this cause would 'plan not empty' if we save the id as /
+func ModifyStatusIdStateValue(id interface{}) string {
+ statusId := id.(string)
+ if strings.Contains(statusId, "/") {
+ return strings.Split(statusId, "/")[1]
+ }
+
+ return statusId
+}
+
+// SplitWorktypeStatusTerraformId will split the status resource id which is in the form
+// / into just the worktypeId and statusId string
+func SplitWorktypeStatusTerraformId(id string) (worktypeId string, statusId string) {
+ return strings.Split(id, "/")[0], strings.Split(id, "/")[1]
+}
+
+// validateSchema checks if status_transition_delay_seconds was provided with default_destination_status_id
+func validateSchema(d *schema.ResourceData) error {
+ if d.Get("default_destination_status_id").(string) != "" {
+ if d.Get("status_transition_delay_seconds").(int) == 0 {
+ return fmt.Errorf("status_transition_delay_seconds is required with default_destination_status_id")
+ }
+ }
+
+ return nil
+}
+
+func updateWorktypeDefaultStatus(ctx context.Context, proxy *taskManagementWorktypeStatusProxy, worktypeId string, statusId string) diag.Diagnostics {
+ worktypeUpdate := platformclientv2.Worktypeupdate{
+ DefaultStatusId: &statusId,
+ }
+
+ _, resp, err := proxy.worktypeProxy.UpdateTaskManagementWorktype(ctx, worktypeId, &worktypeUpdate)
+ if err != nil {
+ return util.BuildAPIDiagnosticError(resourceName, fmt.Sprintf("Failed to update worktype %s with default status %s.", worktypeId, statusId), resp)
+ }
+
+ return nil
+}
+
+func GenerateWorktypeStatusResource(
+ resourceName,
+ workTypeId,
+ name,
+ category,
+ description string,
+ defaultDestinationStatusId string,
+ statusTransitionTime string,
+ attrs ...string,
+) string {
+ return fmt.Sprintf(
+ `resource "genesyscloud_task_management_worktype_status" "%s" {
+ worktype_id = %s
+ name = "%s"
+ category = "%s"
+ description = "%s"
+ default_destination_status_id = %s
+ status_transition_time = "%s"
+ %s
+ }
+`, resourceName, workTypeId, name, category, description, defaultDestinationStatusId, statusTransitionTime, strings.Join(attrs, "\n"))
+}
+
+// ValidateStatusIds will check that two status ids are the same
+// We need this to handle situations where a reference to a status resource is used. In this case
+// the id will be in the format / which is allowed but there terraform function cant check for this
+func ValidateStatusIds(statusResource1 string, key1 string, statusResource2 string, key2 string) resource.TestCheckFunc {
+ return func(state *terraform.State) error {
+ status1, ok := state.RootModule().Resources[statusResource1]
+ if !ok {
+ return fmt.Errorf("failed to find status %s in state", statusResource1)
+ }
+
+ status2, ok := state.RootModule().Resources[statusResource2]
+ if !ok {
+ return fmt.Errorf("failed to find status %s in state", statusResource1)
+ }
+
+ status1KeyValue := status1.Primary.Attributes[key1]
+ if strings.Contains(status1KeyValue, "/") {
+ _, status1KeyValue = SplitWorktypeStatusTerraformId(status1KeyValue)
+ }
+
+ status2KeyValue := status2.Primary.Attributes[key2]
+ if strings.Contains(status2KeyValue, "/") {
+ _, status2KeyValue = SplitWorktypeStatusTerraformId(status2KeyValue)
+ }
+
+ if status1KeyValue != status2KeyValue {
+ attr1 := statusResource1 + "." + key1
+ attr2 := statusResource2 + "." + key2
+ return fmt.Errorf("%s not equal to %s\n %s = %s\n %s = %s", attr1, attr2, attr1, status1KeyValue, attr2, status2KeyValue)
+ }
+
+ return nil
+ }
+}
diff --git a/genesyscloud/telephony_providers_edges_phone/resource_genesyscloud_telephony_providers_edges_phone_test.go b/genesyscloud/telephony_providers_edges_phone/resource_genesyscloud_telephony_providers_edges_phone_test.go
index 4e8421b64..63b83eb52 100644
--- a/genesyscloud/telephony_providers_edges_phone/resource_genesyscloud_telephony_providers_edges_phone_test.go
+++ b/genesyscloud/telephony_providers_edges_phone/resource_genesyscloud_telephony_providers_edges_phone_test.go
@@ -463,7 +463,7 @@ func TestAccResourcePhoneStandaloneRemoteStation(t *testing.T) {
locationRes := "test-location"
- emergencyNumber := "+13173114164"
+ emergencyNumber := "+13173117632"
if err := edgeSite.DeleteLocationWithNumber(emergencyNumber, sdkConfig); err != nil {
t.Skipf("failed to delete location with number %s: %v", emergencyNumber, err)
}
diff --git a/genesyscloud/tfexporter/resource_genesyscloud_tf_export_test.go b/genesyscloud/tfexporter/resource_genesyscloud_tf_export_test.go
index 5d189152c..f0f6fc34b 100644
--- a/genesyscloud/tfexporter/resource_genesyscloud_tf_export_test.go
+++ b/genesyscloud/tfexporter/resource_genesyscloud_tf_export_test.go
@@ -1455,6 +1455,7 @@ func TestAccResourceExportManagedSitesAsData(t *testing.T) {
exportTestDir = filepath.Join("..", "..", ".terraform"+uuid.NewString())
resourceID = "export"
configPath = filepath.Join(exportTestDir, defaultTfJSONFile)
+ statePath = filepath.Join(exportTestDir, defaultTfStateFile)
siteName = "PureCloud Voice - AWS"
)
@@ -1476,7 +1477,7 @@ func TestAccResourceExportManagedSitesAsData(t *testing.T) {
Config: generateTfExportByIncludeFilterResources(
resourceID,
exportTestDir,
- util.FalseValue, // include_state_file
+ util.TrueValue, // include_state_file
[]string{ // include_filter_resources
strconv.Quote("genesyscloud_telephony_providers_edges_site"),
},
@@ -1485,6 +1486,7 @@ func TestAccResourceExportManagedSitesAsData(t *testing.T) {
[]string{},
),
Check: resource.ComposeTestCheckFunc(
+ validateStateFileAsData(statePath, siteName),
validateExportManagedSitesAsData(configPath, siteName),
),
},
@@ -1492,6 +1494,60 @@ func TestAccResourceExportManagedSitesAsData(t *testing.T) {
})
}
+// validateStateFileAsData verifies that the default managed site 'PureCloud Voice - AWS' is exported as a data source
+func validateStateFileAsData(filename, siteName string) resource.TestCheckFunc {
+ return func(state *terraform.State) error {
+ _, err := os.Stat(filename)
+ if err != nil {
+ return fmt.Errorf("failed to find file %s", filename)
+ }
+
+ stateData, err := loadJsonFileToMap(filename)
+ if err != nil {
+ return err
+ }
+ log.Println("Successfully loaded export config into map variable ")
+
+ // Check if data sources exist in the exported data
+ if resources, ok := stateData["resources"].([]interface{}); ok {
+ fmt.Printf("checking that managed site with name %s is exported as data source in tf state", siteName)
+
+ // Validate each site's name
+ for _, r := range resources {
+ fmt.Printf("resource that managed site with name %s is exported as data source", r)
+
+ res, ok := r.(map[string]interface{})
+ if !ok {
+ return fmt.Errorf("unexpected structure for site %s", siteName)
+ }
+
+ name, ok := res["name"].(string)
+ if !ok {
+ return fmt.Errorf("unexpected structure for site %s", siteName)
+ }
+
+ mode, ok := res["mode"].(string)
+ if !ok {
+ return fmt.Errorf("unexpected structure for site %s", siteName)
+ }
+
+ if name == strings.ReplaceAll(siteName, " ", "_") {
+ if mode == "data" {
+ log.Printf("Site with name '%s' is correctly exported as data source", siteName)
+ return nil
+ } else {
+ log.Printf("Site with name '%s' is not correctly exported as data", siteName)
+ return nil
+ }
+ }
+ }
+ return fmt.Errorf("No Resources '%s' was not exported as data source", siteName)
+ } else {
+ return fmt.Errorf("No data sources found in exported data")
+ }
+ }
+}
+
// validateExportManagedSitesAsData verifies that the default managed site 'PureCloud Voice - AWS' is exported as a data source
func validateExportManagedSitesAsData(filename, siteName string) resource.TestCheckFunc {
return func(state *terraform.State) error {
diff --git a/genesyscloud/tfexporter/tf_exporter_resource_test.go b/genesyscloud/tfexporter/tf_exporter_resource_test.go
index 19364f3ef..9be980db9 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"
@@ -61,6 +62,8 @@ import (
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"
+ routingSkillGroup "terraform-provider-genesyscloud/genesyscloud/routing_skill_group"
+ routingSkill "terraform-provider-genesyscloud/genesyscloud/routing_skill"
routingSmsAddress "terraform-provider-genesyscloud/genesyscloud/routing_sms_addresses"
routingUtilization "terraform-provider-genesyscloud/genesyscloud/routing_utilization"
routingUtilizationLabel "terraform-provider-genesyscloud/genesyscloud/routing_utilization_label"
@@ -68,6 +71,7 @@ import (
workbin "terraform-provider-genesyscloud/genesyscloud/task_management_workbin"
workitemSchema "terraform-provider-genesyscloud/genesyscloud/task_management_workitem_schema"
worktype "terraform-provider-genesyscloud/genesyscloud/task_management_worktype"
+ worktypeStatus "terraform-provider-genesyscloud/genesyscloud/task_management_worktype_status"
telephony "terraform-provider-genesyscloud/genesyscloud/telephony"
didPool "terraform-provider-genesyscloud/genesyscloud/telephony_providers_edges_did_pool"
edgeGroup "terraform-provider-genesyscloud/genesyscloud/telephony_providers_edges_edge_group"
@@ -160,7 +164,7 @@ func (r *registerTestInstance) registerTestResources() {
providerResources["genesyscloud_routing_queue"] = routingQueue.ResourceRoutingQueue()
providerResources["genesyscloud_routing_queue_conditional_group_routing"] = routingQueueConditionalGroupRouting.ResourceRoutingQueueConditionalGroupRouting()
providerResources["genesyscloud_routing_queue_outbound_email_address"] = routingQueueOutboundEmailAddress.ResourceRoutingQueueOutboundEmailAddress()
- providerResources["genesyscloud_routing_skill"] = gcloud.ResourceRoutingSkill()
+ providerResources["genesyscloud_routing_skill"] = routingSkill.ResourceRoutingSkill()
providerResources["genesyscloud_routing_settings"] = routingSettings.ResourceRoutingSettings()
providerResources["genesyscloud_routing_utilization"] = routingUtilization.ResourceRoutingUtilization()
providerResources["genesyscloud_routing_utilization_label"] = routingUtilizationLabel.ResourceRoutingUtilizationLabel()
@@ -197,14 +201,18 @@ func (r *registerTestInstance) registerTestResources() {
providerResources["genesyscloud_quality_forms_survey"] = gcloud.ResourceSurveyForm()
providerResources["genesyscloud_responsemanagement_response"] = responsemanagementResponse.ResourceResponsemanagementResponse()
providerResources["genesyscloud_routing_sms_address"] = routingSmsAddress.ResourceRoutingSmsAddress()
- providerResources["genesyscloud_routing_skill_group"] = gcloud.ResourceRoutingSkillGroup()
+ providerResources["genesyscloud_routing_skill_group"] = routingSkillGroup.ResourceRoutingSkillGroup()
providerResources["genesyscloud_telephony_providers_edges_did_pool"] = didPool.ResourceTelephonyDidPool()
providerResources["genesyscloud_script"] = scripts.ResourceScript()
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_task_management_worktype_status"] = worktypeStatus.ResourceTaskManagementWorktypeStatus()
providerResources["genesyscloud_tf_export"] = ResourceTfExport()
}
@@ -275,8 +283,8 @@ func (r *registerTestInstance) registerTestExporters() {
RegisterExporter("genesyscloud_routing_queue_conditional_group_routing", routingQueueConditionalGroupRouting.RoutingQueueConditionalGroupRoutingExporter())
RegisterExporter("genesyscloud_routing_queue_outbound_email_address", routingQueueOutboundEmailAddress.OutboundRoutingQueueOutboundEmailAddressExporter())
RegisterExporter("genesyscloud_routing_settings", routingSettings.RoutingSettingsExporter())
- RegisterExporter("genesyscloud_routing_skill", gcloud.RoutingSkillExporter())
- RegisterExporter("genesyscloud_routing_skill_group", gcloud.ResourceSkillGroupExporter())
+ RegisterExporter("genesyscloud_routing_skill_group", routingSkillGroup.ResourceSkillGroupExporter())
+ RegisterExporter("genesyscloud_routing_skill", routingSkill.RoutingSkillExporter())
RegisterExporter("genesyscloud_routing_sms_address", routingSmsAddress.RoutingSmsAddressExporter())
RegisterExporter("genesyscloud_routing_utilization", routingUtilization.RoutingUtilizationExporter())
RegisterExporter("genesyscloud_routing_utilization_label", routingUtilizationLabel.RoutingUtilizationLabelExporter())
@@ -306,6 +314,9 @@ func (r *registerTestInstance) registerTestExporters() {
RegisterExporter("genesyscloud_task_management_workitem_schema", workbin.TaskManagementWorkbinExporter())
RegisterExporter("genesyscloud_task_management_worktype", worktype.TaskManagementWorktypeExporter())
RegisterExporter("genesyscloud_conversations_messaging_settings", cMessagingSettings.ConversationsMessagingSettingsExporter())
+ RegisterExporter("genesyscloud_task_management_worktype_status", worktypeStatus.TaskManagementWorktypeStatusExporter())
+
+ RegisterExporter("genesyscloud_conversations_messaging_supportedcontent", supportedContent.SupportedContentExporter())
RegisterExporter("genesyscloud_script", scripts.ExporterScript())
diff --git a/genesyscloud/util/test_utils.go b/genesyscloud/util/test_utils.go
index a232e5ce0..e8bcea873 100644
--- a/genesyscloud/util/test_utils.go
+++ b/genesyscloud/util/test_utils.go
@@ -36,7 +36,7 @@ func TestAccPreCheck(t *testing.T) {
}
}
-// For fields such as genesyscloud_outbound_campaign.campaign_status, which use a diff suppress func,
+// VerifyAttributeInArrayOfPotentialValues For fields such as genesyscloud_outbound_campaign.campaign_status, which use a diff suppress func,
// and may return as "on", or "complete" depending on how long the operation takes
func VerifyAttributeInArrayOfPotentialValues(resource string, key string, potentialValues []string) resource.TestCheckFunc {
return func(state *terraform.State) error {
@@ -59,13 +59,13 @@ func ValidateStringInArray(resourceName string, attrName string, value string) r
return func(state *terraform.State) error {
resourceState, ok := state.RootModule().Resources[resourceName]
if !ok {
- return fmt.Errorf("Failed to find resourceState %s in state", resourceName)
+ return fmt.Errorf("failed to find resourceState %s in state", resourceName)
}
resourceID := resourceState.Primary.ID
numAttr, ok := resourceState.Primary.Attributes[attrName+".#"]
if !ok {
- return fmt.Errorf("No %s found for %s in state", attrName, resourceID)
+ return fmt.Errorf("no %s found for %s in state", attrName, resourceID)
}
numValues, _ := strconv.Atoi(numAttr)
diff --git a/main.go b/main.go
index 5174c193f..cd33dff06 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,20 +69,21 @@ import (
routingEmailRoute "terraform-provider-genesyscloud/genesyscloud/routing_email_route"
routingLanguage "terraform-provider-genesyscloud/genesyscloud/routing_language"
routingQueue "terraform-provider-genesyscloud/genesyscloud/routing_queue"
- 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"
workitem "terraform-provider-genesyscloud/genesyscloud/task_management_workitem"
workitemSchema "terraform-provider-genesyscloud/genesyscloud/task_management_workitem_schema"
worktype "terraform-provider-genesyscloud/genesyscloud/task_management_worktype"
+ worktypeStatus "terraform-provider-genesyscloud/genesyscloud/task_management_worktype_status"
"terraform-provider-genesyscloud/genesyscloud/team"
"terraform-provider-genesyscloud/genesyscloud/telephony"
did "terraform-provider-genesyscloud/genesyscloud/telephony_providers_edges_did"
@@ -219,6 +222,7 @@ func registerResources() {
workbin.SetRegistrar(regInstance) //Registering task management workbin
workitemSchema.SetRegistrar(regInstance) //Registering task management workitem schema
worktype.SetRegistrar(regInstance) //Registering task management worktype
+ worktypeStatus.SetRegistrar(regInstance) //Registering task management worktype status
workitem.SetRegistrar(regInstance) //Registering task management workitem
externalContacts.SetRegistrar(regInstance) //Registering external contacts
team.SetRegistrar(regInstance) //Registering team
@@ -246,7 +250,10 @@ 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
// setting resources for Use cases like TF export where provider is used in resource classes.
tfexp.SetRegistrar(regInstance) //Registering tf exporter
registrar.SetResources(providerResources, providerDataSources)