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 = "..." 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) }, 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{ { 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)) diff --git a/pkg/resources/task.go b/pkg/resources/task.go index 44d72c9705..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", taskId.FullyQualifiedName()) + return fmt.Errorf("error suspending task %s, err: %w", 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 {