-
Notifications
You must be signed in to change notification settings - Fork 399
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
feat: Parameters sdk v2 #1914
feat: Parameters sdk v2 #1914
Conversation
sfc-gh-pbosak
commented
Jun 27, 2023
•
edited
edited
- updates session and account parameter resources to use new sdk implementation
…nowflake into parameters-sdk-v2
Integration tests failure for 1a304b8e54ca755bb7664b3ee9978cba1cf62e3a |
Integration tests failure for 3dd4b1ec0c67bf6aeb689277dc978e90d722697f |
Integration tests failure for 5aa65eb9b74e76b70887a8f00c7416b5ce03e396 |
1 similar comment
Integration tests failure for 5aa65eb9b74e76b70887a8f00c7416b5ce03e396 |
Integration tests failure for fbf0e75c04cf5688b207caf4988ee2279156f681 |
Integration tests success for 1807dda8ce2ed3e45a4d736a9661aab9c434d984 |
Integration tests success for f8d2ffa56eb67142d95bf1d70f08d31cb0bd60dd |
Integration tests success for 0e88f4f323a25121ee508695e4acc769af6681d2 |
pkg/sdk/parameters.go
Outdated
} | ||
|
||
func (parameters *parameters) SetAccountParameter(ctx context.Context, parameter AccountParameter, value string) error { | ||
opts := AlterAccountOptions{Set: &AccountSet{Parameters: &AccountLevelParameters{AccountParameters: &AccountParameters{}}}} |
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 hard to read, can you split this over multiple lines?
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.
done
err := client.Parameters.SetSessionParameterForAccount(ctx, parameter, value) | ||
if err != nil { | ||
return err | ||
} | ||
} else { | ||
if user == "" { | ||
return fmt.Errorf("user is required if on_account is false") |
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.
Can we move this logic to a validation function in the resource 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'm not sure if we can do that since we only check if it's empty if on_account is false. validation functions in resource schema cannot access another attribute value afaik
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.
in the tf plugin framework it is possible to use a plan modifier to validate this as Nathan is describing. it is something we should revisit, for sure
pkg/resources/session_parameter.go
Outdated
if reflect.TypeOf(parameterDefault.DefaultValue) == typeString { | ||
value = fmt.Sprintf("'%s'", snowflake.EscapeString(value)) | ||
} | ||
builder := snowflake.NewSessionParameter(key, value, db) |
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.
Still using the old SDK here.
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.
fixed
pkg/resources/session_parameter.go
Outdated
typeString := reflect.TypeOf("") | ||
if reflect.TypeOf(parameterDefault.DefaultValue) == typeString { | ||
value = fmt.Sprintf("'%s'", snowflake.EscapeString(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.
This should already be handled by the new SDK, cf. https://github.com/Snowflake-Labs/terraform-provider-snowflake/blob/main/pkg/sdk/sql_builder.go#L52
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.
fixed
pkg/resources/session_parameter.go
Outdated
if user == "" { | ||
return fmt.Errorf("user is required if on_account is false") | ||
} | ||
parameterDefault := snowflake.GetParameterDefaults(snowflake.ParameterTypeSession)[key] |
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.
Remove dependency on old SDK.
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.
fixed
pkg/resources/object_parameter.go
Outdated
@@ -91,6 +93,9 @@ func CreateObjectParameter(d *schema.ResourceData, meta interface{}) error { | |||
db := meta.(*sql.DB) | |||
key := d.Get("key").(string) | |||
value := d.Get("value").(string) | |||
client := sdk.NewClientFromDB(db) | |||
ctx := context.Background() | |||
parameter := sdk.ObjectParameter(key) | |||
|
|||
parameterDefault := snowflake.GetParameterDefaults(snowflake.ParameterTypeObject)[key] |
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.
Old SDK here too.
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 don't think we can get rid of that in this case, at least not fully. In order to make use of new sdk here, we need to have new sdk implementation for all objects which can take parameters and that's not the case just yet. It can be improved in the future, but I think it has to use old sdk for now
pkg/resources/account_parameter.go
Outdated
|
||
parameterDefault := snowflake.GetParameterDefaults(snowflake.ParameterTypeAccount)[key] | ||
parameterDefault := snowflake.GetParameterDefaults(snowflake.ParameterTypeSession)[key] |
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.
Old SDK here.
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.
fixed
func TestAcc_AccountParameter_CLIENT_METADATA_USE_SESSION_DATABASE(t *testing.T) { | ||
resource.ParallelTest(t, resource.TestCase{ | ||
Providers: providers(), | ||
CheckDestroy: nil, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: accountParameterBasic("CLIENT_METADATA_USE_SESSION_DATABASE", "true"), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr("snowflake_account_parameter.p", "key", "CLIENT_METADATA_USE_SESSION_DATABASE"), | ||
resource.TestCheckResourceAttr("snowflake_account_parameter.p", "value", "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.
Why are we removing this test? It should still pass, right?
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 test tries to set CLIENT_METADATA_USE_SESSION_DATABASE for account.
CLIENT_METADATA_USE_SESSION_DATABASE is a session parameter and I think we should only allow to set it using a session_parameter. For now I modified it to use an actual account parameter, but if you think we should allow to set session parameters using account_parameter resource then we can discuss it
pkg/resources/account_parameter.go
Outdated
if err != nil { | ||
return fmt.Errorf("error reading account parameter err = %w", err) | ||
return fmt.Errorf("error creating account parameter err = %w", 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.
this should probably say "error resetting account parameter to default 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.
fixed
Integration tests success for 555e6f156f276102504ea164f90c1260c9082775 |
Integration tests failure for d2b679e1cc53bf4a943bf83bc062d04df4ca16dc |
…rm-provider-snowflake into parameters-sdk-v2
…nowflake into parameters-sdk-v2
Integration tests failure for 98f91238b1bc918acee47e7cfbd7fd11dd3be7d4 |
Integration tests failure for ad693953fadd6c92212f6260607504b7d855b4c9 |
Integration tests failure for 44283b2a181d7b69208ec969bf91df40223a0cb0 |
Integration tests failure for b45d015595bf3d3755037e77676d63cd3a6e55a7 |
Integration tests failure for a306eadc47dc57d4c0f1810d94b0ae56613decbb |
Integration tests failure for 8411935d901d257ffe3fdf73bb7246f8d3fcabd3 |
Integration tests failure for b41d4d4a80243af477d7d5675ddba56bd83e20d2 |
Integration tests failure for 6e4883eaf195e9fc4630f43decde18beb89cb89b |
Integration tests failure for 76a384754b02267502dbda6d786a48b53299f1a6 |
Integration tests failure for 3665a78bb563c3746cae573e8e3fb30258905c94 |
Integration tests success for 3ae991be2c7d81813dabf68bbaec7a29fb5af733 |
Integration tests success for 4c091ac2585c8178a9cde37f9c535fe9fba62115 |
err := client.Parameters.SetSessionParameterForAccount(ctx, parameter, value) | ||
if err != nil { | ||
return err | ||
} | ||
} else { | ||
if user == "" { | ||
return fmt.Errorf("user is required if on_account is false") |
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.
in the tf plugin framework it is possible to use a plan modifier to validate this as Nathan is describing. it is something we should revisit, for sure
pkg/sdk/parameters.go
Outdated
SetSessionParameterForAccount(ctx context.Context, parameter SessionParameter, value string) error | ||
SetSessionParameterForUser(ctx context.Context, id AccountObjectIdentifier, parameter SessionParameter, value string) error | ||
SetObjectParameterForAccount(ctx context.Context, parameter ObjectParameter, value string) error | ||
SetObjectParameterForUser(ctx context.Context, id AccountObjectIdentifier, parameter ObjectParameter, value string) error |
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 makes no sense. you cannot set an object parameter for a user. Object parameters can only be set for objects or at the account level. Perhaps this should be renamed to SetObjectParameterForObject
pkg/sdk/parameters.go
Outdated
return nil | ||
} | ||
|
||
func (parameters *parameters) SetSessionParameterForUser(ctx context.Context, id AccountObjectIdentifier, parameter SessionParameter, value string) error { |
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 code is copypasted from above. maybe should be refactored?
pkg/sdk/parameters.go
Outdated
func (parameters *parameters) SetObjectParameterForUser(ctx context.Context, id AccountObjectIdentifier, parameter ObjectParameter, value string) error { | ||
opts := AlterUserOptions{Set: &UserSet{ObjectParameters: &UserObjectParameters{}}} | ||
switch parameter { | ||
case ObjectParameterNetworkPolicy: |
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.
both of these are actually session parameters
pkg/sdk/parameters.go
Outdated
AllowedObjectTypes []ObjectType | ||
} | ||
|
||
// ParameterDefaults returns a map of default values for all parameters. |
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.
these parameter defaults feel clunky
return ParameterDefaults()[key] | ||
} | ||
|
||
func parseBooleanParameter(parameter, value string) (_ *bool, err error) { |
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 could be any kind of parse function, no?