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

Swap out internal client for new external client - SAML Groups #123

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

micahkemp-splunk
Copy link
Contributor

@micahkemp-splunk micahkemp-splunk commented May 17, 2022

This PR is the start of the migration from the internally-included Splunk client for the newly available external client. The external client is added alongside the legacy client, and can be used by setting either the appropriate provider (use_client_default) or resource (use_client) configuration to external.

The external client handles CRUD operations with standard Create/Read/Update/Delete functions, which deduplicates a lot of code, and provides a single location to implement fixes when issues are discovered. Migrating this Terraform provider to use it should solve a lot of the error handling and drift issues currently present.

The interesting work is found in 5a34349, which adds composable CRUD function creation, simplifying logic and reducing repetition.

The remaining commits are in support of this swap.

As this PR adds the ability to use the external client, but by default does not change existing behavior, it can be merged and tagged without a major version bump. After all existing resources permit use of the external client, a new PR can be submitted to make the default behavior to use the external client, which would justify a major version bump.

Comment on lines -93 to +124
err := (*provider.Client).UpdateAdminSAMLGroups(d.Id(), adminSAMLGroupsObj)
err := (*provider.Client).UpdateAdminSAMLGroups(d.Get("name").(string), adminSAMLGroupsObj)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because the legacy functions expected the Id to be the name, avoid potential issues caused by inconsistency between the two providers by always using the name when updating/deleting SAML groups.

Comment on lines -103 to +134
resp, err := (*provider.Client).DeleteAdminSAMLGroups(d.Id())
resp, err := (*provider.Client).DeleteAdminSAMLGroups(d.Get("name").(string))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because the legacy functions expected the Id to be the name, avoid potential issues caused by inconsistency between the two providers by always using the name when updating/deleting SAML groups.

go.sum Show resolved Hide resolved
@micahkemp-splunk micahkemp-splunk changed the title Swap out internal client for new external client - SAML Groups WIP - Swap out internal client for new external client - SAML Groups May 27, 2022
@micahkemp-splunk micahkemp-splunk marked this pull request as draft May 27, 2022 23:07
@micahkemp-splunk micahkemp-splunk changed the title WIP - Swap out internal client for new external client - SAML Groups Swap out internal client for new external client - SAML Groups May 27, 2022
@micahkemp-splunk micahkemp-splunk force-pushed the external-saml branch 9 times, most recently from 54f7a69 to 858cabb Compare June 3, 2022 18:25
@micahkemp-splunk micahkemp-splunk force-pushed the external-saml branch 2 times, most recently from 7dab85d to 8ea0202 Compare June 3, 2022 20:57
@micahkemp-splunk micahkemp-splunk marked this pull request as ready for review June 3, 2022 20:59
@micahkemp-splunk micahkemp-splunk marked this pull request as draft June 8, 2022 14:22
Comment on lines 31 to 36
// GetOk only returns true if the fetched value is not the zero value for its type,
// so we can only determine if use_legacy_client was explicitly true. but because
// true is our default value, we know that it can only be false if explicitly set.
if ok || !resourceLegacyClient {
return resourceLegacyClient
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm working to validate this comment and logic is correct, after behavior I saw while testing similar code yesterday.

@micahkemp-splunk micahkemp-splunk marked this pull request as ready for review June 23, 2022 22:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants