Skip to content

Commit

Permalink
fix: Adds case statement for ObjectTypeUser in ShowObjectParameter. (#…
Browse files Browse the repository at this point in the history
…2675)

When issuing `object_type = "USER"` via the `snowflake_object_parameter`
resource the `ShowObjectParameter` function did not handle the
`ObjectTypeUser` which led to invalid ObjectType errors.

## Test Plan
* [x] acceptance tests


## References
* ~~Fixes #2669~~ Actually, I re-reading this issue I don't think it
fixes this error.
  • Loading branch information
cmonty-paypal authored Apr 11, 2024
1 parent 3275ad4 commit 23a3341
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
41 changes: 41 additions & 0 deletions pkg/resources/object_parameter_acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package resources_test

import (
"fmt"
"strings"
"testing"

acc "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance"

"github.com/hashicorp/terraform-plugin-testing/helper/acctest"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/tfversion"
)
Expand Down Expand Up @@ -52,6 +54,28 @@ func TestAcc_ObjectParameterAccount(t *testing.T) {
})
}

func TestAcc_UserParameter(t *testing.T) {
userName := strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha))
resource.Test(t, resource.TestCase{
ProtoV6ProviderFactories: acc.TestAccProtoV6ProviderFactories,
TerraformVersionChecks: []tfversion.TerraformVersionCheck{
tfversion.RequireAbove(tfversion.Version1_5_0),
},
PreCheck: func() { acc.TestAccPreCheck(t) },
CheckDestroy: nil,
Steps: []resource.TestStep{
{
Config: userParameterConfigBasic(userName, "ENABLE_UNREDACTED_QUERY_SYNTAX_ERROR", "true"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("snowflake_object_parameter.p", "key", "ENABLE_UNREDACTED_QUERY_SYNTAX_ERROR"),
resource.TestCheckResourceAttr("snowflake_object_parameter.p", "value", "true"),
resource.TestCheckResourceAttr("snowflake_object_parameter.p", "on_account", "false"),
),
},
},
})
}

func objectParameterConfigOnAccount(key, value string) string {
s := `
resource "snowflake_object_parameter" "p" {
Expand All @@ -76,3 +100,20 @@ resource "snowflake_object_parameter" "p" {
`
return fmt.Sprintf(s, key, value, databaseName)
}

func userParameterConfigBasic(userName string, key string, value string) string {
s := `
resource "snowflake_user" "user" {
name = "%s"
}
resource "snowflake_object_parameter" "p" {
key = "%s"
value = "%s"
object_type = "USER"
object_identifier {
name = snowflake_user.user.name
}
}
`
return fmt.Sprintf(s, userName, key, value)
}
2 changes: 2 additions & 0 deletions pkg/sdk/parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -1004,6 +1004,8 @@ func (v *parameters) ShowObjectParameter(ctx context.Context, parameter ObjectPa
opts.In.Task = object.Name.(SchemaObjectIdentifier)
case ObjectTypeTable:
opts.In.Table = object.Name.(SchemaObjectIdentifier)
case ObjectTypeUser:
opts.In.User = object.Name.(AccountObjectIdentifier)
default:
return nil, fmt.Errorf("unsupported object type %s", object.Name)
}
Expand Down

0 comments on commit 23a3341

Please sign in to comment.