From 68544d46744e7d459831dbed5c592d34bba41d31 Mon Sep 17 00:00:00 2001 From: Cory Monty Date: Thu, 4 Apr 2024 09:44:02 -0700 Subject: [PATCH 1/2] Adds case statement for ObjectTypeUser in ShowObjectParameter. --- pkg/acceptance/testing.go | 8 +++++ .../object_parameter_acceptance_test.go | 35 +++++++++++++++++++ pkg/sdk/parameters.go | 2 ++ 3 files changed, 45 insertions(+) diff --git a/pkg/acceptance/testing.go b/pkg/acceptance/testing.go index d600249420..ec4d89c0ae 100644 --- a/pkg/acceptance/testing.go +++ b/pkg/acceptance/testing.go @@ -24,6 +24,7 @@ const ( TestSchemaName = "terraform_test_schema" TestWarehouseName = "terraform_test_warehouse" TestWarehouseName2 = "terraform_test_warehouse_2" + TestUserName = "terraform_test_user" ) var ( @@ -120,6 +121,13 @@ func TestAccPreCheck(t *testing.T) { }); err != nil { t.Fatal(err) } + + userId := sdk.NewAccountObjectIdentifier(TestUserName) + if err := atc.client.Users.Create(ctx, userId, &sdk.CreateUserOptions{ + IfNotExists: sdk.Bool(true), + }); err != nil { + t.Fatal(err) + } }) } diff --git a/pkg/resources/object_parameter_acceptance_test.go b/pkg/resources/object_parameter_acceptance_test.go index 7985f14583..6cc6483fba 100644 --- a/pkg/resources/object_parameter_acceptance_test.go +++ b/pkg/resources/object_parameter_acceptance_test.go @@ -52,6 +52,27 @@ func TestAcc_ObjectParameterAccount(t *testing.T) { }) } +func TestAcc_UserParameter(t *testing.T) { + 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("ENABLE_UNREDACTED_QUERY_SYNTAX_ERROR", "true", acc.TestUserName), + 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" { @@ -76,3 +97,17 @@ resource "snowflake_object_parameter" "p" { ` return fmt.Sprintf(s, key, value, databaseName) } + +func userParameterConfigBasic(key, value, username string) string { + s := ` +resource "snowflake_object_parameter" "p" { + key = "%s" + value = "%s" + object_type = "USER" + object_identifier { + name = "%s" + } +} +` + return fmt.Sprintf(s, key, value, username) +} diff --git a/pkg/sdk/parameters.go b/pkg/sdk/parameters.go index f358df2a73..fcff205eb7 100644 --- a/pkg/sdk/parameters.go +++ b/pkg/sdk/parameters.go @@ -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) } From a0d8595870f1e37c4223141e96139a96331b6623 Mon Sep 17 00:00:00 2001 From: Cory Monty Date: Wed, 10 Apr 2024 14:34:26 -0700 Subject: [PATCH 2/2] Refactor test user setup --- pkg/acceptance/testing.go | 8 -------- pkg/resources/object_parameter_acceptance_test.go | 14 ++++++++++---- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/pkg/acceptance/testing.go b/pkg/acceptance/testing.go index ec4d89c0ae..d600249420 100644 --- a/pkg/acceptance/testing.go +++ b/pkg/acceptance/testing.go @@ -24,7 +24,6 @@ const ( TestSchemaName = "terraform_test_schema" TestWarehouseName = "terraform_test_warehouse" TestWarehouseName2 = "terraform_test_warehouse_2" - TestUserName = "terraform_test_user" ) var ( @@ -121,13 +120,6 @@ func TestAccPreCheck(t *testing.T) { }); err != nil { t.Fatal(err) } - - userId := sdk.NewAccountObjectIdentifier(TestUserName) - if err := atc.client.Users.Create(ctx, userId, &sdk.CreateUserOptions{ - IfNotExists: sdk.Bool(true), - }); err != nil { - t.Fatal(err) - } }) } diff --git a/pkg/resources/object_parameter_acceptance_test.go b/pkg/resources/object_parameter_acceptance_test.go index 6cc6483fba..5c9679b321 100644 --- a/pkg/resources/object_parameter_acceptance_test.go +++ b/pkg/resources/object_parameter_acceptance_test.go @@ -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" ) @@ -53,6 +55,7 @@ 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{ @@ -62,7 +65,7 @@ func TestAcc_UserParameter(t *testing.T) { CheckDestroy: nil, Steps: []resource.TestStep{ { - Config: userParameterConfigBasic("ENABLE_UNREDACTED_QUERY_SYNTAX_ERROR", "true", acc.TestUserName), + 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"), @@ -98,16 +101,19 @@ resource "snowflake_object_parameter" "p" { return fmt.Sprintf(s, key, value, databaseName) } -func userParameterConfigBasic(key, value, username string) string { +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 = "%s" + name = snowflake_user.user.name } } ` - return fmt.Sprintf(s, key, value, username) + return fmt.Sprintf(s, userName, key, value) }