diff --git a/docs/index.md b/docs/index.md index 31fc8211d8..bc11401f91 100644 --- a/docs/index.md +++ b/docs/index.md @@ -97,7 +97,7 @@ provider "snowflake" { - `passcode_in_password` (Boolean) False by default. Set to true if the MFA passcode is embedded to the configured password. Can also be sourced from the `SNOWFLAKE_PASSCODE_IN_PASSWORD` environment variable. - `password` (String, Sensitive) Password for user + password auth. Cannot be used with `private_key` and `private_key_passphrase`. Can also be sourced from the `SNOWFLAKE_PASSWORD` environment variable. - `port` (Number) Specifies a custom port value used by the driver for privatelink connections. Can also be sourced from the `SNOWFLAKE_PORT` environment variable. -- `preview_features_enabled` (Set of String) A list of preview features that are handled by the provider. See [preview features list](https://github.com/Snowflake-Labs/terraform-provider-snowflake/blob/main/v1-preparations/LIST_OF_PREVIEW_FEATURES_FOR_V1.md). Preview features may have breaking changes in future releases, even without raising the major version. This field can not be set with environmental variables. Valid options are: `snowflake_current_account_datasource` | `snowflake_account_authentication_policy_attachment_resource` | `snowflake_account_password_policy_attachment_resource` | `snowflake_alert_resource` | `snowflake_alerts_datasource` | `snowflake_api_integration_resource` | `snowflake_authentication_policy_resource` | `snowflake_cortex_search_service_resource` | `snowflake_cortex_search_services_datasource` | `snowflake_database_datasource` | `snowflake_database_role_datasource` | `snowflake_dynamic_table_resource` | `snowflake_dynamic_tables_datasource` | `snowflake_external_function_resource` | `snowflake_external_functions_datasource` | `snowflake_external_table_resource` | `snowflake_external_tables_datasource` | `snowflake_external_volume_resource` | `snowflake_failover_group_resource` | `snowflake_failover_groups_datasource` | `snowflake_file_format_resource` | `snowflake_file_formats_datasource` | `snowflake_function_java_resource` | `snowflake_function_javascript_resource` | `snowflake_function_python_resource` | `snowflake_function_scala_resource` | `snowflake_function_sql_resource` | `snowflake_managed_account_resource` | `snowflake_materialized_view_resource` | `snowflake_materialized_views_datasource` | `snowflake_network_policy_attachment_resource` | `snowflake_network_rule_resource` | `snowflake_email_notification_integration_resource` | `snowflake_notification_integration_resource` | `snowflake_object_parameter_resource` | `snowflake_password_policy_resource` | `snowflake_pipe_resource` | `snowflake_pipes_datasource` | `snowflake_current_role_datasource` | `snowflake_sequence_resource` | `snowflake_sequences_datasource` | `snowflake_share_resource` | `snowflake_shares_datasource` | `snowflake_parameters_datasource` | `snowflake_procedure_java_resource` | `snowflake_procedure_javascript_resource` | `snowflake_procedure_python_resource` | `snowflake_procedure_scala_resource` | `snowflake_procedure_sql_resource` | `snowflake_stage_resource` | `snowflake_stages_datasource` | `snowflake_storage_integration_resource` | `snowflake_storage_integrations_datasource` | `snowflake_system_generate_scim_access_token_datasource` | `snowflake_system_get_aws_sns_iam_policy_datasource` | `snowflake_system_get_privatelink_config_datasource` | `snowflake_system_get_snowflake_platform_info_datasource` | `snowflake_table_column_masking_policy_application_resource` | `snowflake_table_constraint_resource` | `snowflake_table_resource` | `snowflake_user_authentication_policy_attachment_resource` | `snowflake_user_public_keys_resource` | `snowflake_user_password_policy_attachment_resource`. +- `preview_features_enabled` (Set of String) A list of preview features that are handled by the provider. See [preview features list](https://github.com/Snowflake-Labs/terraform-provider-snowflake/blob/main/v1-preparations/LIST_OF_PREVIEW_FEATURES_FOR_V1.md). Preview features may have breaking changes in future releases, even without raising the major version. This field can not be set with environmental variables. Valid options are: `snowflake_current_account_datasource` | `snowflake_account_authentication_policy_attachment_resource` | `snowflake_account_password_policy_attachment_resource` | `snowflake_alert_resource` | `snowflake_alerts_datasource` | `snowflake_api_integration_resource` | `snowflake_authentication_policy_resource` | `snowflake_cortex_search_service_resource` | `snowflake_cortex_search_services_datasource` | `snowflake_database_datasource` | `snowflake_database_role_datasource` | `snowflake_dynamic_table_resource` | `snowflake_dynamic_tables_datasource` | `snowflake_external_function_resource` | `snowflake_external_functions_datasource` | `snowflake_external_table_resource` | `snowflake_external_tables_datasource` | `snowflake_external_volume_resource` | `snowflake_failover_group_resource` | `snowflake_failover_groups_datasource` | `snowflake_file_format_resource` | `snowflake_file_formats_datasource` | `snowflake_function_java_resource` | `snowflake_function_javascript_resource` | `snowflake_function_python_resource` | `snowflake_function_scala_resource` | `snowflake_function_sql_resource` | `snowflake_functions_datasource` | `snowflake_managed_account_resource` | `snowflake_materialized_view_resource` | `snowflake_materialized_views_datasource` | `snowflake_network_policy_attachment_resource` | `snowflake_network_rule_resource` | `snowflake_email_notification_integration_resource` | `snowflake_notification_integration_resource` | `snowflake_object_parameter_resource` | `snowflake_password_policy_resource` | `snowflake_pipe_resource` | `snowflake_pipes_datasource` | `snowflake_current_role_datasource` | `snowflake_sequence_resource` | `snowflake_sequences_datasource` | `snowflake_share_resource` | `snowflake_shares_datasource` | `snowflake_parameters_datasource` | `snowflake_procedure_java_resource` | `snowflake_procedure_javascript_resource` | `snowflake_procedure_python_resource` | `snowflake_procedure_scala_resource` | `snowflake_procedure_sql_resource` | `snowflake_procedures_datasource` | `snowflake_stage_resource` | `snowflake_stages_datasource` | `snowflake_storage_integration_resource` | `snowflake_storage_integrations_datasource` | `snowflake_system_generate_scim_access_token_datasource` | `snowflake_system_get_aws_sns_iam_policy_datasource` | `snowflake_system_get_privatelink_config_datasource` | `snowflake_system_get_snowflake_platform_info_datasource` | `snowflake_table_column_masking_policy_application_resource` | `snowflake_table_constraint_resource` | `snowflake_table_resource` | `snowflake_tables_datasource` | `snowflake_user_authentication_policy_attachment_resource` | `snowflake_user_public_keys_resource` | `snowflake_user_password_policy_attachment_resource`. - `private_key` (String, Sensitive) Private Key for username+private-key auth. Cannot be used with `password`. Can also be sourced from the `SNOWFLAKE_PRIVATE_KEY` environment variable. - `private_key_passphrase` (String, Sensitive) Supports the encryption ciphers aes-128-cbc, aes-128-gcm, aes-192-cbc, aes-192-gcm, aes-256-cbc, aes-256-gcm, and des-ede3-cbc. Can also be sourced from the `SNOWFLAKE_PRIVATE_KEY_PASSPHRASE` environment variable. - `profile` (String) Sets the profile to read from ~/.snowflake/config file. Can also be sourced from the `SNOWFLAKE_PROFILE` environment variable. diff --git a/pkg/datasources/functions_acceptance_test.go b/pkg/datasources/functions_acceptance_test.go index c30ab58db1..4ac49882fe 100644 --- a/pkg/datasources/functions_acceptance_test.go +++ b/pkg/datasources/functions_acceptance_test.go @@ -1,40 +1,37 @@ package datasources_test import ( + "fmt" "testing" acc "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance" - "github.com/hashicorp/terraform-plugin-testing/config" + "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/testdatatypes" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/testenvs" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/provider/resources" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/tfversion" ) func TestAcc_Functions(t *testing.T) { - functionNameOne := acc.TestClient().Ids.Alpha() - functionNameTwo := acc.TestClient().Ids.Alpha() + _ = testenvs.GetOrSkipTest(t, testenvs.EnableAcceptance) + acc.TestAccPreCheck(t) + t.Setenv(string(testenvs.ConfigureClientOnce), "") + dataSourceName := "data.snowflake_functions.functions" - m := func() map[string]config.Variable { - return map[string]config.Variable{ - "database": config.StringVariable(acc.TestDatabaseName), - "schema": config.StringVariable(acc.TestSchemaName), - "function_name_one": config.StringVariable(functionNameOne), - "function_name_two": config.StringVariable(functionNameTwo), - } - } - variableSet1 := m() resource.Test(t, resource.TestCase{ ProtoV6ProviderFactories: acc.TestAccProtoV6ProviderFactories, PreCheck: func() { acc.TestAccPreCheck(t) }, TerraformVersionChecks: []tfversion.TerraformVersionCheck{ tfversion.RequireAbove(tfversion.Version1_5_0), }, - CheckDestroy: nil, + CheckDestroy: acc.CheckDestroy(t, resources.FunctionJava), Steps: []resource.TestStep{ { - ConfigDirectory: acc.ConfigurationDirectory("TestAcc_Functions/complete"), - ConfigVariables: variableSet1, + Config: functionsConfig(t), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(dataSourceName, "database", acc.TestDatabaseName), resource.TestCheckResourceAttr(dataSourceName, "schema", acc.TestSchemaName), @@ -44,3 +41,33 @@ func TestAcc_Functions(t *testing.T) { }, }) } + +// TODO [SNOW-1348103]: use generated config builder when reworking the datasource +func functionsConfig(t *testing.T) string { + t.Helper() + + className := "TestFunc" + funcName := "echoVarchar" + argName := "x" + dataType := testdatatypes.DataTypeVarchar_100 + + handler := fmt.Sprintf("%s.%s", className, funcName) + definition := acc.TestClient().Function.SampleJavaDefinition(t, className, funcName, argName) + + id1 := acc.TestClient().Ids.RandomSchemaObjectIdentifierWithArgumentsNewDataTypes(dataType) + id2 := acc.TestClient().Ids.RandomSchemaObjectIdentifierWithArgumentsNewDataTypes(dataType) + + functionsSetup := config.FromModels(t, + model.FunctionJavaBasicInline("f1", id1, dataType, handler, definition).WithArgument(argName, dataType), + model.FunctionJavaBasicInline("f2", id2, dataType, handler, definition).WithArgument(argName, dataType), + ) + + return fmt.Sprintf(` +%s +data "snowflake_functions" "functions" { + database = "%s" + schema = "%s" + depends_on = [snowflake_function_java.f1, snowflake_function_java.f2] +} +`, functionsSetup, acc.TestDatabaseName, acc.TestSchemaName) +} diff --git a/pkg/datasources/procedures_acceptance_test.go b/pkg/datasources/procedures_acceptance_test.go index ceb1a3cea5..cf055e5850 100644 --- a/pkg/datasources/procedures_acceptance_test.go +++ b/pkg/datasources/procedures_acceptance_test.go @@ -1,38 +1,38 @@ package datasources_test import ( + "fmt" "testing" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/testenvs" + acc "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance" - "github.com/hashicorp/terraform-plugin-testing/config" + + "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/testdatatypes" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/provider/resources" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/tfversion" ) func TestAcc_Procedures(t *testing.T) { - procNameOne := acc.TestClient().Ids.Alpha() - procNameTwo := acc.TestClient().Ids.Alpha() + _ = testenvs.GetOrSkipTest(t, testenvs.EnableAcceptance) + acc.TestAccPreCheck(t) + t.Setenv(string(testenvs.ConfigureClientOnce), "") + dataSourceName := "data.snowflake_procedures.procedures" - m := func() map[string]config.Variable { - return map[string]config.Variable{ - "database": config.StringVariable(acc.TestDatabaseName), - "schema": config.StringVariable(acc.TestSchemaName), - "proc_name_one": config.StringVariable(procNameOne), - "proc_name_two": config.StringVariable(procNameTwo), - } - } - configVariables := m() + resource.Test(t, resource.TestCase{ ProtoV6ProviderFactories: acc.TestAccProtoV6ProviderFactories, PreCheck: func() { acc.TestAccPreCheck(t) }, TerraformVersionChecks: []tfversion.TerraformVersionCheck{ tfversion.RequireAbove(tfversion.Version1_5_0), }, - CheckDestroy: nil, + CheckDestroy: acc.CheckDestroy(t, resources.ProcedureJava), Steps: []resource.TestStep{ { - ConfigDirectory: acc.ConfigurationDirectory("TestAcc_Procedures/complete"), - ConfigVariables: configVariables, + Config: proceduresConfig(t), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(dataSourceName, "database", acc.TestDatabaseName), resource.TestCheckResourceAttr(dataSourceName, "schema", acc.TestSchemaName), @@ -44,3 +44,33 @@ func TestAcc_Procedures(t *testing.T) { }, }) } + +// TODO [SNOW-1348103]: use generated config builder when reworking the datasource +func proceduresConfig(t *testing.T) string { + t.Helper() + + className := "TestFunc" + funcName := "echoVarchar" + argName := "x" + dataType := testdatatypes.DataTypeVarchar_100 + + handler := fmt.Sprintf("%s.%s", className, funcName) + definition := acc.TestClient().Procedure.SampleJavaDefinition(t, className, funcName, argName) + + id1 := acc.TestClient().Ids.RandomSchemaObjectIdentifierWithArgumentsNewDataTypes(dataType) + id2 := acc.TestClient().Ids.RandomSchemaObjectIdentifierWithArgumentsNewDataTypes(dataType) + + functionsSetup := config.FromModels(t, + model.ProcedureJavaBasicInline("p1", id1, dataType, handler, definition).WithArgument(argName, dataType), + model.ProcedureJavaBasicInline("p2", id2, dataType, handler, definition).WithArgument(argName, dataType), + ) + + return fmt.Sprintf(` +%s +data "snowflake_procedures" "procedures" { + database = "%s" + schema = "%s" + depends_on = [snowflake_procedure_java.p1, snowflake_procedure_java.p2] +} +`, functionsSetup, acc.TestDatabaseName, acc.TestSchemaName) +} diff --git a/pkg/datasources/testdata/TestAcc_Functions/complete/test.tf b/pkg/datasources/testdata/TestAcc_Functions/complete/test.tf deleted file mode 100644 index 2baba5f105..0000000000 --- a/pkg/datasources/testdata/TestAcc_Functions/complete/test.tf +++ /dev/null @@ -1,33 +0,0 @@ -resource "snowflake_function" "test_function_one" { - name = var.function_name_one - database = var.database - schema = var.schema - return_type = "VARCHAR" - language = "JAVASCRIPT" - statement = <<-EOF - return "Hi" - EOF -} - -resource "snowflake_function" "test_function_two" { - name = var.function_name_two - database = var.database - schema = var.schema - arguments { - name = "arg1" - type = "varchar" - } - comment = "Terraform acceptance test" - return_type = "varchar" - language = "JAVASCRIPT" - statement = <<-EOF - var x = 1 - return x - EOF -} - -data "snowflake_functions" "functions" { - database = var.database - schema = var.schema - depends_on = [snowflake_function.test_function_one, snowflake_function.test_function_two] -} diff --git a/pkg/datasources/testdata/TestAcc_Functions/complete/variables.tf b/pkg/datasources/testdata/TestAcc_Functions/complete/variables.tf deleted file mode 100644 index af64399ad9..0000000000 --- a/pkg/datasources/testdata/TestAcc_Functions/complete/variables.tf +++ /dev/null @@ -1,15 +0,0 @@ -variable "function_name_one" { - type = string -} - -variable "function_name_two" { - type = string -} - -variable "database" { - type = string -} - -variable "schema" { - type = string -} diff --git a/pkg/datasources/testdata/TestAcc_Procedures/complete/test.tf b/pkg/datasources/testdata/TestAcc_Procedures/complete/test.tf deleted file mode 100644 index b91ba271a9..0000000000 --- a/pkg/datasources/testdata/TestAcc_Procedures/complete/test.tf +++ /dev/null @@ -1,47 +0,0 @@ -variable "proc_name_one" { - type = string -} - -variable "proc_name_two" { - type = string -} - -variable "database" { - type = string -} - -variable "schema" { - type = string -} - -resource "snowflake_procedure_javascript" "test_proc_one" { - name = var.proc_name_one - database = var.database - schema = var.schema - return_type = "VARCHAR" - statement = <<-EOF - return "Hi" - EOF -} - -resource "snowflake_procedure_javascript" "test_proc_two" { - name = var.proc_name_two - database = var.database - schema = var.schema - arguments { - name = "arg1" - type = "varchar" - } - comment = "Terraform acceptance test" - return_type = "varchar" - statement = <<-EOF - var X=1 - return X - EOF -} - -data "snowflake_procedures" "procedures" { - database = var.database - schema = var.schema - depends_on = [snowflake_procedure_javascript.test_proc_one, snowflake_procedure_javascript.test_proc_two] -} diff --git a/pkg/provider/previewfeatures/preview_features.go b/pkg/provider/previewfeatures/preview_features.go index 112ac705e6..5988f260c6 100644 --- a/pkg/provider/previewfeatures/preview_features.go +++ b/pkg/provider/previewfeatures/preview_features.go @@ -105,6 +105,7 @@ var allPreviewFeatures = []feature{ FunctionPythonResource, FunctionScalaResource, FunctionSqlResource, + FunctionsDatasource, ManagedAccountResource, MaterializedViewResource, MaterializedViewsDatasource, @@ -127,6 +128,7 @@ var allPreviewFeatures = []feature{ ProcedurePythonResource, ProcedureScalaResource, ProcedureSqlResource, + ProceduresDatasource, StageResource, StagesDatasource, StorageIntegrationResource, @@ -138,6 +140,7 @@ var allPreviewFeatures = []feature{ TableColumnMaskingPolicyApplicationResource, TableConstraintResource, TableResource, + TablesDatasource, UserAuthenticationPolicyAttachmentResource, UserPublicKeysResource, UserPasswordPolicyAttachmentResource, diff --git a/pkg/resources/testdata/TestAcc_ExternalFunction/complete/test.tf b/pkg/resources/testdata/TestAcc_ExternalFunction/complete/test.tf index e1e950a78d..718812d8bb 100644 --- a/pkg/resources/testdata/TestAcc_ExternalFunction/complete/test.tf +++ b/pkg/resources/testdata/TestAcc_ExternalFunction/complete/test.tf @@ -6,41 +6,36 @@ resource "snowflake_api_integration" "test_api_int" { enabled = true } -resource "snowflake_function" "test_func_req_translator" { +resource "snowflake_function_javascript" "test_func_req_translator" { name = "${var.name}_request_translator" database = var.database schema = var.schema arguments { - name = "EVENT" - type = "OBJECT" + arg_name = "EVENT" + arg_data_type = "OBJECT" } - comment = "Terraform acceptance test" - return_type = "OBJECT" - language = "javascript" - statement = <