-
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
GPE-14846: Add External Sources resource #1450
base: dev
Are you sure you want to change the base?
GPE-14846: Add External Sources resource #1450
Conversation
|
||
### Optional | ||
|
||
- `active` (Boolean) Whether the external source is active. Defaults to `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.
When creating new External Sources, the backing API will ignore the value from the request and always create resource with active
set to true
.
I thought I'd call this out, in case this is a problem for TF provider or our users.
When running the provider locally with added trace logging, we can see this message:
2025-01-06T12:15:59.181Z [WARN] Provider "provider["genesys.com/mypurecloud/genesyscloud"]" produced an unexpected new value for genesyscloud_externalcontacts_external_source.inactive_external_source, but we are tolerating it because it is using the legacy plugin SDK.
The following problems may be the cause of any confusing errors from downstream operations:
- .active: was cty.False, but now cty.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.
A change is being proposed to address this in the backend, so that the active
value from the request is honoured.
|
||
Optional: | ||
|
||
- `uri_template` (String) |
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.
This string allows templating, with {{}}
. The only value supported for now is {{externalId.value}}. Should this be called out in the field description?
This is not mentioned in Public API docs.
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.
If more values are supported in the future, we'll have to come back and modify the docs here, so it might be easier to be generic and let the response tell them what they did wrong.
|
||
cursor := "" | ||
for { | ||
externalSources, resp, err := p.externalContactsApi.GetExternalcontactsExternalsources(cursor, 100, query, true) // workaround for active being a required arg on Platform Client SDK Go GetExternalcontactsExternalsources |
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 comment in the code to make this more visible. The method in our SDK requires passing active
as an arg and this is not optional, so I ended up making two requests: first one for all active:true and the second for all active:false.
) | ||
|
||
// getAllAuthExternalContactsExternalSources retrieves all of the external sources via Terraform in the Genesys Cloud and is used for the exporter | ||
func getAllAuthExternalContactsExternalSources(ctx context.Context, clientConfig *platformclientv2.Configuration) (resourceExporter.ResourceIDMetaMap, diag.Diagnostics) { |
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.
This is similar resource to External Organizations and can have same problem as the one dealt with in DEVTOOLING-977.
The API can return more than 1000 resources, as there is no upper limit on how many External Sources we can have in total. The limit is only applied on the number of active ones.
active = true | ||
link_configuration { | ||
uri_template = "https://some.host/{{externalId.value}}" | ||
} |
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.
name
is the only attribute in the data source schema, so you can remove all other fields from this example (you'll need to refresh the docs by running make docs
after this)
dataSourceExternalSourceCache = rc.NewDataSourceCache(sdkConfig, hydrateExternalSourceCacheFn, getExternalSourceByNameFn) | ||
} | ||
return util.WithRetries(ctx, 15*time.Second, func() *retry.RetryError { | ||
externalSourceId, retryable, response, err := proxy.getExternalContactsExternalSourceIdByName(ctx, name) |
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.
We're not actually making use of the data source cache here. Take a look at this example to see how to make use of the functions hydrateExternalSourceCacheFn
and getExternalSourceByNameFn
- https://github.com/MyPureCloud/terraform-provider-genesyscloud/blob/main/genesyscloud/routing_queue/data_source_genesyscloud_routing_queue.go#L33
r.resourceMapMutex.Lock() | ||
defer r.resourceMapMutex.Unlock() | ||
|
||
providerResources["genesyscloud_externalcontacts_external_source"] = ResourceExternalContactsExternalSource() |
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.
You can use the constant ResourceType
here and on line 34
// deleteExternalContactsExternalSourceFn is an implementation function for deleting a Genesys Cloud external contacts external source | ||
func deleteExternalContactsExternalSourceFn(ctx context.Context, p *externalContactsExternalSourceProxy, id string) (apiResponse *platformclientv2.APIResponse, err error) { | ||
_, response, err := p.externalContactsApi.DeleteExternalcontactsExternalsource(id) | ||
return response, err |
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.
No harm in deleting from cache also if this operation was successful. Here's an example in another package - https://github.com/MyPureCloud/terraform-provider-genesyscloud/blob/main/genesyscloud/routing_queue/genesyscloud_routing_queue_proxy.go#L227
StateContext: schema.ImportStatePassthroughContext, | ||
}, | ||
SchemaVersion: 1, | ||
Schema: map[string]*schema.Schema{ |
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 noticed id
is a field in the request body for the POST. Can the client choose the ID? If they can, we should probably add it here just so the end user can do anything from CX as Code that they can do via the API.
Adding External Sources resource to manage resources with /api/v2/externalcontacts/externalsources API