diff --git a/pkg/resources/function_java_acceptance_test.go b/pkg/resources/function_java_acceptance_test.go index e210974888..7edf7905e3 100644 --- a/pkg/resources/function_java_acceptance_test.go +++ b/pkg/resources/function_java_acceptance_test.go @@ -77,6 +77,22 @@ func TestAcc_FunctionJava_InlineBasic(t *testing.T) { assert.Check(resource.TestCheckResourceAttr(functionModel.ResourceReference(), "arguments.0.arg_default_value", "")), ), }, + // REMOVE EXTERNALLY (CHECK RECREATION) + { + PreConfig: func() { + acc.TestClient().Function.DropFunctionFunc(t, id)() + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(functionModel.ResourceReference(), plancheck.ResourceActionCreate), + }, + }, + Config: config.FromModels(t, functionModel), + Check: assert.AssertThat(t, + resourceassert.FunctionJavaResource(t, functionModel.ResourceReference()). + HasNameString(id.Name()), + ), + }, // IMPORT { ResourceName: functionModel.ResourceReference(), @@ -183,6 +199,7 @@ func TestAcc_FunctionJava_InlineBasicDefaultArg(t *testing.T) { func TestAcc_FunctionJava_InlineFull(t *testing.T) { _ = testenvs.GetOrSkipTest(t, testenvs.EnableAcceptance) acc.TestAccPreCheck(t) + t.Setenv(string(testenvs.ConfigureClientOnce), "") stage, stageCleanup := acc.TestClient().Stage.CreateStage(t) t.Cleanup(stageCleanup) diff --git a/pkg/resources/function_javascript_acceptance_test.go b/pkg/resources/function_javascript_acceptance_test.go index 2ef1c7d7f7..71028f1d1b 100644 --- a/pkg/resources/function_javascript_acceptance_test.go +++ b/pkg/resources/function_javascript_acceptance_test.go @@ -64,6 +64,22 @@ func TestAcc_FunctionJavascript_InlineBasic(t *testing.T) { assert.Check(resource.TestCheckResourceAttr(functionModel.ResourceReference(), "arguments.0.arg_default_value", "")), ), }, + // REMOVE EXTERNALLY (CHECK RECREATION) + { + PreConfig: func() { + acc.TestClient().Function.DropFunctionFunc(t, id)() + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(functionModel.ResourceReference(), plancheck.ResourceActionCreate), + }, + }, + Config: config.FromModels(t, functionModel), + Check: assert.AssertThat(t, + resourceassert.FunctionJavascriptResource(t, functionModel.ResourceReference()). + HasNameString(id.Name()), + ), + }, // RENAME { Config: config.FromModels(t, functionModelRenamed), diff --git a/pkg/resources/function_python_acceptance_test.go b/pkg/resources/function_python_acceptance_test.go index 04c82d91e5..487083c2c1 100644 --- a/pkg/resources/function_python_acceptance_test.go +++ b/pkg/resources/function_python_acceptance_test.go @@ -23,6 +23,10 @@ import ( ) func TestAcc_FunctionPython_InlineBasic(t *testing.T) { + _ = testenvs.GetOrSkipTest(t, testenvs.EnableAcceptance) + acc.TestAccPreCheck(t) + t.Setenv(string(testenvs.ConfigureClientOnce), "") + funcName := "some_function" argName := "x" dataType := testdatatypes.DataTypeNumber_36_2 @@ -64,6 +68,22 @@ func TestAcc_FunctionPython_InlineBasic(t *testing.T) { assert.Check(resource.TestCheckResourceAttr(functionModel.ResourceReference(), "arguments.0.arg_default_value", "")), ), }, + // REMOVE EXTERNALLY (CHECK RECREATION) + { + PreConfig: func() { + acc.TestClient().Function.DropFunctionFunc(t, id)() + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(functionModel.ResourceReference(), plancheck.ResourceActionCreate), + }, + }, + Config: config.FromModels(t, functionModel), + Check: assert.AssertThat(t, + resourceassert.FunctionPythonResource(t, functionModel.ResourceReference()). + HasNameString(id.Name()), + ), + }, // IMPORT { ResourceName: functionModel.ResourceReference(), @@ -94,6 +114,7 @@ func TestAcc_FunctionPython_InlineBasic(t *testing.T) { func TestAcc_FunctionPython_InlineFull(t *testing.T) { _ = testenvs.GetOrSkipTest(t, testenvs.EnableAcceptance) acc.TestAccPreCheck(t) + t.Setenv(string(testenvs.ConfigureClientOnce), "") secretId := acc.TestClient().Ids.RandomSchemaObjectIdentifier() secretId2 := acc.TestClient().Ids.RandomSchemaObjectIdentifier() diff --git a/pkg/resources/function_scala_acceptance_test.go b/pkg/resources/function_scala_acceptance_test.go index 2dbc466a4a..a8361b4f4e 100644 --- a/pkg/resources/function_scala_acceptance_test.go +++ b/pkg/resources/function_scala_acceptance_test.go @@ -69,6 +69,22 @@ func TestAcc_FunctionScala_InlineBasic(t *testing.T) { assert.Check(resource.TestCheckResourceAttr(functionModel.ResourceReference(), "arguments.0.arg_default_value", "")), ), }, + // REMOVE EXTERNALLY (CHECK RECREATION) + { + PreConfig: func() { + acc.TestClient().Function.DropFunctionFunc(t, id)() + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(functionModel.ResourceReference(), plancheck.ResourceActionCreate), + }, + }, + Config: config.FromModels(t, functionModel), + Check: assert.AssertThat(t, + resourceassert.FunctionScalaResource(t, functionModel.ResourceReference()). + HasNameString(id.Name()), + ), + }, // IMPORT { ResourceName: functionModel.ResourceReference(), @@ -99,6 +115,7 @@ func TestAcc_FunctionScala_InlineBasic(t *testing.T) { func TestAcc_FunctionScala_InlineFull(t *testing.T) { _ = testenvs.GetOrSkipTest(t, testenvs.EnableAcceptance) acc.TestAccPreCheck(t) + t.Setenv(string(testenvs.ConfigureClientOnce), "") stage, stageCleanup := acc.TestClient().Stage.CreateStage(t) t.Cleanup(stageCleanup) diff --git a/pkg/resources/function_sql_acceptance_test.go b/pkg/resources/function_sql_acceptance_test.go index c8df1348ed..f155f31e8a 100644 --- a/pkg/resources/function_sql_acceptance_test.go +++ b/pkg/resources/function_sql_acceptance_test.go @@ -4,7 +4,6 @@ import ( "testing" acc "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance" - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers/random" r "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/resources" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/assert" @@ -12,12 +11,14 @@ import ( "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/assert/resourceshowoutputassert" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/config" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/config/model" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers/random" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/importchecks" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/testdatatypes" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/helpers" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/provider/resources" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/plancheck" "github.com/hashicorp/terraform-plugin-testing/tfversion" ) @@ -25,7 +26,7 @@ func TestAcc_FunctionSql_InlineBasic(t *testing.T) { argName := "abc" dataType := testdatatypes.DataTypeFloat id := acc.TestClient().Ids.RandomSchemaObjectIdentifierWithArgumentsNewDataTypes(dataType) - idWithChangedNameButTheSameDataType := acc.TestClient().Ids.RandomSchemaObjectIdentifierWithArgumentsNewDataTypes() + idWithChangedNameButTheSameDataType := acc.TestClient().Ids.RandomSchemaObjectIdentifierWithArgumentsNewDataTypes(dataType) definition := acc.TestClient().Function.SampleSqlDefinitionWithArgument(t, argName) @@ -60,12 +61,28 @@ func TestAcc_FunctionSql_InlineBasic(t *testing.T) { assert.Check(resource.TestCheckResourceAttr(functionModel.ResourceReference(), "arguments.0.arg_default_value", "")), ), }, + // REMOVE EXTERNALLY (CHECK RECREATION) + { + PreConfig: func() { + acc.TestClient().Function.DropFunctionFunc(t, id)() + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(functionModel.ResourceReference(), plancheck.ResourceActionCreate), + }, + }, + Config: config.FromModels(t, functionModel), + Check: assert.AssertThat(t, + resourceassert.FunctionSqlResource(t, functionModel.ResourceReference()). + HasNameString(id.Name()), + ), + }, // IMPORT { ResourceName: functionModel.ResourceReference(), ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{}, + ImportStateVerifyIgnore: []string{"is_secure"}, ImportStateCheck: assert.AssertThatImport(t, resourceassert.ImportedFunctionSqlResource(t, id.FullyQualifiedName()). HasFullyQualifiedNameString(id.FullyQualifiedName()), diff --git a/pkg/resources/procedure_java_acceptance_test.go b/pkg/resources/procedure_java_acceptance_test.go index 651e1e35c5..b8d8dbb79b 100644 --- a/pkg/resources/procedure_java_acceptance_test.go +++ b/pkg/resources/procedure_java_acceptance_test.go @@ -76,6 +76,22 @@ func TestAcc_ProcedureJava_InlineBasic(t *testing.T) { assert.Check(resource.TestCheckResourceAttr(procedureModel.ResourceReference(), "arguments.0.arg_default_value", "")), ), }, + // REMOVE EXTERNALLY (CHECK RECREATION) + { + PreConfig: func() { + acc.TestClient().Procedure.DropProcedureFunc(t, id)() + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(procedureModel.ResourceReference(), plancheck.ResourceActionCreate), + }, + }, + Config: config.FromModels(t, procedureModel), + Check: assert.AssertThat(t, + resourceassert.ProcedureJavaResource(t, procedureModel.ResourceReference()). + HasNameString(id.Name()), + ), + }, // IMPORT { ResourceName: procedureModel.ResourceReference(), diff --git a/pkg/resources/procedure_javascript_acceptance_test.go b/pkg/resources/procedure_javascript_acceptance_test.go index 3a6bf5efd8..9040cfd225 100644 --- a/pkg/resources/procedure_javascript_acceptance_test.go +++ b/pkg/resources/procedure_javascript_acceptance_test.go @@ -62,6 +62,22 @@ func TestAcc_ProcedureJavascript_InlineBasic(t *testing.T) { assert.Check(resource.TestCheckResourceAttr(procedureModel.ResourceReference(), "arguments.0.arg_default_value", "")), ), }, + // REMOVE EXTERNALLY (CHECK RECREATION) + { + PreConfig: func() { + acc.TestClient().Procedure.DropProcedureFunc(t, id)() + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(procedureModel.ResourceReference(), plancheck.ResourceActionCreate), + }, + }, + Config: config.FromModels(t, procedureModel), + Check: assert.AssertThat(t, + resourceassert.ProcedureJavascriptResource(t, procedureModel.ResourceReference()). + HasNameString(id.Name()), + ), + }, // IMPORT { ResourceName: procedureModel.ResourceReference(), diff --git a/pkg/resources/procedure_python_acceptance_test.go b/pkg/resources/procedure_python_acceptance_test.go index 7932a83381..b9f4b681b5 100644 --- a/pkg/resources/procedure_python_acceptance_test.go +++ b/pkg/resources/procedure_python_acceptance_test.go @@ -65,6 +65,22 @@ func TestAcc_ProcedurePython_InlineBasic(t *testing.T) { assert.Check(resource.TestCheckResourceAttr(procedureModel.ResourceReference(), "arguments.0.arg_default_value", "")), ), }, + // REMOVE EXTERNALLY (CHECK RECREATION) + { + PreConfig: func() { + acc.TestClient().Procedure.DropProcedureFunc(t, id)() + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(procedureModel.ResourceReference(), plancheck.ResourceActionCreate), + }, + }, + Config: config.FromModels(t, procedureModel), + Check: assert.AssertThat(t, + resourceassert.ProcedurePythonResource(t, procedureModel.ResourceReference()). + HasNameString(id.Name()), + ), + }, // IMPORT { ResourceName: procedureModel.ResourceReference(), diff --git a/pkg/resources/procedure_scala_acceptance_test.go b/pkg/resources/procedure_scala_acceptance_test.go index a45a717b63..dcbfe7eda7 100644 --- a/pkg/resources/procedure_scala_acceptance_test.go +++ b/pkg/resources/procedure_scala_acceptance_test.go @@ -74,6 +74,22 @@ func TestAcc_ProcedureScala_InlineBasic(t *testing.T) { assert.Check(resource.TestCheckResourceAttr(procedureModel.ResourceReference(), "arguments.0.arg_default_value", "")), ), }, + // REMOVE EXTERNALLY (CHECK RECREATION) + { + PreConfig: func() { + acc.TestClient().Procedure.DropProcedureFunc(t, id)() + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(procedureModel.ResourceReference(), plancheck.ResourceActionCreate), + }, + }, + Config: config.FromModels(t, procedureModel), + Check: assert.AssertThat(t, + resourceassert.ProcedureScalaResource(t, procedureModel.ResourceReference()). + HasNameString(id.Name()), + ), + }, // IMPORT { ResourceName: procedureModel.ResourceReference(), diff --git a/pkg/resources/procedure_sql_acceptance_test.go b/pkg/resources/procedure_sql_acceptance_test.go index f00eb1003f..79fbb5bb98 100644 --- a/pkg/resources/procedure_sql_acceptance_test.go +++ b/pkg/resources/procedure_sql_acceptance_test.go @@ -62,6 +62,22 @@ func TestAcc_ProcedureSql_InlineBasic(t *testing.T) { assert.Check(resource.TestCheckResourceAttr(procedureModel.ResourceReference(), "arguments.0.arg_default_value", "")), ), }, + // REMOVE EXTERNALLY (CHECK RECREATION) + { + PreConfig: func() { + acc.TestClient().Procedure.DropProcedureFunc(t, id)() + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(procedureModel.ResourceReference(), plancheck.ResourceActionCreate), + }, + }, + Config: config.FromModels(t, procedureModel), + Check: assert.AssertThat(t, + resourceassert.ProcedureSqlResource(t, procedureModel.ResourceReference()). + HasNameString(id.Name()), + ), + }, // IMPORT { ResourceName: procedureModel.ResourceReference(),