From c714f01249c3da31329247f1c0d7b2120db280c0 Mon Sep 17 00:00:00 2001 From: Richard Barrett <32808365+Richard-Barrett@users.noreply.github.com> Date: Mon, 30 Sep 2024 22:39:10 -0500 Subject: [PATCH] Update account_parameter.go Fixes #1679 --- pkg/resources/account_parameter.go | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/pkg/resources/account_parameter.go b/pkg/resources/account_parameter.go index ccff34a089..1b5dfa0666 100644 --- a/pkg/resources/account_parameter.go +++ b/pkg/resources/account_parameter.go @@ -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 == "" { + 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 }