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

Update account_parameter.go #3108

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions pkg/resources/account_parameter.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,28 @@ func DeleteAccountParameter(d *schema.ResourceData, meta interface{}) error {
client := meta.(*provider.Context).Client
key := d.Get("key").(string)
ctx := context.Background()

// Identify the parameter
parameter := sdk.AccountParameter(key)
defaultParameter, err := client.Parameters.ShowAccountParameter(ctx, sdk.AccountParameter(key))

// Retrieve the current default value for the parameter
defaultParameter, err := client.Parameters.ShowAccountParameter(ctx, parameter)
if err != nil {
return err
return fmt.Errorf("error retrieving default value for account parameter %s: %w", key, err)
}

defaultValue := defaultParameter.Default
if defaultValue == "" {
Copy link
Collaborator

@sfc-gh-asawicki sfc-gh-asawicki Oct 1, 2024

Choose a reason for hiding this comment

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

This check is incorrect. There are parameters which default to none value (e.g. https://docs.snowflake.com/en/sql-reference/parameters#query-tag).

return fmt.Errorf("no default value found for account parameter %s", key)
}

// Reset the account parameter to its default value
err = client.Parameters.SetAccountParameter(ctx, parameter, defaultValue)
if err != nil {
return fmt.Errorf("error resetting account parameter err = %w", err)
return fmt.Errorf("error resetting account parameter %s: %w", key, err)
}

// Successfully reset the parameter, clear the ID
d.SetId("")
return nil
}