Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WORKITEMS-3562 Add Task Management Rules resources #1451

Open
wants to merge 12 commits into
base: dev
Choose a base branch
from

Conversation

maikow-genesys
Copy link
Contributor

Adding three resources that represent Task Management Rules:

  • genesyscloud_task_management_oncreate_rule
  • genesyscloud_task_management_onattributechange_rule
  • genesyscloud_task_management_datebased_rule

All of them are very similar. Although this PR looks big, the majority of the code is repeated across resources. Hence I decided to create one PR for all.

Also the schema_id should be optional in the genesyscloud_task_management_worktype resource (WORKITEMS-3726). I've added the fix in this PR otherwise I'd have to write extra test code for the 3 resources above.

# Conflicts:
#	genesyscloud/task_management_worktype/data_source_genesyscloud_task_management_worktype_test.go
#	genesyscloud/task_management_worktype/resource_genesyscloud_task_management_worktype_test.go
#	genesyscloud/task_management_worktype/resource_genesyscloud_task_management_worktype_utils.go
Copy link
Collaborator

@charliecon charliecon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left a lot of comments because there are a lot of changes, but looks good overall. Thanks for the contribution!

return retry.RetryableError(util.BuildWithRetriesApiDiagnosticError(ResourceType, fmt.Sprintf("no task management datebased rule found with name %s", name), resp))
}

d.SetId(typeId + "/" + dateBasedRuleId)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this approach of combining the IDs is appropriate with a data source. For example, if there is another resource that has a field databased_rule_id , will it expect this combination of IDs or will it expect the rule ID alone? In other words, if another endpoint in the public API were to have a field in its request body that is a reference to a databased rule, will it expect the "" or "/"


providerResources[ResourceType] = ResourceTaskManagementDateBasedRule()
providerResources["genesyscloud_task_management_worktype"] = worktype.ResourceTaskManagementWorktype()
providerResources["genesyscloud_task_management_workbin"] = workbin.ResourceTaskManagementWorkbin()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume there are public constants in these packages, so you could reference them like worktype.ResourceType instead of hard-coding the value again here

ruleCondition.SetField("Attribute", platformclientv2.String(attribute))
ruleCondition.SetField("RelativeMinutesToInvocation", platformclientv2.Int(relativeMinutesToInvocation))

datebased_rule := platformclientv2.Workitemdatebasedrulecreate{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

databased_rule -> databasedRule

3. The datasource schema definitions for the task_management_datebased_rule datasource.
4. The resource exporter configuration for the task_management_datebased_rule exporter.
*/
const ResourceType = "genesyscloud_task_management_datebased_rule"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recommend changing this to "genesyscloud_task_management_worktypes_flows_datebased_rule" to align with the API endpoints. It's very long-winded but in the long run it keeps things much simpler

3. The datasource schema definitions for the task_management_onattributechange_rule datasource.
4. The resource exporter configuration for the task_management_onattributechange_rule exporter.
*/
const ResourceType = "genesyscloud_task_management_onattributechange_rule"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here - "genesyscloud_task_management_worktypes_flows_onattributechange_rule

resources[*worktype.Id+"/"+*onCreateRule.Id] = &resourceExporter.ResourceMeta{BlockLabel: *onCreateRule.Name}
}
}
return resources, nil
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here - nil check worktypes and onCreateRules before trying to dereference them

return util.WithRetriesForRead(ctx, d, func() *retry.RetryError {
onCreateRule, resp, getErr := proxy.getTaskManagementOnCreateRuleById(ctx, worktypeId, id)
if getErr != nil {
return retry.RetryableError(util.BuildWithRetriesApiDiagnosticError(ResourceType, fmt.Sprintf("failed to read task management oncreate rule %s for worktype %s | error: %s", id, worktypeId, getErr), resp))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here about checking for 404

`worktype_id`: {
Description: `The Worktype ID of the Rule.`,
Required: true,
ForceNew: true,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here


// getWorkitemoncreaterulecreateFromResourceData maps data from schema ResourceData object to a platformclientv2.Workitemoncreaterulecreate
func getWorkitemoncreaterulecreateFromResourceData(d *schema.ResourceData) platformclientv2.Workitemoncreaterulecreate {
oncreate_rule := platformclientv2.Workitemoncreaterulecreate{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oncreate_rule -> onCreateRule

// splitOnCreateRuleTerraformId will split the rule resource id which is in the form
// <worktypeId>/<ruleId> into just the worktypeId and ruleId string
func splitOnCreateRuleTerraformId(id string) (worktypeId string, ruleId string) {
return strings.Split(id, "/")[0], strings.Split(id, "/")[1]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here about adding a build function

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And about checking the length before indexing, to be on the safe side

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants