-
Notifications
You must be signed in to change notification settings - Fork 89
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
Fix auth0 tenant flags so it only sends set values #144
Conversation
32d963e
to
9ba43e8
Compare
func Flag(configFlags cty.Value, key string) *bool { | ||
configFlag := configFlags.GetAttr(key) | ||
|
||
if configFlag.IsNull() { |
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.
Terraform Plugin SDK v2 uses github.com/hashicorp/go-cty/cty under the hood and because of that we are now able to distinguish between values that are set in the config (true/false) and nil values (not present in the config) correctly making sure we also omit them from the PATCH payload if not present in the config.
flags.EnablePublicSignupUserExistsError = Bool(d, "enable_public_signup_user_exists_error") | ||
flags.UseScopeDescriptionsForConsent = Bool(d, "use_scope_descriptions_for_consent") | ||
func expandTenantFlags(flagsList cty.Value) *management.TenantFlags { | ||
var tenantFlags *management.TenantFlags |
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.
By changing this to a pointer and only setting the flags if we have the flags list set in the terraform config, we won't force the flags to be sent as an empty object any more to avoid the 400 bad requests error we get from the API in case we don't have any flags sent within. This truly makes the flags now optional as the docs indicate.
@@ -257,13 +258,27 @@ func Float64(d ResourceData, key string, conditions ...Condition) (f *float64) { | |||
// Bool accesses the value held by key and type asserts it to a pointer to a | |||
// bool. | |||
func Bool(d ResourceData, key string, conditions ...Condition) (b *bool) { | |||
// We need to keep using this for bool values even if it's marked as deprecated. |
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.
The issue with the flags was that they were using GetOkExists to check if the bool value was set or not which actually defaults to false when the flag is not set forcing the entire payload to be sent as the flags are pointers to bool and omitempty will only omit nil values.
Even tho GetOkExists is deprecated in the sdkv2 we need to keep using it for all the other bool fields we have on other structs. See hashicorp/terraform-plugin-sdk#817 for more details.
Description
Fixes: #137
Fixes: #127
Fixes: #63
Fixes #54
Fix auth0 tenant flags so it only sends set values.
Checklist
Note: Checklist required to be completed before a PR is considered to be reviewable.
Auth0 Code of Conduct
Auth0 General Contribution Guidelines
Changes include test coverage?
Does the description provide the correct amount of context?
Have you updated the documentation?
Is this code ready for production?