-
Notifications
You must be signed in to change notification settings - Fork 87
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
base: dev
Are you sure you want to change the base?
WORKITEMS-3562 Add Task Management Rules resources #1451
Conversation
# 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
There was a problem hiding this 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) |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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{ |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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{ |
There was a problem hiding this comment.
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] |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
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 thegenesyscloud_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.