From 4316eb831f12e120b6c6f1219fd0a29dc6460545 Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Fri, 16 Feb 2024 12:26:22 +0100 Subject: [PATCH 1/6] Introduce requested doc change references #2509 --- docs/index.md | 1 + examples/provider/provider.tf | 1 + 2 files changed, 2 insertions(+) diff --git a/docs/index.md b/docs/index.md index 603aa75c56..77fe01af68 100644 --- a/docs/index.md +++ b/docs/index.md @@ -22,6 +22,7 @@ provider "snowflake" { account = "..." # required if not using profile. Can also be set via SNOWFLAKE_ACCOUNT env var username = "..." # required if not using profile or token. Can also be set via SNOWFLAKE_USER env var password = "..." + authenticator = "..." # required if not using password as auth method oauth_access_token = "..." private_key_path = "..." private_key = "..." diff --git a/examples/provider/provider.tf b/examples/provider/provider.tf index bc1c074c10..26318f3a0f 100644 --- a/examples/provider/provider.tf +++ b/examples/provider/provider.tf @@ -2,6 +2,7 @@ provider "snowflake" { account = "..." # required if not using profile. Can also be set via SNOWFLAKE_ACCOUNT env var username = "..." # required if not using profile or token. Can also be set via SNOWFLAKE_USER env var password = "..." + authenticator = "..." # required if not using password as auth method oauth_access_token = "..." private_key_path = "..." private_key = "..." From 1daaabd54d77b213a9728414c777596638db3bac Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Fri, 16 Feb 2024 12:32:28 +0100 Subject: [PATCH 2/6] Attempt to fix TestAcc_ResourceMonitor flaky test --- .../resource_monitor_acceptance_test.go | 65 ++++++++++--------- 1 file changed, 35 insertions(+), 30 deletions(-) diff --git a/pkg/resources/resource_monitor_acceptance_test.go b/pkg/resources/resource_monitor_acceptance_test.go index 0738d4c007..5e4104960d 100644 --- a/pkg/resources/resource_monitor_acceptance_test.go +++ b/pkg/resources/resource_monitor_acceptance_test.go @@ -9,8 +9,10 @@ import ( "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" "github.com/stretchr/testify/require" ) @@ -18,13 +20,16 @@ func TestAcc_ResourceMonitor(t *testing.T) { // TODO test more attributes name := strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha)) - resource.ParallelTest(t, resource.TestCase{ - Providers: acc.TestAccProviders(), - PreCheck: func() { acc.TestAccPreCheck(t) }, + resource.Test(t, resource.TestCase{ + ProtoV6ProviderFactories: acc.TestAccProtoV6ProviderFactories, + PreCheck: func() { acc.TestAccPreCheck(t) }, + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ + tfversion.RequireAbove(tfversion.Version1_5_0), + }, CheckDestroy: nil, Steps: []resource.TestStep{ { - Config: resourceMonitorConfig(name), + Config: resourceMonitorConfig(name, acc.TestWarehouseName), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("snowflake_resource_monitor.test", "name", name), resource.TestCheckResourceAttr("snowflake_resource_monitor.test", "credit_quota", "100"), @@ -71,9 +76,12 @@ func TestAcc_ResourceMonitor(t *testing.T) { func TestAcc_ResourceMonitorChangeStartEndTimestamp(t *testing.T) { name := strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha)) - resource.ParallelTest(t, resource.TestCase{ - Providers: acc.TestAccProviders(), - PreCheck: func() { acc.TestAccPreCheck(t) }, + resource.Test(t, resource.TestCase{ + ProtoV6ProviderFactories: acc.TestAccProtoV6ProviderFactories, + PreCheck: func() { acc.TestAccPreCheck(t) }, + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ + tfversion.RequireAbove(tfversion.Version1_5_0), + }, CheckDestroy: nil, Steps: []resource.TestStep{ { @@ -165,9 +173,12 @@ func TestAcc_ResourceMonitorUpdateNotifyUsers(t *testing.T) { if err != nil { t.Error(err) } - resource.ParallelTest(t, resource.TestCase{ - Providers: acc.TestAccProviders(), - PreCheck: func() { acc.TestAccPreCheck(t) }, + resource.Test(t, resource.TestCase{ + ProtoV6ProviderFactories: acc.TestAccProtoV6ProviderFactories, + PreCheck: func() { acc.TestAccPreCheck(t) }, + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ + tfversion.RequireAbove(tfversion.Version1_5_0), + }, CheckDestroy: nil, Steps: []resource.TestStep{ { @@ -190,14 +201,8 @@ func TestAcc_ResourceMonitorUpdateNotifyUsers(t *testing.T) { }) } -func resourceMonitorConfig(accName string) string { +func resourceMonitorConfig(accName string, warehouse string) string { return fmt.Sprintf(` -resource "snowflake_warehouse" "warehouse" { - name = "test" - comment = "foo" - warehouse_size = "SMALL" -} - resource "snowflake_resource_monitor" "test" { name = "%v" credit_quota = 100 @@ -205,19 +210,13 @@ resource "snowflake_resource_monitor" "test" { notify_triggers = [40] suspend_trigger = 80 suspend_immediate_trigger = 90 - warehouses = [snowflake_warehouse.warehouse.id] + warehouses = ["%s"] } -`, accName) +`, accName, warehouse) } func resourceMonitorConfig2(accName string, suspendTrigger int) string { return fmt.Sprintf(` -resource "snowflake_warehouse" "warehouse" { - name = "test" - comment = "foo" - warehouse_size = "SMALL" -} - resource "snowflake_resource_monitor" "test" { name = "%v" credit_quota = 150 @@ -241,8 +240,11 @@ func TestAcc_ResourceMonitor_issue2167(t *testing.T) { require.NoError(t, err) resource.Test(t, resource.TestCase{ - Providers: acc.TestAccProviders(), - PreCheck: func() { acc.TestAccPreCheck(t) }, + ProtoV6ProviderFactories: acc.TestAccProtoV6ProviderFactories, + PreCheck: func() { acc.TestAccPreCheck(t) }, + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ + tfversion.RequireAbove(tfversion.Version1_5_0), + }, CheckDestroy: nil, Steps: []resource.TestStep{ { @@ -277,9 +279,12 @@ func TestAcc_ResourceMonitorNotifyUsers(t *testing.T) { for _, s := range users { checks = append(checks, resource.TestCheckTypeSetElemAttr("snowflake_resource_monitor.test", "notify_users.*", s)) } - resource.ParallelTest(t, resource.TestCase{ - Providers: acc.TestAccProviders(), - PreCheck: func() { acc.TestAccPreCheck(t) }, + resource.Test(t, resource.TestCase{ + ProtoV6ProviderFactories: acc.TestAccProtoV6ProviderFactories, + PreCheck: func() { acc.TestAccPreCheck(t) }, + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ + tfversion.RequireAbove(tfversion.Version1_5_0), + }, CheckDestroy: nil, Steps: []resource.TestStep{ { From 4fef4990791c7637be150bd069cd7c4e90bc5860 Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Fri, 16 Feb 2024 12:45:56 +0100 Subject: [PATCH 3/6] Add more logging to task suspension (to check error when it fails sometime on the CI) --- pkg/resources/task.go | 2 +- pkg/resources/task_acceptance_test.go | 34 +++++++++++++-------------- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/pkg/resources/task.go b/pkg/resources/task.go index 44d72c9705..b5dfb540ec 100644 --- a/pkg/resources/task.go +++ b/pkg/resources/task.go @@ -500,7 +500,7 @@ func UpdateTask(d *schema.ResourceData, meta interface{}) error { if d.HasChange("after") { // making changes to after require suspending the current task if err := suspendTask(ctx, client, taskId); err != nil { - return fmt.Errorf("error suspending task %s", taskId.FullyQualifiedName()) + return fmt.Errorf("error suspending task %s, err: %v", taskId.FullyQualifiedName(), err) } o, n := d.GetChange("after") diff --git a/pkg/resources/task_acceptance_test.go b/pkg/resources/task_acceptance_test.go index 9d50e1130e..e32d59af5d 100644 --- a/pkg/resources/task_acceptance_test.go +++ b/pkg/resources/task_acceptance_test.go @@ -600,11 +600,11 @@ func TestAcc_Task_SwitchScheduled(t *testing.T) { } func taskConfigManagedScheduled(name string, taskRootName string, databaseName string, schemaName string) string { - s := ` + return fmt.Sprintf(` resource "snowflake_task" "test_task_root" { - name = "%s" - database = "%s" - schema = "%s" + name = "%[1]s" + database = "%[2]s" + schema = "%[3]s" sql_statement = "SELECT 1" enabled = true schedule = "5 MINUTE" @@ -612,23 +612,22 @@ resource "snowflake_task" "test_task_root" { } resource "snowflake_task" "test_task" { - name = "%s" - database = "%s" - schema = "%s" + name = "%[4]s" + database = "%[2]s" + schema = "%[3]s" sql_statement = "SELECT 1" enabled = true schedule = "5 MINUTE" } -` - return fmt.Sprintf(s, taskRootName, databaseName, schemaName, name, databaseName, schemaName) +`, taskRootName, databaseName, schemaName, name) } func taskConfigManagedScheduled2(name string, taskRootName string, databaseName string, schemaName string) string { - s := ` + return fmt.Sprintf(` resource "snowflake_task" "test_task_root" { - name = "%s" - database = "%s" - schema = "%s" + name = "%[1]s" + database = "%[2]s" + schema = "%[3]s" sql_statement = "SELECT 1" enabled = true schedule = "5 MINUTE" @@ -636,15 +635,14 @@ resource "snowflake_task" "test_task_root" { } resource "snowflake_task" "test_task" { - name = "%s" - database = "%s" - schema = "%s" + name = "%[4]s" + database = "%[2]s" + schema = "%[3]s" sql_statement = "SELECT 1" enabled = true after = [snowflake_task.test_task_root.name] } -` - return fmt.Sprintf(s, taskRootName, databaseName, schemaName, name, databaseName, schemaName) +`, taskRootName, databaseName, schemaName, name) } func taskConfigManagedScheduled3(name string, taskRootName string, databaseName string, schemaName string) string { From 6cd1b513ca1e1b9940af2da4a5ff8966a22e835e Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Fri, 16 Feb 2024 13:30:45 +0100 Subject: [PATCH 4/6] Set random name in test --- pkg/resources/grant_database_role_acceptance_test.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pkg/resources/grant_database_role_acceptance_test.go b/pkg/resources/grant_database_role_acceptance_test.go index 4fcec9f346..53262c9da8 100644 --- a/pkg/resources/grant_database_role_acceptance_test.go +++ b/pkg/resources/grant_database_role_acceptance_test.go @@ -58,9 +58,9 @@ func TestAcc_GrantDatabaseRole_databaseRole(t *testing.T) { } func TestAcc_GrantDatabaseRole_issue2402(t *testing.T) { - databaseName := "DB_TEST_DB_DEV" - databaseRoleName := "TEST_DATABASE_ROLE_02" - parentDatabaseRoleName := "TEST_DATABASE_ROLE_01" + databaseName := strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha)) + databaseRoleName := strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha)) + parentDatabaseRoleName := strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha)) resourceName := "snowflake_grant_database_role.g" m := func() map[string]config.Variable { return map[string]config.Variable{ @@ -69,6 +69,7 @@ func TestAcc_GrantDatabaseRole_issue2402(t *testing.T) { "parent_database_role_name": config.StringVariable(parentDatabaseRoleName), } } + resource.Test(t, resource.TestCase{ ProtoV6ProviderFactories: acc.TestAccProtoV6ProviderFactories, PreCheck: func() { acc.TestAccPreCheck(t) }, From 9d6d5c72eb864446bb4ae058e3cb26497ab7fcef Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Fri, 16 Feb 2024 13:52:56 +0100 Subject: [PATCH 5/6] Fix linter --- pkg/resources/task.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/resources/task.go b/pkg/resources/task.go index b5dfb540ec..4c94c9a002 100644 --- a/pkg/resources/task.go +++ b/pkg/resources/task.go @@ -500,7 +500,7 @@ func UpdateTask(d *schema.ResourceData, meta interface{}) error { if d.HasChange("after") { // making changes to after require suspending the current task if err := suspendTask(ctx, client, taskId); err != nil { - return fmt.Errorf("error suspending task %s, err: %v", taskId.FullyQualifiedName(), err) + return fmt.Errorf("error suspending task %s, err: %w", taskId.FullyQualifiedName(), err) } o, n := d.GetChange("after") From ce7d50ad2f211854899c7e5b0b3b4fd0657c0e45 Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Fri, 16 Feb 2024 14:19:28 +0100 Subject: [PATCH 6/6] Added one more error log --- pkg/resources/stage.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/resources/stage.go b/pkg/resources/stage.go index f1fc964092..659b0cce85 100644 --- a/pkg/resources/stage.go +++ b/pkg/resources/stage.go @@ -150,7 +150,7 @@ func CreateStage(ctx context.Context, d *schema.ResourceData, meta any) diag.Dia q := builder.Create() if err := snowflake.Exec(db, q); err != nil { - return diag.Errorf("error creating stage %v", name) + return diag.Errorf("error creating stage %v, err: %v", name, err) } d.SetId(helpers.EncodeSnowflakeID(database, schema, name))