diff --git a/MIGRATION_GUIDE.md b/MIGRATION_GUIDE.md index d9bc0f050d..2fe0dd5647 100644 --- a/MIGRATION_GUIDE.md +++ b/MIGRATION_GUIDE.md @@ -9,6 +9,14 @@ across different versions. ## v0.99.0 ➞ v0.100.0 +### snowflake_account_parameter resource changes + +#### *(behavior change)* resource deletion +During resource deleting, provider now uses `UNSET` instead of `SET` with the default value. + +#### *(behavior change)* changes in `key` field +The value of `key` field is now case-insensitive and is validated. The list of supported values is available in the resource documentation. + ### snowflake_oauth_integration_for_partner_applications and snowflake_oauth_integration_for_custom_clients resource changes #### *(behavior change)* `blocked_roles_list` field is no longer required diff --git a/docs/resources/account_parameter.md b/docs/resources/account_parameter.md index 4607f52742..07b49e485f 100644 --- a/docs/resources/account_parameter.md +++ b/docs/resources/account_parameter.md @@ -2,12 +2,16 @@ page_title: "snowflake_account_parameter Resource - terraform-provider-snowflake" subcategory: "" description: |- - + Resource used to manage current account parameters. For more information, check parameters documentation https://docs.snowflake.com/en/sql-reference/parameters. --- -# snowflake_account_parameter (Resource) +!> **V1 release candidate** This resource was reworked and is a release candidate for the V1. We do not expect significant changes in it before the V1. We will welcome any feedback and adjust the resource if needed. Any errors reported will be resolved with a higher priority. We encourage checking this resource out before the V1 release. Please follow the [migration guide](https://github.com/Snowflake-Labs/terraform-provider-snowflake/blob/main/MIGRATION_GUIDE.md#v0990--v01000) to use it. + +-> **Note** This resource does not support all account parameters. The supported ones are listed below. This feature gap will be addressed in future releases. +# snowflake_account_parameter (Resource) +Resource used to manage current account parameters. For more information, check [parameters documentation](https://docs.snowflake.com/en/sql-reference/parameters). ## Example Usage @@ -22,7 +26,6 @@ resource "snowflake_account_parameter" "p2" { value = "256" } ``` - -> **Note** Instead of using fully_qualified_name, you can reference objects managed outside Terraform by constructing a correct ID, consult [identifiers guide](https://registry.terraform.io/providers/Snowflake-Labs/snowflake/latest/docs/guides/identifiers#new-computed-fully-qualified-name-field-in-resources). @@ -31,8 +34,8 @@ resource "snowflake_account_parameter" "p2" { ### Required -- `key` (String) Name of account parameter. Valid values are those in [account parameters](https://docs.snowflake.com/en/sql-reference/parameters.html#account-parameters). -- `value` (String) Value of account parameter, as a string. Constraints are the same as those for the parameters in Snowflake documentation. +- `key` (String) Name of account parameter. Valid values are (case-insensitive): `ALLOW_CLIENT_MFA_CACHING` | `ALLOW_ID_TOKEN` | `CLIENT_ENCRYPTION_KEY_SIZE` | `ENABLE_IDENTIFIER_FIRST_LOGIN` | `ENABLE_INTERNAL_STAGES_PRIVATELINK` | `ENABLE_TRI_SECRET_AND_REKEY_OPT_OUT_FOR_IMAGE_REPOSITORY` | `ENABLE_TRI_SECRET_AND_REKEY_OPT_OUT_FOR_SPCS_BLOCK_STORAGE` | `EVENT_TABLE` | `EXTERNAL_OAUTH_ADD_PRIVILEGED_ROLES_TO_BLOCKED_LIST` | `INITIAL_REPLICATION_SIZE_LIMIT_IN_TB` | `MIN_DATA_RETENTION_TIME_IN_DAYS` | `NETWORK_POLICY` | `OAUTH_ADD_PRIVILEGED_ROLES_TO_BLOCKED_LIST` | `PERIODIC_DATA_REKEYING` | `PREVENT_LOAD_FROM_INLINE_URL` | `PREVENT_UNLOAD_TO_INLINE_URL` | `PREVENT_UNLOAD_TO_INTERNAL_STAGES` | `REQUIRE_STORAGE_INTEGRATION_FOR_STAGE_CREATION` | `REQUIRE_STORAGE_INTEGRATION_FOR_STAGE_OPERATION` | `SSO_LOGIN_PAGE` | `ABORT_DETACHED_QUERY` | `AUTOCOMMIT` | `BINARY_INPUT_FORMAT` | `BINARY_OUTPUT_FORMAT` | `CLIENT_MEMORY_LIMIT` | `CLIENT_METADATA_REQUEST_USE_CONNECTION_CTX` | `CLIENT_METADATA_USE_SESSION_DATABASE` | `CLIENT_PREFETCH_THREADS` | `CLIENT_RESULT_CHUNK_SIZE` | `CLIENT_SESSION_KEEP_ALIVE` | `CLIENT_SESSION_KEEP_ALIVE_HEARTBEAT_FREQUENCY` | `CLIENT_TIMESTAMP_TYPE_MAPPING` | `ENABLE_UNLOAD_PHYSICAL_TYPE_OPTIMIZATION` | `CLIENT_RESULT_COLUMN_CASE_INSENSITIVE` | `DATE_INPUT_FORMAT` | `DATE_OUTPUT_FORMAT` | `ERROR_ON_NONDETERMINISTIC_MERGE` | `ERROR_ON_NONDETERMINISTIC_UPDATE` | `GEOGRAPHY_OUTPUT_FORMAT` | `GEOMETRY_OUTPUT_FORMAT` | `JDBC_TREAT_DECIMAL_AS_INT` | `JDBC_TREAT_TIMESTAMP_NTZ_AS_UTC` | `JDBC_USE_SESSION_TIMEZONE` | `JSON_INDENT` | `LOCK_TIMEOUT` | `MULTI_STATEMENT_COUNT` | `NOORDER_SEQUENCE_AS_DEFAULT` | `ODBC_TREAT_DECIMAL_AS_INT` | `QUERY_TAG` | `QUOTED_IDENTIFIERS_IGNORE_CASE` | `ROWS_PER_RESULTSET` | `S3_STAGE_VPCE_DNS_NAME` | `SEARCH_PATH` | `SIMULATED_DATA_SHARING_CONSUMER` | `STATEMENT_TIMEOUT_IN_SECONDS` | `STRICT_JSON_OUTPUT` | `TIME_INPUT_FORMAT` | `TIME_OUTPUT_FORMAT` | `TIMESTAMP_DAY_IS_ALWAYS_24H` | `TIMESTAMP_INPUT_FORMAT` | `TIMESTAMP_LTZ_OUTPUT_FORMAT` | `TIMESTAMP_NTZ_OUTPUT_FORMAT` | `TIMESTAMP_OUTPUT_FORMAT` | `TIMESTAMP_TYPE_MAPPING` | `TIMESTAMP_TZ_OUTPUT_FORMAT` | `TIMEZONE` | `TRANSACTION_ABORT_ON_ERROR` | `TRANSACTION_DEFAULT_ISOLATION_LEVEL` | `TWO_DIGIT_CENTURY_START` | `UNSUPPORTED_DDL_ACTION` | `USE_CACHED_RESULT` | `WEEK_OF_YEAR_POLICY` | `WEEK_START` | `CATALOG` | `DATA_RETENTION_TIME_IN_DAYS` | `DEFAULT_DDL_COLLATION` | `EXTERNAL_VOLUME` | `LOG_LEVEL` | `MAX_CONCURRENCY_LEVEL` | `MAX_DATA_EXTENSION_TIME_IN_DAYS` | `PIPE_EXECUTION_PAUSED` | `PREVENT_UNLOAD_TO_INTERNAL_STAGES` | `REPLACE_INVALID_CHARACTERS` | `STATEMENT_QUEUED_TIMEOUT_IN_SECONDS` | `STORAGE_SERIALIZATION_POLICY` | `SHARE_RESTRICTIONS` | `SUSPEND_TASK_AFTER_NUM_FAILURES` | `TRACE_LEVEL` | `USER_TASK_MANAGED_INITIAL_WAREHOUSE_SIZE` | `USER_TASK_TIMEOUT_MS` | `TASK_AUTO_RETRY_ATTEMPTS` | `USER_TASK_MINIMUM_TRIGGER_INTERVAL_IN_SECONDS` | `METRIC_LEVEL` | `ENABLE_CONSOLE_OUTPUT` | `ENABLE_UNREDACTED_QUERY_SYNTAX_ERROR`. +- `value` (String) Value of account parameter, as a string. Constraints are the same as those for the parameters in Snowflake documentation. The parameter values are validated in Snowflake. ### Read-Only @@ -43,5 +46,5 @@ resource "snowflake_account_parameter" "p2" { Import is supported using the following syntax: ```shell -terraform import snowflake_account_parameter.p +terraform import snowflake_account_parameter.p '' ``` diff --git a/examples/resources/snowflake_account_parameter/import.sh b/examples/resources/snowflake_account_parameter/import.sh index c1dd2640d1..c5a0051fd8 100644 --- a/examples/resources/snowflake_account_parameter/import.sh +++ b/examples/resources/snowflake_account_parameter/import.sh @@ -1 +1 @@ -terraform import snowflake_account_parameter.p +terraform import snowflake_account_parameter.p '' diff --git a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/database_parameters_snowflake_gen.go b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/database_parameters_snowflake_gen.go index 6c33814187..8937660447 100644 --- a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/database_parameters_snowflake_gen.go +++ b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/database_parameters_snowflake_gen.go @@ -81,7 +81,7 @@ func (d *DatabaseParametersAssert) HasAllDefaults() *DatabaseParametersAssert { HasDefaultParameterValueOnLevel(sdk.DatabaseParameterUserTaskManagedInitialWarehouseSize, sdk.ParameterTypeSnowflakeDefault). HasDefaultParameterValueOnLevel(sdk.DatabaseParameterUserTaskTimeoutMs, sdk.ParameterTypeSnowflakeDefault). HasDefaultParameterValueOnLevel(sdk.DatabaseParameterUserTaskMinimumTriggerIntervalInSeconds, sdk.ParameterTypeSnowflakeDefault). - HasDefaultParameterValueOnLevel(sdk.DatabaseParameterQuotedIdentifiersIgnoreCase, sdk.ParameterTypeAccount). + HasDefaultParameterValueOnLevel(sdk.DatabaseParameterQuotedIdentifiersIgnoreCase, sdk.ParameterTypeSnowflakeDefault). HasDefaultParameterValueOnLevel(sdk.DatabaseParameterEnableConsoleOutput, sdk.ParameterTypeSnowflakeDefault) } diff --git a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/object_parameters_def.go b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/object_parameters_def.go index fd716a8993..9f9c3c6733 100644 --- a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/object_parameters_def.go +++ b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/object_parameters_def.go @@ -36,7 +36,7 @@ var allObjectsParameters = []SnowflakeObjectParameters{ {ParameterName: string(sdk.UserParameterNetworkPolicy), ParameterType: "string", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, {ParameterName: string(sdk.UserParameterPreventUnloadToInternalStages), ParameterType: "bool", DefaultValue: "false", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, {ParameterName: string(sdk.UserParameterAbortDetachedQuery), ParameterType: "bool", DefaultValue: "false", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, - {ParameterName: string(sdk.UserParameterAutocommit), ParameterType: "bool", DefaultValue: "true", DefaultLevel: "sdk.ParameterTypeAccount"}, + {ParameterName: string(sdk.UserParameterAutocommit), ParameterType: "bool", DefaultValue: "true", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, {ParameterName: string(sdk.UserParameterBinaryInputFormat), ParameterType: "sdk.BinaryInputFormat", DefaultValue: "sdk.BinaryInputFormatHex", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, {ParameterName: string(sdk.UserParameterBinaryOutputFormat), ParameterType: "sdk.BinaryOutputFormat", DefaultValue: "sdk.BinaryOutputFormatHex", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, {ParameterName: string(sdk.UserParameterClientMemoryLimit), ParameterType: "int", DefaultValue: "1536", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, @@ -64,7 +64,7 @@ var allObjectsParameters = []SnowflakeObjectParameters{ {ParameterName: string(sdk.UserParameterNoorderSequenceAsDefault), ParameterType: "bool", DefaultValue: "true", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, {ParameterName: string(sdk.UserParameterOdbcTreatDecimalAsInt), ParameterType: "bool", DefaultValue: "false", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, {ParameterName: string(sdk.UserParameterQueryTag), ParameterType: "string", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, - {ParameterName: string(sdk.UserParameterQuotedIdentifiersIgnoreCase), ParameterType: "bool", DefaultValue: "false", DefaultLevel: "sdk.ParameterTypeAccount"}, + {ParameterName: string(sdk.UserParameterQuotedIdentifiersIgnoreCase), ParameterType: "bool", DefaultValue: "false", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, {ParameterName: string(sdk.UserParameterRowsPerResultset), ParameterType: "int", DefaultValue: "0", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, {ParameterName: string(sdk.UserParameterS3StageVpceDnsName), ParameterType: "string", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, {ParameterName: string(sdk.UserParameterSearchPath), ParameterType: "string", DefaultValue: "$current, $public", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, @@ -83,7 +83,7 @@ var allObjectsParameters = []SnowflakeObjectParameters{ {ParameterName: string(sdk.UserParameterTimeInputFormat), ParameterType: "string", DefaultValue: "AUTO", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, {ParameterName: string(sdk.UserParameterTimeOutputFormat), ParameterType: "string", DefaultValue: "HH24:MI:SS", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, {ParameterName: string(sdk.UserParameterTraceLevel), ParameterType: "sdk.TraceLevel", DefaultValue: "sdk.TraceLevelOff", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, - {ParameterName: string(sdk.UserParameterTransactionAbortOnError), ParameterType: "bool", DefaultValue: "false", DefaultLevel: "sdk.ParameterTypeAccount"}, + {ParameterName: string(sdk.UserParameterTransactionAbortOnError), ParameterType: "bool", DefaultValue: "false", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, {ParameterName: string(sdk.UserParameterTransactionDefaultIsolationLevel), ParameterType: "sdk.TransactionDefaultIsolationLevel", DefaultValue: "sdk.TransactionDefaultIsolationLevelReadCommitted", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, {ParameterName: string(sdk.UserParameterTwoDigitCenturyStart), ParameterType: "int", DefaultValue: "1970", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, // TODO [SNOW-1501905]: quick workaround for now: lowercase for ignore in snowflake by default but uppercase for FAIL @@ -124,7 +124,7 @@ var allObjectsParameters = []SnowflakeObjectParameters{ {ParameterName: string(sdk.DatabaseParameterUserTaskManagedInitialWarehouseSize), ParameterType: "sdk.WarehouseSize", DefaultValue: "sdk.WarehouseSizeMedium", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, {ParameterName: string(sdk.DatabaseParameterUserTaskTimeoutMs), ParameterType: "int", DefaultValue: "3600000", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, {ParameterName: string(sdk.DatabaseParameterUserTaskMinimumTriggerIntervalInSeconds), ParameterType: "int", DefaultValue: "30", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, - {ParameterName: string(sdk.DatabaseParameterQuotedIdentifiersIgnoreCase), ParameterType: "bool", DefaultValue: "false", DefaultLevel: "sdk.ParameterTypeAccount"}, + {ParameterName: string(sdk.DatabaseParameterQuotedIdentifiersIgnoreCase), ParameterType: "bool", DefaultValue: "false", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, {ParameterName: string(sdk.DatabaseParameterEnableConsoleOutput), ParameterType: "bool", DefaultValue: "false", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, }, }, @@ -139,7 +139,7 @@ var allObjectsParameters = []SnowflakeObjectParameters{ {ParameterName: string(sdk.TaskParameterUserTaskMinimumTriggerIntervalInSeconds), ParameterType: "int", DefaultValue: "30", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, {ParameterName: string(sdk.TaskParameterUserTaskTimeoutMs), ParameterType: "int", DefaultValue: "3600000", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, {ParameterName: string(sdk.TaskParameterAbortDetachedQuery), ParameterType: "bool", DefaultValue: "false", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, - {ParameterName: string(sdk.TaskParameterAutocommit), ParameterType: "bool", DefaultValue: "true", DefaultLevel: "sdk.ParameterTypeAccount"}, + {ParameterName: string(sdk.TaskParameterAutocommit), ParameterType: "bool", DefaultValue: "true", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, {ParameterName: string(sdk.TaskParameterBinaryInputFormat), ParameterType: "sdk.BinaryInputFormat", DefaultValue: "sdk.BinaryInputFormatHex", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, {ParameterName: string(sdk.TaskParameterBinaryOutputFormat), ParameterType: "sdk.BinaryOutputFormat", DefaultValue: "sdk.BinaryOutputFormatHex", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, {ParameterName: string(sdk.TaskParameterClientMemoryLimit), ParameterType: "int", DefaultValue: "1536", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, @@ -166,7 +166,7 @@ var allObjectsParameters = []SnowflakeObjectParameters{ {ParameterName: string(sdk.TaskParameterNoorderSequenceAsDefault), ParameterType: "bool", DefaultValue: "true", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, {ParameterName: string(sdk.TaskParameterOdbcTreatDecimalAsInt), ParameterType: "bool", DefaultValue: "false", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, {ParameterName: string(sdk.TaskParameterQueryTag), ParameterType: "string", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, - {ParameterName: string(sdk.TaskParameterQuotedIdentifiersIgnoreCase), ParameterType: "bool", DefaultValue: "false", DefaultLevel: "sdk.ParameterTypeAccount"}, + {ParameterName: string(sdk.TaskParameterQuotedIdentifiersIgnoreCase), ParameterType: "bool", DefaultValue: "false", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, {ParameterName: string(sdk.TaskParameterRowsPerResultset), ParameterType: "int", DefaultValue: "0", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, {ParameterName: string(sdk.TaskParameterS3StageVpceDnsName), ParameterType: "string", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, {ParameterName: string(sdk.TaskParameterSearchPath), ParameterType: "string", DefaultValue: "$current, $public", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, @@ -184,7 +184,7 @@ var allObjectsParameters = []SnowflakeObjectParameters{ {ParameterName: string(sdk.TaskParameterTimeInputFormat), ParameterType: "string", DefaultValue: "AUTO", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, {ParameterName: string(sdk.TaskParameterTimeOutputFormat), ParameterType: "string", DefaultValue: "HH24:MI:SS", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, {ParameterName: string(sdk.TaskParameterTraceLevel), ParameterType: "sdk.TraceLevel", DefaultValue: "sdk.TraceLevelOff", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, - {ParameterName: string(sdk.TaskParameterTransactionAbortOnError), ParameterType: "bool", DefaultValue: "false", DefaultLevel: "sdk.ParameterTypeAccount"}, + {ParameterName: string(sdk.TaskParameterTransactionAbortOnError), ParameterType: "bool", DefaultValue: "false", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, {ParameterName: string(sdk.TaskParameterTransactionDefaultIsolationLevel), ParameterType: "sdk.TransactionDefaultIsolationLevel", DefaultValue: "sdk.TransactionDefaultIsolationLevelReadCommitted", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, {ParameterName: string(sdk.TaskParameterTwoDigitCenturyStart), ParameterType: "int", DefaultValue: "1970", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, // TODO [SNOW-1501905]: quick workaround for now: lowercase for ignore in snowflake by default but uppercase for FAIL diff --git a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/task_parameters_snowflake_gen.go b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/task_parameters_snowflake_gen.go index b5c571149d..85ef79ebd6 100644 --- a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/task_parameters_snowflake_gen.go +++ b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/task_parameters_snowflake_gen.go @@ -74,7 +74,7 @@ func (t *TaskParametersAssert) HasAllDefaults() *TaskParametersAssert { HasDefaultParameterValueOnLevel(sdk.TaskParameterUserTaskMinimumTriggerIntervalInSeconds, sdk.ParameterTypeSnowflakeDefault). HasDefaultParameterValueOnLevel(sdk.TaskParameterUserTaskTimeoutMs, sdk.ParameterTypeSnowflakeDefault). HasDefaultParameterValueOnLevel(sdk.TaskParameterAbortDetachedQuery, sdk.ParameterTypeSnowflakeDefault). - HasDefaultParameterValueOnLevel(sdk.TaskParameterAutocommit, sdk.ParameterTypeAccount). + HasDefaultParameterValueOnLevel(sdk.TaskParameterAutocommit, sdk.ParameterTypeSnowflakeDefault). HasDefaultParameterValueOnLevel(sdk.TaskParameterBinaryInputFormat, sdk.ParameterTypeSnowflakeDefault). HasDefaultParameterValueOnLevel(sdk.TaskParameterBinaryOutputFormat, sdk.ParameterTypeSnowflakeDefault). HasDefaultParameterValueOnLevel(sdk.TaskParameterClientMemoryLimit, sdk.ParameterTypeSnowflakeDefault). @@ -101,7 +101,7 @@ func (t *TaskParametersAssert) HasAllDefaults() *TaskParametersAssert { HasDefaultParameterValueOnLevel(sdk.TaskParameterNoorderSequenceAsDefault, sdk.ParameterTypeSnowflakeDefault). HasDefaultParameterValueOnLevel(sdk.TaskParameterOdbcTreatDecimalAsInt, sdk.ParameterTypeSnowflakeDefault). HasDefaultParameterValueOnLevel(sdk.TaskParameterQueryTag, sdk.ParameterTypeSnowflakeDefault). - HasDefaultParameterValueOnLevel(sdk.TaskParameterQuotedIdentifiersIgnoreCase, sdk.ParameterTypeAccount). + HasDefaultParameterValueOnLevel(sdk.TaskParameterQuotedIdentifiersIgnoreCase, sdk.ParameterTypeSnowflakeDefault). HasDefaultParameterValueOnLevel(sdk.TaskParameterRowsPerResultset, sdk.ParameterTypeSnowflakeDefault). HasDefaultParameterValueOnLevel(sdk.TaskParameterS3StageVpceDnsName, sdk.ParameterTypeSnowflakeDefault). HasDefaultParameterValueOnLevel(sdk.TaskParameterSearchPath, sdk.ParameterTypeSnowflakeDefault). @@ -119,7 +119,7 @@ func (t *TaskParametersAssert) HasAllDefaults() *TaskParametersAssert { HasDefaultParameterValueOnLevel(sdk.TaskParameterTimeInputFormat, sdk.ParameterTypeSnowflakeDefault). HasDefaultParameterValueOnLevel(sdk.TaskParameterTimeOutputFormat, sdk.ParameterTypeSnowflakeDefault). HasDefaultParameterValueOnLevel(sdk.TaskParameterTraceLevel, sdk.ParameterTypeSnowflakeDefault). - HasDefaultParameterValueOnLevel(sdk.TaskParameterTransactionAbortOnError, sdk.ParameterTypeAccount). + HasDefaultParameterValueOnLevel(sdk.TaskParameterTransactionAbortOnError, sdk.ParameterTypeSnowflakeDefault). HasDefaultParameterValueOnLevel(sdk.TaskParameterTransactionDefaultIsolationLevel, sdk.ParameterTypeSnowflakeDefault). HasDefaultParameterValueOnLevel(sdk.TaskParameterTwoDigitCenturyStart, sdk.ParameterTypeSnowflakeDefault). HasDefaultParameterValueOnLevel(sdk.TaskParameterUnsupportedDdlAction, sdk.ParameterTypeSnowflakeDefault). diff --git a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/user_parameters_snowflake_gen.go b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/user_parameters_snowflake_gen.go index 4f860eb38d..433fc0fa70 100644 --- a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/user_parameters_snowflake_gen.go +++ b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/user_parameters_snowflake_gen.go @@ -72,7 +72,7 @@ func (u *UserParametersAssert) HasAllDefaults() *UserParametersAssert { HasDefaultParameterValueOnLevel(sdk.UserParameterNetworkPolicy, sdk.ParameterTypeSnowflakeDefault). HasDefaultParameterValueOnLevel(sdk.UserParameterPreventUnloadToInternalStages, sdk.ParameterTypeSnowflakeDefault). HasDefaultParameterValueOnLevel(sdk.UserParameterAbortDetachedQuery, sdk.ParameterTypeSnowflakeDefault). - HasDefaultParameterValueOnLevel(sdk.UserParameterAutocommit, sdk.ParameterTypeAccount). + HasDefaultParameterValueOnLevel(sdk.UserParameterAutocommit, sdk.ParameterTypeSnowflakeDefault). HasDefaultParameterValueOnLevel(sdk.UserParameterBinaryInputFormat, sdk.ParameterTypeSnowflakeDefault). HasDefaultParameterValueOnLevel(sdk.UserParameterBinaryOutputFormat, sdk.ParameterTypeSnowflakeDefault). HasDefaultParameterValueOnLevel(sdk.UserParameterClientMemoryLimit, sdk.ParameterTypeSnowflakeDefault). @@ -100,7 +100,7 @@ func (u *UserParametersAssert) HasAllDefaults() *UserParametersAssert { HasDefaultParameterValueOnLevel(sdk.UserParameterNoorderSequenceAsDefault, sdk.ParameterTypeSnowflakeDefault). HasDefaultParameterValueOnLevel(sdk.UserParameterOdbcTreatDecimalAsInt, sdk.ParameterTypeSnowflakeDefault). HasDefaultParameterValueOnLevel(sdk.UserParameterQueryTag, sdk.ParameterTypeSnowflakeDefault). - HasDefaultParameterValueOnLevel(sdk.UserParameterQuotedIdentifiersIgnoreCase, sdk.ParameterTypeAccount). + HasDefaultParameterValueOnLevel(sdk.UserParameterQuotedIdentifiersIgnoreCase, sdk.ParameterTypeSnowflakeDefault). HasDefaultParameterValueOnLevel(sdk.UserParameterRowsPerResultset, sdk.ParameterTypeSnowflakeDefault). HasDefaultParameterValueOnLevel(sdk.UserParameterS3StageVpceDnsName, sdk.ParameterTypeSnowflakeDefault). HasDefaultParameterValueOnLevel(sdk.UserParameterSearchPath, sdk.ParameterTypeSnowflakeDefault). @@ -119,7 +119,7 @@ func (u *UserParametersAssert) HasAllDefaults() *UserParametersAssert { HasDefaultParameterValueOnLevel(sdk.UserParameterTimeInputFormat, sdk.ParameterTypeSnowflakeDefault). HasDefaultParameterValueOnLevel(sdk.UserParameterTimeOutputFormat, sdk.ParameterTypeSnowflakeDefault). HasDefaultParameterValueOnLevel(sdk.UserParameterTraceLevel, sdk.ParameterTypeSnowflakeDefault). - HasDefaultParameterValueOnLevel(sdk.UserParameterTransactionAbortOnError, sdk.ParameterTypeAccount). + HasDefaultParameterValueOnLevel(sdk.UserParameterTransactionAbortOnError, sdk.ParameterTypeSnowflakeDefault). HasDefaultParameterValueOnLevel(sdk.UserParameterTransactionDefaultIsolationLevel, sdk.ParameterTypeSnowflakeDefault). HasDefaultParameterValueOnLevel(sdk.UserParameterTwoDigitCenturyStart, sdk.ParameterTypeSnowflakeDefault). HasDefaultParameterValueOnLevel(sdk.UserParameterUnsupportedDdlAction, sdk.ParameterTypeSnowflakeDefault). diff --git a/pkg/acceptance/bettertestspoc/assert/resourceassert/account_parameter_resource_gen.go b/pkg/acceptance/bettertestspoc/assert/resourceassert/account_parameter_resource_gen.go new file mode 100644 index 0000000000..a021e54a07 --- /dev/null +++ b/pkg/acceptance/bettertestspoc/assert/resourceassert/account_parameter_resource_gen.go @@ -0,0 +1,57 @@ +// Code generated by assertions generator; DO NOT EDIT. + +package resourceassert + +import ( + "testing" + + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/assert" +) + +type AccountParameterResourceAssert struct { + *assert.ResourceAssert +} + +func AccountParameterResource(t *testing.T, name string) *AccountParameterResourceAssert { + t.Helper() + + return &AccountParameterResourceAssert{ + ResourceAssert: assert.NewResourceAssert(name, "resource"), + } +} + +func ImportedAccountParameterResource(t *testing.T, id string) *AccountParameterResourceAssert { + t.Helper() + + return &AccountParameterResourceAssert{ + ResourceAssert: assert.NewImportedResourceAssert(id, "imported resource"), + } +} + +/////////////////////////////////// +// Attribute value string checks // +/////////////////////////////////// + +func (a *AccountParameterResourceAssert) HasKeyString(expected string) *AccountParameterResourceAssert { + a.AddAssertion(assert.ValueSet("key", expected)) + return a +} + +func (a *AccountParameterResourceAssert) HasValueString(expected string) *AccountParameterResourceAssert { + a.AddAssertion(assert.ValueSet("value", expected)) + return a +} + +//////////////////////////// +// Attribute empty checks // +//////////////////////////// + +func (a *AccountParameterResourceAssert) HasNoKey() *AccountParameterResourceAssert { + a.AddAssertion(assert.ValueNotSet("key")) + return a +} + +func (a *AccountParameterResourceAssert) HasNoValue() *AccountParameterResourceAssert { + a.AddAssertion(assert.ValueNotSet("value")) + return a +} diff --git a/pkg/acceptance/bettertestspoc/assert/resourceassert/gen/resource_schema_def.go b/pkg/acceptance/bettertestspoc/assert/resourceassert/gen/resource_schema_def.go index e39d6f0533..e757ffc0a6 100644 --- a/pkg/acceptance/bettertestspoc/assert/resourceassert/gen/resource_schema_def.go +++ b/pkg/acceptance/bettertestspoc/assert/resourceassert/gen/resource_schema_def.go @@ -121,6 +121,10 @@ var allResourceSchemaDefs = []ResourceSchemaDef{ name: "Account", schema: resources.Account().Schema, }, + { + name: "AccountParameter", + schema: resources.AccountParameter().Schema, + }, { name: "OauthIntegrationForCustomClients", schema: resources.OauthIntegrationForCustomClients().Schema, diff --git a/pkg/acceptance/bettertestspoc/config/model/account_parameter_model_gen.go b/pkg/acceptance/bettertestspoc/config/model/account_parameter_model_gen.go new file mode 100644 index 0000000000..9fc1cff42a --- /dev/null +++ b/pkg/acceptance/bettertestspoc/config/model/account_parameter_model_gen.go @@ -0,0 +1,70 @@ +// Code generated by config model builder generator; DO NOT EDIT. + +package model + +import ( + tfconfig "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/provider/resources" +) + +type AccountParameterModel struct { + Key tfconfig.Variable `json:"key,omitempty"` + Value tfconfig.Variable `json:"value,omitempty"` + + *config.ResourceModelMeta +} + +///////////////////////////////////////////////// +// Basic builders (resource name and required) // +///////////////////////////////////////////////// + +func AccountParameter( + resourceName string, + key string, + value string, +) *AccountParameterModel { + a := &AccountParameterModel{ResourceModelMeta: config.Meta(resourceName, resources.AccountParameter)} + a.WithKey(key) + a.WithValue(value) + return a +} + +func AccountParameterWithDefaultMeta( + key string, + value string, +) *AccountParameterModel { + a := &AccountParameterModel{ResourceModelMeta: config.DefaultMeta(resources.AccountParameter)} + a.WithKey(key) + a.WithValue(value) + return a +} + +///////////////////////////////// +// below all the proper values // +///////////////////////////////// + +func (a *AccountParameterModel) WithKey(key string) *AccountParameterModel { + a.Key = tfconfig.StringVariable(key) + return a +} + +func (a *AccountParameterModel) WithValue(value string) *AccountParameterModel { + a.Value = tfconfig.StringVariable(value) + return a +} + +////////////////////////////////////////// +// below it's possible to set any value // +////////////////////////////////////////// + +func (a *AccountParameterModel) WithKeyValue(value tfconfig.Variable) *AccountParameterModel { + a.Key = value + return a +} + +func (a *AccountParameterModel) WithValueValue(value tfconfig.Variable) *AccountParameterModel { + a.Value = value + return a +} diff --git a/pkg/acceptance/check_destroy.go b/pkg/acceptance/check_destroy.go index 5959720df0..6d056a613b 100644 --- a/pkg/acceptance/check_destroy.go +++ b/pkg/acceptance/check_destroy.go @@ -630,3 +630,19 @@ func TestAccCheckGrantApplicationRoleDestroy(s *terraform.State) error { } return nil } + +func CheckAccountParameterUnset(t *testing.T, paramName sdk.AccountParameter) func(*terraform.State) error { + t.Helper() + return func(s *terraform.State) error { + for _, rs := range s.RootModule().Resources { + if rs.Type != "snowflake_account_parameter" { + continue + } + parameter := TestClient().Parameter.ShowAccountParameter(t, paramName) + if parameter.Level != sdk.ParameterTypeSnowflakeDefault { + return fmt.Errorf("expected parameter level empty, got %v", parameter.Level) + } + } + return nil + } +} diff --git a/pkg/resources/account_parameter.go b/pkg/resources/account_parameter.go index 95cea28579..2f8021c080 100644 --- a/pkg/resources/account_parameter.go +++ b/pkg/resources/account_parameter.go @@ -2,8 +2,10 @@ package resources import ( "context" + "errors" "fmt" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/helpers" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/provider/resources" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" @@ -15,15 +17,17 @@ import ( var accountParameterSchema = map[string]*schema.Schema{ "key": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - Description: "Name of account parameter. Valid values are those in [account parameters](https://docs.snowflake.com/en/sql-reference/parameters.html#account-parameters).", + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateDiagFunc: sdkValidation(sdk.ToAccountParameter), + DiffSuppressFunc: NormalizeAndCompare(sdk.ToAccountParameter), + Description: fmt.Sprintf("Name of account parameter. Valid values are (case-insensitive): %s.", possibleValuesListed(sdk.AsStringList(sdk.AllAccountParameters))), }, "value": { Type: schema.TypeString, Required: true, - Description: "Value of account parameter, as a string. Constraints are the same as those for the parameters in Snowflake documentation.", + Description: "Value of account parameter, as a string. Constraints are the same as those for the parameters in Snowflake documentation. The parameter values are validated in Snowflake.", }, } @@ -34,6 +38,8 @@ func AccountParameter() *schema.Resource { UpdateContext: TrackingUpdateWrapper(resources.AccountParameter, UpdateAccountParameter), DeleteContext: TrackingDeleteWrapper(resources.AccountParameter, DeleteAccountParameter), + Description: "Resource used to manage current account parameters. For more information, check [parameters documentation](https://docs.snowflake.com/en/sql-reference/parameters).", + Schema: accountParameterSchema, Importer: &schema.ResourceImporter{ StateContext: schema.ImportStatePassthroughContext, @@ -42,56 +48,58 @@ func AccountParameter() *schema.Resource { } // CreateAccountParameter implements schema.CreateFunc. -func CreateAccountParameter(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func CreateAccountParameter(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { client := meta.(*provider.Context).Client key := d.Get("key").(string) value := d.Get("value").(string) - parameter := sdk.AccountParameter(key) - err := client.Parameters.SetAccountParameter(ctx, parameter, value) + parameter, err := sdk.ToAccountParameter(key) + if err != nil { + return diag.FromErr(err) + } + err = client.Parameters.SetAccountParameter(ctx, parameter, value) if err != nil { return diag.FromErr(err) } - d.SetId(key) + d.SetId(helpers.EncodeResourceIdentifier(string(parameter))) return ReadAccountParameter(ctx, d, meta) } // ReadAccountParameter implements schema.ReadFunc. -func ReadAccountParameter(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func ReadAccountParameter(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { client := meta.(*provider.Context).Client - parameterName := d.Id() - parameter, err := client.Parameters.ShowAccountParameter(ctx, sdk.AccountParameter(parameterName)) + parameterNameRaw := d.Id() + parameterName, err := sdk.ToAccountParameter(parameterNameRaw) if err != nil { - return diag.FromErr(fmt.Errorf("error reading account parameter err = %w", err)) + return diag.FromErr(err) } - err = d.Set("value", parameter.Value) + parameter, err := client.Parameters.ShowAccountParameter(ctx, parameterName) if err != nil { - return diag.FromErr(fmt.Errorf("error setting account parameter err = %w", err)) + return diag.FromErr(fmt.Errorf("reading account parameter: %w", err)) } - err = d.Set("key", parameter.Key) - if err != nil { - return diag.FromErr(fmt.Errorf("error setting account parameter err = %w", err)) + errs := errors.Join( + d.Set("value", parameter.Value), + d.Set("key", parameter.Key), + ) + if errs != nil { + return diag.FromErr(errs) } return nil } // UpdateAccountParameter implements schema.UpdateFunc. -func UpdateAccountParameter(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func UpdateAccountParameter(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { return CreateAccountParameter(ctx, d, meta) } // DeleteAccountParameter implements schema.DeleteFunc. -func DeleteAccountParameter(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func DeleteAccountParameter(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { client := meta.(*provider.Context).Client key := d.Get("key").(string) parameter := sdk.AccountParameter(key) - defaultParameter, err := client.Parameters.ShowAccountParameter(ctx, sdk.AccountParameter(key)) - if err != nil { - return diag.FromErr(err) - } - defaultValue := defaultParameter.Default - err = client.Parameters.SetAccountParameter(ctx, parameter, defaultValue) + + err := client.Parameters.UnsetAccountParameter(ctx, parameter) if err != nil { - return diag.FromErr(fmt.Errorf("error resetting account parameter err = %w", err)) + return diag.FromErr(fmt.Errorf("unsetting account parameter: %w", err)) } d.SetId("") diff --git a/pkg/resources/account_parameter_acceptance_test.go b/pkg/resources/account_parameter_acceptance_test.go index 8b269e8983..ab20439532 100644 --- a/pkg/resources/account_parameter_acceptance_test.go +++ b/pkg/resources/account_parameter_acceptance_test.go @@ -1,59 +1,55 @@ package resources_test import ( - "fmt" "testing" acc "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/assert" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/assert/resourceassert" + "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/sdk" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/tfversion" ) func TestAcc_AccountParameter(t *testing.T) { + model := model.AccountParameter("test", string(sdk.AccountParameterAllowIDToken), "true") 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.CheckAccountParameterUnset(t, sdk.AccountParameterAllowIDToken), Steps: []resource.TestStep{ { - Config: accountParameterBasic("ALLOW_ID_TOKEN", "true"), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("snowflake_account_parameter.p", "key", "ALLOW_ID_TOKEN"), - resource.TestCheckResourceAttr("snowflake_account_parameter.p", "value", "true"), + Config: config.FromModel(t, model), + Check: assert.AssertThat(t, resourceassert.AccountParameterResource(t, model.ResourceReference()). + HasKeyString(string(sdk.AccountParameterAllowIDToken)). + HasValueString("true"), ), }, }, }) } -func accountParameterBasic(key, value string) string { - s := ` -resource "snowflake_account_parameter" "p" { - key = "%s" - value = "%s" -} -` - return fmt.Sprintf(s, key, value) -} - func TestAcc_AccountParameter_PREVENT_LOAD_FROM_INLINE_URL(t *testing.T) { + model := model.AccountParameter("test", string(sdk.AccountParameterPreventLoadFromInlineURL), "true") 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.CheckAccountParameterUnset(t, sdk.AccountParameterPreventLoadFromInlineURL), Steps: []resource.TestStep{ { - Config: accountParameterBasic("PREVENT_LOAD_FROM_INLINE_URL", "true"), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("snowflake_account_parameter.p", "key", "PREVENT_LOAD_FROM_INLINE_URL"), - resource.TestCheckResourceAttr("snowflake_account_parameter.p", "value", "true"), + Config: config.FromModel(t, model), + Check: assert.AssertThat(t, resourceassert.AccountParameterResource(t, model.ResourceReference()). + HasKeyString(string(sdk.AccountParameterPreventLoadFromInlineURL)). + HasValueString("true"), ), }, }, @@ -61,45 +57,45 @@ func TestAcc_AccountParameter_PREVENT_LOAD_FROM_INLINE_URL(t *testing.T) { } func TestAcc_AccountParameter_REQUIRE_STORAGE_INTEGRATION_FOR_STAGE_CREATION(t *testing.T) { + model := model.AccountParameter("test", string(sdk.AccountParameterRequireStorageIntegrationForStageCreation), "true") 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.CheckAccountParameterUnset(t, sdk.AccountParameterRequireStorageIntegrationForStageCreation), Steps: []resource.TestStep{ { - Config: accountParameterBasic("REQUIRE_STORAGE_INTEGRATION_FOR_STAGE_CREATION", "true"), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("snowflake_account_parameter.p", "key", "REQUIRE_STORAGE_INTEGRATION_FOR_STAGE_CREATION"), - resource.TestCheckResourceAttr("snowflake_account_parameter.p", "value", "true"), + Config: config.FromModel(t, model), + Check: assert.AssertThat(t, resourceassert.AccountParameterResource(t, model.ResourceReference()). + HasKeyString(string(sdk.AccountParameterRequireStorageIntegrationForStageCreation)). + HasValueString("true"), ), }, }, }) } -// TODO [SNOW-1528546]: unskip func TestAcc_AccountParameter_Issue2573(t *testing.T) { - t.Skipf("The cleanup for parameter is currently incorrect and this test messes with other ones. Skipping until SNOW-1528546 is resolved.") + model := model.AccountParameter("test", string(sdk.AccountParameterTimezone), "Etc/UTC") 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.CheckAccountParameterUnset(t, sdk.AccountParameterTimezone), Steps: []resource.TestStep{ { - Config: accountParameterBasic("TIMEZONE", "Etc/UTC"), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("snowflake_account_parameter.p", "key", "TIMEZONE"), - resource.TestCheckResourceAttr("snowflake_account_parameter.p", "value", "Etc/UTC"), + Config: config.FromModel(t, model), + Check: assert.AssertThat(t, resourceassert.AccountParameterResource(t, model.ResourceReference()). + HasKeyString(string(sdk.AccountParameterTimezone)). + HasValueString("Etc/UTC"), ), }, { - ResourceName: "snowflake_account_parameter.p", + ResourceName: "snowflake_account_parameter.test", ImportState: true, ImportStateVerify: true, ImportStateVerifyIgnore: []string{}, @@ -109,24 +105,24 @@ func TestAcc_AccountParameter_Issue2573(t *testing.T) { } func TestAcc_AccountParameter_Issue3025(t *testing.T) { - t.Skipf("The cleanup for parameter is currently incorrect and this test messes with other ones. Skipping until SNOW-1528546 is resolved.") + model := model.AccountParameter("test", string(sdk.AccountParameterOAuthAddPrivilegedRolesToBlockedList), "true") 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.CheckAccountParameterUnset(t, sdk.AccountParameterOAuthAddPrivilegedRolesToBlockedList), Steps: []resource.TestStep{ { - Config: accountParameterBasic("OAUTH_ADD_PRIVILEGED_ROLES_TO_BLOCKED_LIST", "true"), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("snowflake_account_parameter.p", "key", "OAUTH_ADD_PRIVILEGED_ROLES_TO_BLOCKED_LIST"), - resource.TestCheckResourceAttr("snowflake_account_parameter.p", "value", "true"), + Config: config.FromModel(t, model), + Check: assert.AssertThat(t, resourceassert.AccountParameterResource(t, model.ResourceReference()). + HasKeyString(string(sdk.AccountParameterOAuthAddPrivilegedRolesToBlockedList)). + HasValueString("true"), ), }, { - ResourceName: "snowflake_account_parameter.p", + ResourceName: "snowflake_account_parameter.test", ImportState: true, ImportStateVerify: true, ImportStateVerifyIgnore: []string{}, @@ -134,3 +130,5 @@ func TestAcc_AccountParameter_Issue3025(t *testing.T) { }, }) } + +// TODO(next pr): add more acc tests for the remaining parameters diff --git a/pkg/sdk/parameters.go b/pkg/sdk/parameters.go index 44f73e9e55..377d46a5fd 100644 --- a/pkg/sdk/parameters.go +++ b/pkg/sdk/parameters.go @@ -5,6 +5,7 @@ import ( "database/sql" "errors" "fmt" + "slices" "strconv" "strings" ) @@ -22,6 +23,7 @@ var _ Parameters = (*parameters)(nil) type Parameters interface { SetAccountParameter(ctx context.Context, parameter AccountParameter, value string) error + UnsetAccountParameter(ctx context.Context, parameter AccountParameter) error SetSessionParameterOnAccount(ctx context.Context, parameter SessionParameter, value string) error SetSessionParameterOnUser(ctx context.Context, userID AccountObjectIdentifier, parameter SessionParameter, value string) error SetObjectParameterOnAccount(ctx context.Context, parameter ObjectParameter, value string) error @@ -174,6 +176,64 @@ func (parameters *parameters) SetAccountParameter(ctx context.Context, parameter return nil } +// TODO(next pr): add integration tests +func (parameters *parameters) UnsetAccountParameter(ctx context.Context, parameter AccountParameter) error { + opts := AlterAccountOptions{ + Unset: &AccountUnset{ + Parameters: &AccountLevelParametersUnset{ + AccountParameters: &AccountParametersUnset{}, + }, + }, + } + switch parameter { + case AccountParameterAllowClientMFACaching: + opts.Unset.Parameters.AccountParameters.AllowClientMFACaching = Pointer(true) + case AccountParameterAllowIDToken: + opts.Unset.Parameters.AccountParameters.AllowIDToken = Pointer(true) + case AccountParameterClientEncryptionKeySize: + opts.Unset.Parameters.AccountParameters.ClientEncryptionKeySize = Pointer(true) + case AccountParameterEnableIdentifierFirstLogin: + opts.Unset.Parameters.AccountParameters.EnableIdentifierFirstLogin = Pointer(true) + case AccountParameterEnableInternalStagesPrivatelink: + opts.Unset.Parameters.AccountParameters.EnableInternalStagesPrivatelink = Pointer(true) + case AccountParameterEnableTriSecretAndRekeyOptOutForImageRepository: + opts.Unset.Parameters.AccountParameters.EnableTriSecretAndRekeyOptOutForImageRepository = Pointer(true) + case AccountParameterEnableTriSecretAndRekeyOptOutForSpcsBlockStorage: + opts.Unset.Parameters.AccountParameters.EnableTriSecretAndRekeyOptOutForSpcsBlockStorage = Pointer(true) + case AccountParameterEnableUnredactedQuerySyntaxError: + opts.Unset.Parameters.AccountParameters.EnableUnredactedQuerySyntaxError = Pointer(true) + case AccountParameterEventTable: + opts.Unset.Parameters.AccountParameters.EventTable = Pointer(true) + case AccountParameterExternalOAuthAddPrivilegedRolesToBlockedList: + opts.Unset.Parameters.AccountParameters.ExternalOAuthAddPrivilegedRolesToBlockedList = Pointer(true) + case AccountParameterInitialReplicationSizeLimitInTB: + opts.Unset.Parameters.AccountParameters.InitialReplicationSizeLimitInTB = Pointer(true) + case AccountParameterMinDataRetentionTimeInDays: + opts.Unset.Parameters.AccountParameters.MinDataRetentionTimeInDays = Pointer(true) + case AccountParameterNetworkPolicy: + opts.Unset.Parameters.AccountParameters.NetworkPolicy = Pointer(true) + case AccountParameterOAuthAddPrivilegedRolesToBlockedList: + opts.Unset.Parameters.AccountParameters.OAuthAddPrivilegedRolesToBlockedList = Pointer(true) + case AccountParameterPeriodicDataRekeying: + opts.Unset.Parameters.AccountParameters.PeriodicDataRekeying = Pointer(true) + case AccountParameterPreventLoadFromInlineURL: + opts.Unset.Parameters.AccountParameters.PreventLoadFromInlineURL = Pointer(true) + case AccountParameterPreventUnloadToInlineURL: + opts.Unset.Parameters.AccountParameters.PreventUnloadToInlineURL = Pointer(true) + case AccountParameterPreventUnloadToInternalStages: + opts.Unset.Parameters.AccountParameters.PreventUnloadToInternalStages = Pointer(true) + case AccountParameterRequireStorageIntegrationForStageCreation: + opts.Unset.Parameters.AccountParameters.RequireStorageIntegrationForStageCreation = Pointer(true) + case AccountParameterRequireStorageIntegrationForStageOperation: + opts.Unset.Parameters.AccountParameters.RequireStorageIntegrationForStageOperation = Pointer(true) + case AccountParameterSSOLoginPage: + opts.Unset.Parameters.AccountParameters.SSOLoginPage = Pointer(true) + default: + return parameters.UnsetSessionParameterOnAccount(ctx, SessionParameter(parameter)) + } + return parameters.client.Accounts.Alter(ctx, &opts) +} + func (parameters *parameters) SetSessionParameterOnAccount(ctx context.Context, parameter SessionParameter, value string) error { sp := &SessionParameters{} err := sp.setParam(parameter, value) @@ -192,6 +252,24 @@ func (parameters *parameters) SetSessionParameterOnAccount(ctx context.Context, } } +func (parameters *parameters) UnsetSessionParameterOnAccount(ctx context.Context, parameter SessionParameter) error { + sp := &SessionParametersUnset{} + err := sp.setParam(parameter) + if err == nil { + opts := AlterAccountOptions{Unset: &AccountUnset{Parameters: &AccountLevelParametersUnset{SessionParameters: sp}}} + err = parameters.client.Accounts.Alter(ctx, &opts) + if err != nil { + return err + } + return nil + } else { + if strings.Contains(err.Error(), "session parameter is not supported") { + return parameters.UnsetObjectParameterOnAccount(ctx, ObjectParameter(parameter)) + } + return err + } +} + func (parameters *parameters) SetSessionParameterOnUser(ctx context.Context, userId AccountObjectIdentifier, parameter SessionParameter, value string) error { sp := &SessionParameters{} err := sp.setParam(parameter, value) @@ -297,6 +375,49 @@ func (parameters *parameters) SetObjectParameterOnAccount(ctx context.Context, p return nil } +func (parameters *parameters) UnsetObjectParameterOnAccount(ctx context.Context, parameter ObjectParameter) error { + opts := AlterAccountOptions{Unset: &AccountUnset{Parameters: &AccountLevelParametersUnset{ObjectParameters: &ObjectParametersUnset{}}}} + switch parameter { + case ObjectParameterCatalog: + opts.Unset.Parameters.ObjectParameters.Catalog = Pointer(true) + case ObjectParameterDataRetentionTimeInDays: + opts.Unset.Parameters.ObjectParameters.DataRetentionTimeInDays = Pointer(true) + case ObjectParameterDefaultDDLCollation: + opts.Unset.Parameters.ObjectParameters.DefaultDDLCollation = Pointer(true) + case ObjectParameterLogLevel: + opts.Unset.Parameters.ObjectParameters.LogLevel = Pointer(true) + case ObjectParameterMaxConcurrencyLevel: + opts.Unset.Parameters.ObjectParameters.MaxConcurrencyLevel = Pointer(true) + case ObjectParameterMaxDataExtensionTimeInDays: + opts.Unset.Parameters.ObjectParameters.MaxDataExtensionTimeInDays = Pointer(true) + case ObjectParameterPipeExecutionPaused: + opts.Unset.Parameters.ObjectParameters.PipeExecutionPaused = Pointer(true) + case ObjectParameterPreventUnloadToInternalStages: + opts.Unset.Parameters.ObjectParameters.PreventUnloadToInternalStages = Pointer(true) + case ObjectParameterStatementQueuedTimeoutInSeconds: + opts.Unset.Parameters.ObjectParameters.StatementQueuedTimeoutInSeconds = Pointer(true) + case ObjectParameterStatementTimeoutInSeconds: + opts.Unset.Parameters.ObjectParameters.StatementTimeoutInSeconds = Pointer(true) + case ObjectParameterNetworkPolicy: + opts.Unset.Parameters.ObjectParameters.NetworkPolicy = Pointer(true) + case ObjectParameterShareRestrictions: + opts.Unset.Parameters.ObjectParameters.ShareRestrictions = Pointer(true) + case ObjectParameterSuspendTaskAfterNumFailures: + opts.Unset.Parameters.ObjectParameters.SuspendTaskAfterNumFailures = Pointer(true) + case ObjectParameterTraceLevel: + opts.Unset.Parameters.ObjectParameters.TraceLevel = Pointer(true) + case ObjectParameterUserTaskManagedInitialWarehouseSize: + opts.Unset.Parameters.ObjectParameters.UserTaskManagedInitialWarehouseSize = Pointer(true) + case ObjectParameterUserTaskTimeoutMs: + opts.Unset.Parameters.ObjectParameters.UserTaskTimeoutMs = Pointer(true) + case ObjectParameterEnableUnredactedQuerySyntaxError: + opts.Unset.Parameters.ObjectParameters.EnableUnredactedQuerySyntaxError = Pointer(true) + default: + return fmt.Errorf("invalid object parameter: %v", string(parameter)) + } + return parameters.client.Accounts.Alter(ctx, &opts) +} + type setParameterOnObject struct { alter bool `ddl:"static" sql:"ALTER"` objectType ObjectType `ddl:"keyword"` @@ -344,6 +465,7 @@ type AccountParameter string // https://docs.snowflake.com/en/sql-reference/parameters#parameter-hierarchy-and-types // Account Parameters include Session Parameters, Object Parameters and User Parameters const ( + // TODO(next pr): add remaining parameters; also in parameters_impl.go // Account Parameters AccountParameterAllowClientMFACaching AccountParameter = "ALLOW_CLIENT_MFA_CACHING" AccountParameterAllowIDToken AccountParameter = "ALLOW_ID_TOKEN" // #nosec G101 @@ -367,45 +489,59 @@ const ( AccountParameterSSOLoginPage AccountParameter = "SSO_LOGIN_PAGE" // Session Parameters (inherited) - AccountParameterAbortDetachedQuery AccountParameter = "ABORT_DETACHED_QUERY" - AccountParameterAutocommit AccountParameter = "AUTOCOMMIT" - AccountParameterBinaryInputFormat AccountParameter = "BINARY_INPUT_FORMAT" - AccountParameterBinaryOutputFormat AccountParameter = "BINARY_OUTPUT_FORMAT" - AccountParameterClientMetadataRequestUseConnectionCtx AccountParameter = "CLIENT_METADATA_REQUEST_USE_CONNECTION_CTX" - AccountParameterClientMetadataUseSessionDatabase AccountParameter = "CLIENT_METADATA_USE_SESSION_DATABASE" - AccountParameterClientResultColumnCaseInsensitive AccountParameter = "CLIENT_RESULT_COLUMN_CASE_INSENSITIVE" - AccountParameterDateInputFormat AccountParameter = "DATE_INPUT_FORMAT" - AccountParameterGeographyOutputFormat AccountParameter = "GEOGRAPHY_OUTPUT_FORMAT" - AccountParameterDateOutputFormat AccountParameter = "DATE_OUTPUT_FORMAT" - AccountParameterErrorOnNondeterministicMerge AccountParameter = "ERROR_ON_NONDETERMINISTIC_MERGE" - AccountParameterErrorOnNondeterministicUpdate AccountParameter = "ERROR_ON_NONDETERMINISTIC_UPDATE" - AccountParameterJSONIndent AccountParameter = "JSON_INDENT" - AccountParameterLockTimeout AccountParameter = "LOCK_TIMEOUT" - AccountParameterMultiStatementCount AccountParameter = "MULTI_STATEMENT_COUNT" - AccountParameterQueryTag AccountParameter = "QUERY_TAG" - AccountParameterQuotedIdentifiersIgnoreCase AccountParameter = "QUOTED_IDENTIFIERS_IGNORE_CASE" - AccountParameterRowsPerResultset AccountParameter = "ROWS_PER_RESULTSET" - AccountParameterS3StageVpceDnsName AccountParameter = "S3_STAGE_VPCE_DNS_NAME" - AccountParameterSimulatedDataSharingConsumer AccountParameter = "SIMULATED_DATA_SHARING_CONSUMER" - AccountParameterStatementTimeoutInSeconds AccountParameter = "STATEMENT_TIMEOUT_IN_SECONDS" - AccountParameterStrictJSONOutput AccountParameter = "STRICT_JSON_OUTPUT" - AccountParameterTimeInputFormat AccountParameter = "TIME_INPUT_FORMAT" - AccountParameterTimeOutputFormat AccountParameter = "TIME_OUTPUT_FORMAT" - AccountParameterTimestampDayIsAlways24h AccountParameter = "TIMESTAMP_DAY_IS_ALWAYS_24H" - AccountParameterTimestampInputFormat AccountParameter = "TIMESTAMP_INPUT_FORMAT" - AccountParameterTimestampLtzOutputFormat AccountParameter = "TIMESTAMP_LTZ_OUTPUT_FORMAT" - AccountParameterTimestampNtzOutputFormat AccountParameter = "TIMESTAMP_NTZ_OUTPUT_FORMAT" - AccountParameterTimestampOutputFormat AccountParameter = "TIMESTAMP_OUTPUT_FORMAT" - AccountParameterTimestampTypeMapping AccountParameter = "TIMESTAMP_TYPE_MAPPING" - AccountParameterTimestampTzOutputFormat AccountParameter = "TIMESTAMP_TZ_OUTPUT_FORMAT" - AccountParameterTimezone AccountParameter = "TIMEZONE" - AccountParameterTransactionAbortOnError AccountParameter = "TRANSACTION_ABORT_ON_ERROR" - AccountParameterTransactionDefaultIsolationLevel AccountParameter = "TRANSACTION_DEFAULT_ISOLATION_LEVEL" - AccountParameterTwoDigitCenturyStart AccountParameter = "TWO_DIGIT_CENTURY_START" - AccountParameterUnsupportedDdlAction AccountParameter = "UNSUPPORTED_DDL_ACTION" - AccountParameterUseCachedResult AccountParameter = "USE_CACHED_RESULT" - AccountParameterWeekOfYearPolicy AccountParameter = "WEEK_OF_YEAR_POLICY" - AccountParameterWeekStart AccountParameter = "WEEK_START" + AccountParameterAbortDetachedQuery AccountParameter = "ABORT_DETACHED_QUERY" + AccountParameterAutocommit AccountParameter = "AUTOCOMMIT" + AccountParameterBinaryInputFormat AccountParameter = "BINARY_INPUT_FORMAT" + AccountParameterBinaryOutputFormat AccountParameter = "BINARY_OUTPUT_FORMAT" + AccountParameterClientMemoryLimit AccountParameter = "CLIENT_MEMORY_LIMIT" + AccountParameterClientMetadataRequestUseConnectionCtx AccountParameter = "CLIENT_METADATA_REQUEST_USE_CONNECTION_CTX" + AccountParameterClientMetadataUseSessionDatabase AccountParameter = "CLIENT_METADATA_USE_SESSION_DATABASE" + AccountParameterClientPrefetchThreads AccountParameter = "CLIENT_PREFETCH_THREADS" + AccountParameterClientResultChunkSize AccountParameter = "CLIENT_RESULT_CHUNK_SIZE" + AccountParameterClientResultColumnCaseInsensitive AccountParameter = "CLIENT_RESULT_COLUMN_CASE_INSENSITIVE" + AccountParameterClientSessionKeepAlive AccountParameter = "CLIENT_SESSION_KEEP_ALIVE" + AccountParameterClientSessionKeepAliveHeartbeatFrequency AccountParameter = "CLIENT_SESSION_KEEP_ALIVE_HEARTBEAT_FREQUENCY" + AccountParameterClientTimestampTypeMapping AccountParameter = "CLIENT_TIMESTAMP_TYPE_MAPPING" + AccountParameterDateInputFormat AccountParameter = "DATE_INPUT_FORMAT" + AccountParameterDateOutputFormat AccountParameter = "DATE_OUTPUT_FORMAT" + AccountParameterEnableUnloadPhysicalTypeOptimization AccountParameter = "ENABLE_UNLOAD_PHYSICAL_TYPE_OPTIMIZATION" + AccountParameterErrorOnNondeterministicMerge AccountParameter = "ERROR_ON_NONDETERMINISTIC_MERGE" + AccountParameterErrorOnNondeterministicUpdate AccountParameter = "ERROR_ON_NONDETERMINISTIC_UPDATE" + AccountParameterGeographyOutputFormat AccountParameter = "GEOGRAPHY_OUTPUT_FORMAT" + AccountParameterGeometryOutputFormat AccountParameter = "GEOMETRY_OUTPUT_FORMAT" + AccountParameterJdbcTreatDecimalAsInt AccountParameter = "JDBC_TREAT_DECIMAL_AS_INT" + AccountParameterJdbcTreatTimestampNtzAsUtc AccountParameter = "JDBC_TREAT_TIMESTAMP_NTZ_AS_UTC" + AccountParameterJdbcUseSessionTimezone AccountParameter = "JDBC_USE_SESSION_TIMEZONE" + AccountParameterJSONIndent AccountParameter = "JSON_INDENT" + AccountParameterLockTimeout AccountParameter = "LOCK_TIMEOUT" + AccountParameterMultiStatementCount AccountParameter = "MULTI_STATEMENT_COUNT" + AccountParameterNoorderSequenceAsDefault AccountParameter = "NOORDER_SEQUENCE_AS_DEFAULT" + AccountParameterOdbcTreatDecimalAsInt AccountParameter = "ODBC_TREAT_DECIMAL_AS_INT" + AccountParameterQueryTag AccountParameter = "QUERY_TAG" + AccountParameterQuotedIdentifiersIgnoreCase AccountParameter = "QUOTED_IDENTIFIERS_IGNORE_CASE" + AccountParameterRowsPerResultset AccountParameter = "ROWS_PER_RESULTSET" + AccountParameterS3StageVpceDnsName AccountParameter = "S3_STAGE_VPCE_DNS_NAME" + AccountParameterSearchPath AccountParameter = "SEARCH_PATH" + AccountParameterSimulatedDataSharingConsumer AccountParameter = "SIMULATED_DATA_SHARING_CONSUMER" + AccountParameterStatementTimeoutInSeconds AccountParameter = "STATEMENT_TIMEOUT_IN_SECONDS" + AccountParameterStrictJSONOutput AccountParameter = "STRICT_JSON_OUTPUT" + AccountParameterTimeInputFormat AccountParameter = "TIME_INPUT_FORMAT" + AccountParameterTimeOutputFormat AccountParameter = "TIME_OUTPUT_FORMAT" + AccountParameterTimestampDayIsAlways24h AccountParameter = "TIMESTAMP_DAY_IS_ALWAYS_24H" + AccountParameterTimestampInputFormat AccountParameter = "TIMESTAMP_INPUT_FORMAT" + AccountParameterTimestampLtzOutputFormat AccountParameter = "TIMESTAMP_LTZ_OUTPUT_FORMAT" + AccountParameterTimestampNtzOutputFormat AccountParameter = "TIMESTAMP_NTZ_OUTPUT_FORMAT" + AccountParameterTimestampOutputFormat AccountParameter = "TIMESTAMP_OUTPUT_FORMAT" + AccountParameterTimestampTypeMapping AccountParameter = "TIMESTAMP_TYPE_MAPPING" + AccountParameterTimestampTzOutputFormat AccountParameter = "TIMESTAMP_TZ_OUTPUT_FORMAT" + AccountParameterTimezone AccountParameter = "TIMEZONE" + AccountParameterTransactionAbortOnError AccountParameter = "TRANSACTION_ABORT_ON_ERROR" + AccountParameterTransactionDefaultIsolationLevel AccountParameter = "TRANSACTION_DEFAULT_ISOLATION_LEVEL" + AccountParameterTwoDigitCenturyStart AccountParameter = "TWO_DIGIT_CENTURY_START" + AccountParameterUnsupportedDdlAction AccountParameter = "UNSUPPORTED_DDL_ACTION" + AccountParameterUseCachedResult AccountParameter = "USE_CACHED_RESULT" + AccountParameterWeekOfYearPolicy AccountParameter = "WEEK_OF_YEAR_POLICY" + AccountParameterWeekStart AccountParameter = "WEEK_START" // Object Parameters (inherited) AccountParameterCatalog AccountParameter = "CATALOG" @@ -433,6 +569,112 @@ const ( AccountParameterEnableUnredactedQuerySyntaxError AccountParameter = "ENABLE_UNREDACTED_QUERY_SYNTAX_ERROR" ) +var AllAccountParameters = []AccountParameter{ + AccountParameterAllowClientMFACaching, + AccountParameterAllowIDToken, + AccountParameterClientEncryptionKeySize, + AccountParameterEnableIdentifierFirstLogin, + AccountParameterEnableInternalStagesPrivatelink, + AccountParameterEnableTriSecretAndRekeyOptOutForImageRepository, + AccountParameterEnableTriSecretAndRekeyOptOutForSpcsBlockStorage, + AccountParameterEventTable, + AccountParameterExternalOAuthAddPrivilegedRolesToBlockedList, + AccountParameterInitialReplicationSizeLimitInTB, + AccountParameterMinDataRetentionTimeInDays, + AccountParameterNetworkPolicy, + AccountParameterOAuthAddPrivilegedRolesToBlockedList, + AccountParameterPeriodicDataRekeying, + AccountParameterPreventLoadFromInlineURL, + AccountParameterPreventUnloadToInlineURL, + AccountParameterPreventUnloadToInternalStages, + AccountParameterRequireStorageIntegrationForStageCreation, + AccountParameterRequireStorageIntegrationForStageOperation, + AccountParameterSSOLoginPage, + AccountParameterAbortDetachedQuery, + AccountParameterAutocommit, + AccountParameterBinaryInputFormat, + AccountParameterBinaryOutputFormat, + AccountParameterClientMemoryLimit, + AccountParameterClientMetadataRequestUseConnectionCtx, + AccountParameterClientMetadataUseSessionDatabase, + AccountParameterClientPrefetchThreads, + AccountParameterClientResultChunkSize, + AccountParameterClientSessionKeepAlive, + AccountParameterClientSessionKeepAliveHeartbeatFrequency, + AccountParameterClientTimestampTypeMapping, + AccountParameterEnableUnloadPhysicalTypeOptimization, + AccountParameterClientResultColumnCaseInsensitive, + AccountParameterDateInputFormat, + AccountParameterDateOutputFormat, + AccountParameterErrorOnNondeterministicMerge, + AccountParameterErrorOnNondeterministicUpdate, + AccountParameterGeographyOutputFormat, + AccountParameterGeometryOutputFormat, + AccountParameterJdbcTreatDecimalAsInt, + AccountParameterJdbcTreatTimestampNtzAsUtc, + AccountParameterJdbcUseSessionTimezone, + AccountParameterJSONIndent, + AccountParameterLockTimeout, + AccountParameterMultiStatementCount, + AccountParameterNoorderSequenceAsDefault, + AccountParameterOdbcTreatDecimalAsInt, + AccountParameterQueryTag, + AccountParameterQuotedIdentifiersIgnoreCase, + AccountParameterRowsPerResultset, + AccountParameterS3StageVpceDnsName, + AccountParameterSearchPath, + AccountParameterSimulatedDataSharingConsumer, + AccountParameterStatementTimeoutInSeconds, + AccountParameterStrictJSONOutput, + AccountParameterTimeInputFormat, + AccountParameterTimeOutputFormat, + AccountParameterTimestampDayIsAlways24h, + AccountParameterTimestampInputFormat, + AccountParameterTimestampLtzOutputFormat, + AccountParameterTimestampNtzOutputFormat, + AccountParameterTimestampOutputFormat, + AccountParameterTimestampTypeMapping, + AccountParameterTimestampTzOutputFormat, + AccountParameterTimezone, + AccountParameterTransactionAbortOnError, + AccountParameterTransactionDefaultIsolationLevel, + AccountParameterTwoDigitCenturyStart, + AccountParameterUnsupportedDdlAction, + AccountParameterUseCachedResult, + AccountParameterWeekOfYearPolicy, + AccountParameterWeekStart, + AccountParameterCatalog, + AccountParameterDataRetentionTimeInDays, + AccountParameterDefaultDDLCollation, + AccountParameterExternalVolume, + AccountParameterLogLevel, + AccountParameterMaxConcurrencyLevel, + AccountParameterMaxDataExtensionTimeInDays, + AccountParameterPipeExecutionPaused, + AccountParameterPreventUnloadToInternalStages, + AccountParameterReplaceInvalidCharacters, + AccountParameterStatementQueuedTimeoutInSeconds, + AccountParameterStorageSerializationPolicy, + AccountParameterShareRestrictions, + AccountParameterSuspendTaskAfterNumFailures, + AccountParameterTraceLevel, + AccountParameterUserTaskManagedInitialWarehouseSize, + AccountParameterUserTaskTimeoutMs, + AccountParameterTaskAutoRetryAttempts, + AccountParameterUserTaskMinimumTriggerIntervalInSeconds, + AccountParameterMetricLevel, + AccountParameterEnableConsoleOutput, + AccountParameterEnableUnredactedQuerySyntaxError, +} + +func ToAccountParameter(s string) (AccountParameter, error) { + s = strings.ToUpper(s) + if !slices.Contains(AllAccountParameters, AccountParameter(s)) { + return "", fmt.Errorf("invalid account parameter: %s", s) + } + return AccountParameter(s), nil +} + type SessionParameter string const ( @@ -922,11 +1164,14 @@ type AccountParametersUnset struct { EnableTriSecretAndRekeyOptOutForImageRepository *bool `ddl:"keyword" sql:"ENABLE_TRI_SECRET_AND_REKEY_OPT_OUT_FOR_IMAGE_REPOSITORY"` EnableTriSecretAndRekeyOptOutForSpcsBlockStorage *bool `ddl:"keyword" sql:"ENABLE_TRI_SECRET_AND_REKEY_OPT_OUT_FOR_SPCS_BLOCK_STORAGE"` EventTable *bool `ddl:"keyword" sql:"EVENT_TABLE"` + EnableUnredactedQuerySyntaxError *bool `ddl:"keyword" sql:"ENABLE_UNREDACTED_QUERY_SYNTAX_ERROR"` ExternalOAuthAddPrivilegedRolesToBlockedList *bool `ddl:"keyword" sql:"EXTERNAL_OAUTH_ADD_PRIVILEGED_ROLES_TO_BLOCKED_LIST"` InitialReplicationSizeLimitInTB *bool `ddl:"keyword" sql:"INITIAL_REPLICATION_SIZE_LIMIT_IN_TB"` MinDataRetentionTimeInDays *bool `ddl:"keyword" sql:"MIN_DATA_RETENTION_TIME_IN_DAYS"` NetworkPolicy *bool `ddl:"keyword" sql:"NETWORK_POLICY"` + OAuthAddPrivilegedRolesToBlockedList *bool `ddl:"keyword" sql:"OAUTH_ADD_PRIVILEGED_ROLES_TO_BLOCKED_LIST"` PeriodicDataRekeying *bool `ddl:"keyword" sql:"PERIODIC_DATA_REKEYING"` + PreventLoadFromInlineURL *bool `ddl:"keyword" sql:"PREVENT_LOAD_FROM_INLINE_URL"` PreventUnloadToInlineURL *bool `ddl:"keyword" sql:"PREVENT_UNLOAD_TO_INLINE_URL"` PreventUnloadToInternalStages *bool `ddl:"keyword" sql:"PREVENT_UNLOAD_TO_INTERNAL_STAGES"` RequireStorageIntegrationForStageCreation *bool `ddl:"keyword" sql:"REQUIRE_STORAGE_INTEGRATION_FOR_STAGE_CREATION"` @@ -1267,6 +1512,7 @@ func (v *SessionParametersUnset) validate() error { // ObjectParameters is based on https://docs.snowflake.com/en/sql-reference/parameters#object-parameters. type ObjectParameters struct { + Catalog *string `ddl:"parameter" sql:"CATALOG"` DataRetentionTimeInDays *int `ddl:"parameter" sql:"DATA_RETENTION_TIME_IN_DAYS"` DefaultDDLCollation *string `ddl:"parameter,single_quotes" sql:"DEFAULT_DDL_COLLATION"` EnableUnredactedQuerySyntaxError *bool `ddl:"parameter" sql:"ENABLE_UNREDACTED_QUERY_SYNTAX_ERROR"` @@ -1283,7 +1529,6 @@ type ObjectParameters struct { TraceLevel *TraceLevel `ddl:"parameter" sql:"TRACE_LEVEL"` UserTaskManagedInitialWarehouseSize *WarehouseSize `ddl:"parameter" sql:"USER_TASK_MANAGED_INITIAL_WAREHOUSE_SIZE"` UserTaskTimeoutMs *int `ddl:"parameter" sql:"USER_TASK_TIMEOUT_MS"` - Catalog *string `ddl:"parameter" sql:"CATALOG"` } func (v *ObjectParameters) validate() error { @@ -1327,8 +1572,10 @@ func (v *ObjectParameters) validate() error { } type ObjectParametersUnset struct { + Catalog *bool `ddl:"keyword" sql:"CATALOG"` DataRetentionTimeInDays *bool `ddl:"keyword" sql:"DATA_RETENTION_TIME_IN_DAYS"` DefaultDDLCollation *bool `ddl:"keyword" sql:"DEFAULT_DDL_COLLATION"` + EnableUnredactedQuerySyntaxError *bool `ddl:"keyword" sql:"ENABLE_UNREDACTED_QUERY_SYNTAX_ERROR"` LogLevel *bool `ddl:"keyword" sql:"LOG_LEVEL"` MaxConcurrencyLevel *bool `ddl:"keyword" sql:"MAX_CONCURRENCY_LEVEL"` MaxDataExtensionTimeInDays *bool `ddl:"keyword" sql:"MAX_DATA_EXTENSION_TIME_IN_DAYS"` diff --git a/pkg/sdk/parameters_impl.go b/pkg/sdk/parameters_impl.go index 098e9e1d03..d01af6d161 100644 --- a/pkg/sdk/parameters_impl.go +++ b/pkg/sdk/parameters_impl.go @@ -187,14 +187,14 @@ func (sessionParametersUnset *SessionParametersUnset) setParam(parameter Session unsetField = &sessionParametersUnset.ClientMemoryLimit case SessionParameterClientMetadataRequestUseConnectionCtx: unsetField = &sessionParametersUnset.ClientMetadataRequestUseConnectionCtx + case SessionParameterClientMetadataUseSessionDatabase: + unsetField = &sessionParametersUnset.ClientMetadataUseSessionDatabase + case SessionParameterClientResultColumnCaseInsensitive: + unsetField = &sessionParametersUnset.ClientResultColumnCaseInsensitive case SessionParameterClientPrefetchThreads: unsetField = &sessionParametersUnset.ClientPrefetchThreads case SessionParameterClientResultChunkSize: unsetField = &sessionParametersUnset.ClientResultChunkSize - case SessionParameterClientResultColumnCaseInsensitive: - unsetField = &sessionParametersUnset.ClientResultColumnCaseInsensitive - case SessionParameterClientMetadataUseSessionDatabase: - unsetField = &sessionParametersUnset.ClientMetadataUseSessionDatabase case SessionParameterClientSessionKeepAlive: unsetField = &sessionParametersUnset.ClientSessionKeepAlive case SessionParameterClientSessionKeepAliveHeartbeatFrequency: diff --git a/pkg/sdk/parameters_test.go b/pkg/sdk/parameters_test.go index f7f1a88233..a288f9eee5 100644 --- a/pkg/sdk/parameters_test.go +++ b/pkg/sdk/parameters_test.go @@ -2,6 +2,8 @@ package sdk import ( "testing" + + "github.com/stretchr/testify/require" ) // TODO: add more tests @@ -51,3 +53,117 @@ func TestUnSetObjectParameterNetworkPolicyOnUser(t *testing.T) { assertOptsValidAndSQLEquals(t, opts, `ALTER USER "TEST_USER" UNSET NETWORK_POLICY`) }) } + +func TestToAccountParameter(t *testing.T) { + type test struct { + input string + want AccountParameter + } + + valid := []test{ + // Case insensitive. + {input: "allow_client_mfa_caching", want: AccountParameterAllowClientMFACaching}, + + // Supported Values. + {input: "ALLOW_CLIENT_MFA_CACHING", want: AccountParameterAllowClientMFACaching}, + {input: "ALLOW_ID_TOKEN", want: AccountParameterAllowIDToken}, + {input: "CLIENT_ENCRYPTION_KEY_SIZE", want: AccountParameterClientEncryptionKeySize}, + {input: "ENABLE_IDENTIFIER_FIRST_LOGIN", want: AccountParameterEnableIdentifierFirstLogin}, + {input: "ENABLE_INTERNAL_STAGES_PRIVATELINK", want: AccountParameterEnableInternalStagesPrivatelink}, + {input: "ENABLE_TRI_SECRET_AND_REKEY_OPT_OUT_FOR_IMAGE_REPOSITORY", want: AccountParameterEnableTriSecretAndRekeyOptOutForImageRepository}, + {input: "ENABLE_TRI_SECRET_AND_REKEY_OPT_OUT_FOR_SPCS_BLOCK_STORAGE", want: AccountParameterEnableTriSecretAndRekeyOptOutForSpcsBlockStorage}, + {input: "EVENT_TABLE", want: AccountParameterEventTable}, + {input: "EXTERNAL_OAUTH_ADD_PRIVILEGED_ROLES_TO_BLOCKED_LIST", want: AccountParameterExternalOAuthAddPrivilegedRolesToBlockedList}, + {input: "INITIAL_REPLICATION_SIZE_LIMIT_IN_TB", want: AccountParameterInitialReplicationSizeLimitInTB}, + {input: "MIN_DATA_RETENTION_TIME_IN_DAYS", want: AccountParameterMinDataRetentionTimeInDays}, + {input: "NETWORK_POLICY", want: AccountParameterNetworkPolicy}, + {input: "OAUTH_ADD_PRIVILEGED_ROLES_TO_BLOCKED_LIST", want: AccountParameterOAuthAddPrivilegedRolesToBlockedList}, + {input: "PERIODIC_DATA_REKEYING", want: AccountParameterPeriodicDataRekeying}, + {input: "PREVENT_LOAD_FROM_INLINE_URL", want: AccountParameterPreventLoadFromInlineURL}, + {input: "PREVENT_UNLOAD_TO_INLINE_URL", want: AccountParameterPreventUnloadToInlineURL}, + {input: "PREVENT_UNLOAD_TO_INTERNAL_STAGES", want: AccountParameterPreventUnloadToInternalStages}, + {input: "REQUIRE_STORAGE_INTEGRATION_FOR_STAGE_CREATION", want: AccountParameterRequireStorageIntegrationForStageCreation}, + {input: "REQUIRE_STORAGE_INTEGRATION_FOR_STAGE_OPERATION", want: AccountParameterRequireStorageIntegrationForStageOperation}, + {input: "SSO_LOGIN_PAGE", want: AccountParameterSSOLoginPage}, + {input: "ABORT_DETACHED_QUERY", want: AccountParameterAbortDetachedQuery}, + {input: "AUTOCOMMIT", want: AccountParameterAutocommit}, + {input: "BINARY_INPUT_FORMAT", want: AccountParameterBinaryInputFormat}, + {input: "BINARY_OUTPUT_FORMAT", want: AccountParameterBinaryOutputFormat}, + {input: "CLIENT_METADATA_REQUEST_USE_CONNECTION_CTX", want: AccountParameterClientMetadataRequestUseConnectionCtx}, + {input: "CLIENT_METADATA_USE_SESSION_DATABASE", want: AccountParameterClientMetadataUseSessionDatabase}, + {input: "CLIENT_RESULT_COLUMN_CASE_INSENSITIVE", want: AccountParameterClientResultColumnCaseInsensitive}, + {input: "DATE_INPUT_FORMAT", want: AccountParameterDateInputFormat}, + {input: "DATE_OUTPUT_FORMAT", want: AccountParameterDateOutputFormat}, + {input: "ERROR_ON_NONDETERMINISTIC_MERGE", want: AccountParameterErrorOnNondeterministicMerge}, + {input: "ERROR_ON_NONDETERMINISTIC_UPDATE", want: AccountParameterErrorOnNondeterministicUpdate}, + {input: "GEOGRAPHY_OUTPUT_FORMAT", want: AccountParameterGeographyOutputFormat}, + {input: "JSON_INDENT", want: AccountParameterJSONIndent}, + {input: "LOCK_TIMEOUT", want: AccountParameterLockTimeout}, + {input: "MULTI_STATEMENT_COUNT", want: AccountParameterMultiStatementCount}, + {input: "QUERY_TAG", want: AccountParameterQueryTag}, + {input: "QUOTED_IDENTIFIERS_IGNORE_CASE", want: AccountParameterQuotedIdentifiersIgnoreCase}, + {input: "ROWS_PER_RESULTSET", want: AccountParameterRowsPerResultset}, + {input: "S3_STAGE_VPCE_DNS_NAME", want: AccountParameterS3StageVpceDnsName}, + {input: "SIMULATED_DATA_SHARING_CONSUMER", want: AccountParameterSimulatedDataSharingConsumer}, + {input: "STATEMENT_TIMEOUT_IN_SECONDS", want: AccountParameterStatementTimeoutInSeconds}, + {input: "STRICT_JSON_OUTPUT", want: AccountParameterStrictJSONOutput}, + {input: "TIME_INPUT_FORMAT", want: AccountParameterTimeInputFormat}, + {input: "TIME_OUTPUT_FORMAT", want: AccountParameterTimeOutputFormat}, + {input: "TIMESTAMP_DAY_IS_ALWAYS_24H", want: AccountParameterTimestampDayIsAlways24h}, + {input: "TIMESTAMP_INPUT_FORMAT", want: AccountParameterTimestampInputFormat}, + {input: "TIMESTAMP_LTZ_OUTPUT_FORMAT", want: AccountParameterTimestampLtzOutputFormat}, + {input: "TIMESTAMP_NTZ_OUTPUT_FORMAT", want: AccountParameterTimestampNtzOutputFormat}, + {input: "TIMESTAMP_OUTPUT_FORMAT", want: AccountParameterTimestampOutputFormat}, + {input: "TIMESTAMP_TYPE_MAPPING", want: AccountParameterTimestampTypeMapping}, + {input: "TIMESTAMP_TZ_OUTPUT_FORMAT", want: AccountParameterTimestampTzOutputFormat}, + {input: "TIMEZONE", want: AccountParameterTimezone}, + {input: "TRANSACTION_ABORT_ON_ERROR", want: AccountParameterTransactionAbortOnError}, + {input: "TRANSACTION_DEFAULT_ISOLATION_LEVEL", want: AccountParameterTransactionDefaultIsolationLevel}, + {input: "TWO_DIGIT_CENTURY_START", want: AccountParameterTwoDigitCenturyStart}, + {input: "UNSUPPORTED_DDL_ACTION", want: AccountParameterUnsupportedDdlAction}, + {input: "USE_CACHED_RESULT", want: AccountParameterUseCachedResult}, + {input: "WEEK_OF_YEAR_POLICY", want: AccountParameterWeekOfYearPolicy}, + {input: "WEEK_START", want: AccountParameterWeekStart}, + {input: "CATALOG", want: AccountParameterCatalog}, + {input: "DATA_RETENTION_TIME_IN_DAYS", want: AccountParameterDataRetentionTimeInDays}, + {input: "DEFAULT_DDL_COLLATION", want: AccountParameterDefaultDDLCollation}, + {input: "EXTERNAL_VOLUME", want: AccountParameterExternalVolume}, + {input: "LOG_LEVEL", want: AccountParameterLogLevel}, + {input: "MAX_CONCURRENCY_LEVEL", want: AccountParameterMaxConcurrencyLevel}, + {input: "MAX_DATA_EXTENSION_TIME_IN_DAYS", want: AccountParameterMaxDataExtensionTimeInDays}, + {input: "PIPE_EXECUTION_PAUSED", want: AccountParameterPipeExecutionPaused}, + {input: "REPLACE_INVALID_CHARACTERS", want: AccountParameterReplaceInvalidCharacters}, + {input: "STATEMENT_QUEUED_TIMEOUT_IN_SECONDS", want: AccountParameterStatementQueuedTimeoutInSeconds}, + {input: "STORAGE_SERIALIZATION_POLICY", want: AccountParameterStorageSerializationPolicy}, + {input: "SHARE_RESTRICTIONS", want: AccountParameterShareRestrictions}, + {input: "SUSPEND_TASK_AFTER_NUM_FAILURES", want: AccountParameterSuspendTaskAfterNumFailures}, + {input: "TRACE_LEVEL", want: AccountParameterTraceLevel}, + {input: "USER_TASK_MANAGED_INITIAL_WAREHOUSE_SIZE", want: AccountParameterUserTaskManagedInitialWarehouseSize}, + {input: "USER_TASK_TIMEOUT_MS", want: AccountParameterUserTaskTimeoutMs}, + {input: "TASK_AUTO_RETRY_ATTEMPTS", want: AccountParameterTaskAutoRetryAttempts}, + {input: "USER_TASK_MINIMUM_TRIGGER_INTERVAL_IN_SECONDS", want: AccountParameterUserTaskMinimumTriggerIntervalInSeconds}, + {input: "METRIC_LEVEL", want: AccountParameterMetricLevel}, + {input: "ENABLE_CONSOLE_OUTPUT", want: AccountParameterEnableConsoleOutput}, + {input: "ENABLE_UNREDACTED_QUERY_SYNTAX_ERROR", want: AccountParameterEnableUnredactedQuerySyntaxError}, + } + + invalid := []test{ + {input: ""}, + {input: "foo"}, + } + + for _, tc := range valid { + t.Run(tc.input, func(t *testing.T) { + got, err := ToAccountParameter(tc.input) + require.NoError(t, err) + require.Equal(t, tc.want, got) + }) + } + + for _, tc := range invalid { + t.Run(tc.input, func(t *testing.T) { + _, err := ToAccountParameter(tc.input) + require.Error(t, err) + }) + } +} diff --git a/templates/resources/account_parameter.md.tmpl b/templates/resources/account_parameter.md.tmpl new file mode 100644 index 0000000000..15c1ee96c9 --- /dev/null +++ b/templates/resources/account_parameter.md.tmpl @@ -0,0 +1,37 @@ +--- +page_title: "{{.Name}} {{.Type}} - {{.ProviderName}}" +subcategory: "" +description: |- +{{ if gt (len (split .Description "")) 1 -}} +{{ index (split .Description "") 1 | plainmarkdown | trimspace | prefixlines " " }} +{{- else -}} +{{ .Description | plainmarkdown | trimspace | prefixlines " " }} +{{- end }} +--- + +!> **V1 release candidate** This resource was reworked and is a release candidate for the V1. We do not expect significant changes in it before the V1. We will welcome any feedback and adjust the resource if needed. Any errors reported will be resolved with a higher priority. We encourage checking this resource out before the V1 release. Please follow the [migration guide](https://github.com/Snowflake-Labs/terraform-provider-snowflake/blob/main/MIGRATION_GUIDE.md#v0990--v01000) to use it. + +-> **Note** This resource does not support all account parameters. The supported ones are listed below. This feature gap will be addressed in future releases. + +# {{.Name}} ({{.Type}}) + +{{ .Description | trimspace }} + +{{ if .HasExample -}} +## Example Usage + +{{ tffile (printf "examples/resources/%s/resource.tf" .Name)}} +-> **Note** Instead of using fully_qualified_name, you can reference objects managed outside Terraform by constructing a correct ID, consult [identifiers guide](https://registry.terraform.io/providers/Snowflake-Labs/snowflake/latest/docs/guides/identifiers#new-computed-fully-qualified-name-field-in-resources). + + +{{- end }} + +{{ .SchemaMarkdown | trimspace }} +{{- if .HasImport }} + +## Import + +Import is supported using the following syntax: + +{{ codefile "shell" (printf "examples/resources/%s/import.sh" .Name)}} +{{- end }}