Skip to content

Commit

Permalink
chore: apply minor database changes (#2872)
Browse files Browse the repository at this point in the history
Apply the rest of the changes requested in #2842 
- Moved out a schema for the show database output
- Throw error in state upgrader for certain cases we cannot upgrade to
- Update state upgrader to map account locators to the recommended
account identifier format
- Use more strict mapping functions in update functions for all
databases (+ test them)

To add (in this pr)
- Better documentation for old database `from_share` field

TODO
- Find out which test is setting data retention time in days on the
account and doesn't call unset (causing `TestAcc_Database_IntParameter`
to fail).
  • Loading branch information
sfc-gh-jcieslak authored Jun 25, 2024
1 parent 6fb437b commit 6ccac59
Show file tree
Hide file tree
Showing 16 changed files with 762 additions and 283 deletions.
7 changes: 4 additions & 3 deletions MIGRATION_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ All the field changes in comparison to the previous database resource are:
- `from_share` - the parameter was moved to the dedicated resource for databases created from shares `snowflake_shared_database`. Right now, it's a text field instead of a map. Additionally, instead of legacy account identifier format we're expecting the new one that with share looks like this: `<organization_name>.<account_name>.<share_name>`. For more information on account identifiers, visit the [official documentation](https://docs.snowflake.com/en/user-guide/admin-account-identifier).
- p,
- `from_replication` - the parameter was moved to the dedicated resource for databases created from primary databases `snowflake_secondary_database`
- `replication_configuration` - renamed: was renamed to `configuration` and is only available in the `snowflake_database`. Its internal schema changed that instead of list of accounts, we expect a list of nested objects with accounts for which replication (and optionally failover) should be enabled. More information about converting between both versions [here](#resource-renamed-snowflake_database---snowflake_database_old). Additionally, instead of legacy account identifier format we're expecting the new one that looks like this: `<organization_name>.<account_name>`. For more information on account identifiers, visit the [official documentation](https://docs.snowflake.com/en/user-guide/admin-account-identifier).
- `replication_configuration` - renamed: was renamed to `configuration` and is only available in the `snowflake_database`. Its internal schema changed that instead of list of accounts, we expect a list of nested objects with accounts for which replication (and optionally failover) should be enabled. More information about converting between both versions [here](#resource-renamed-snowflake_database---snowflake_database_old). Additionally, instead of legacy account identifier format we're expecting the new one that looks like this: `<organization_name>.<account_name>` (it will be automatically migrated to the recommended format by the state upgrader). For more information on account identifiers, visit the [official documentation](https://docs.snowflake.com/en/user-guide/admin-account-identifier).
- `data_retention_time_in_days`
- in `snowflake_shared_database`
- removed: the field is removed from `snowflake_shared_database` as it doesn't have any effect on shared databases.
Expand Down Expand Up @@ -158,9 +158,10 @@ The only difference would be that instead of writing/generating new configuratio
- `replication_configuration` field was removed from `databases`.
- `pattern` was replaced by `like` field.
- Additional filtering options added (`limit`).
- Added missing fields returned by SHOW DATABASES.
- Added missing fields returned by SHOW DATABASES and enclosed its output in `show_output` field.
- Added outputs from **DESC DATABASE** and **SHOW PARAMETERS IN DATABASE** (they can be turned off by declaring `with_describe = false` and `with_parameters = false`, **they're turned on by default**).
The additional parameters call **DESC DATABASE** (with `with_describe` turned on) and **SHOW PARAMETERS IN DATABASE** (with `with_parameters` turned on) **per database** returned by **SHOW DATABASES**.
The additional parameters call **DESC DATABASE** (with `with_describe` turned on) and **SHOW PARAMETERS IN DATABASE** (with `with_parameters` turned on) **per database** returned by **SHOW DATABASES**.
The outputs of both commands are held in `databases` entry, where **DESC DATABASE** is saved in the `describe_output` field, and **SHOW PARAMETERS IN DATABASE** in the `parameters` field.
It's important to limit the records and calls to Snowflake to the minimum. That's why we recommend assessing which information you need from the data source and then providing strong filters and turning off additional fields for better plan performance.

## v0.89.0 ➞ v0.90.0
Expand Down
245 changes: 228 additions & 17 deletions docs/data-sources/databases.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ output "limit_output" {
# Without additional data (to limit the number of calls make for every found database)
data "snowflake_databases" "only_show" {
# with_describe is turned on by default and it calls DESCRIBE DATABASE for every database found and attaches its output to databases.*.description field
# with_describe is turned on by default and it calls DESCRIBE DATABASE for every database found and attaches its output to databases.*.describe_output field
with_describe = false
# with_parameters is turned on by default and it calls SHOW PARAMETERS FOR DATABASE for every database found and attaches its output to databases.*.parameters field
Expand Down Expand Up @@ -120,24 +120,12 @@ Optional:

Read-Only:

- `comment` (String)
- `created_on` (String)
- `description` (List of Object) (see [below for nested schema](#nestedobjatt--databases--description))
- `is_current` (Boolean)
- `is_default` (Boolean)
- `is_transient` (Boolean)
- `kind` (String)
- `name` (String)
- `options` (String)
- `origin` (String)
- `owner` (String)
- `owner_role_type` (String)
- `describe_output` (List of Object) (see [below for nested schema](#nestedobjatt--databases--describe_output))
- `parameters` (List of Object) (see [below for nested schema](#nestedobjatt--databases--parameters))
- `resource_group` (String)
- `retention_time` (Number)
- `show_output` (List of Object) (see [below for nested schema](#nestedobjatt--databases--show_output))

<a id="nestedobjatt--databases--description"></a>
### Nested Schema for `databases.description`
<a id="nestedobjatt--databases--describe_output"></a>
### Nested Schema for `databases.describe_output`

Read-Only:

Expand All @@ -151,8 +139,231 @@ Read-Only:

Read-Only:

- `catalog` (List of Object) (see [below for nested schema](#nestedobjatt--databases--parameters--catalog))
- `data_retention_time_in_days` (List of Object) (see [below for nested schema](#nestedobjatt--databases--parameters--data_retention_time_in_days))
- `default_ddl_collation` (List of Object) (see [below for nested schema](#nestedobjatt--databases--parameters--default_ddl_collation))
- `enable_console_output` (List of Object) (see [below for nested schema](#nestedobjatt--databases--parameters--enable_console_output))
- `external_volume` (List of Object) (see [below for nested schema](#nestedobjatt--databases--parameters--external_volume))
- `log_level` (List of Object) (see [below for nested schema](#nestedobjatt--databases--parameters--log_level))
- `max_data_extension_time_in_days` (List of Object) (see [below for nested schema](#nestedobjatt--databases--parameters--max_data_extension_time_in_days))
- `quoted_identifiers_ignore_case` (List of Object) (see [below for nested schema](#nestedobjatt--databases--parameters--quoted_identifiers_ignore_case))
- `replace_invalid_characters` (List of Object) (see [below for nested schema](#nestedobjatt--databases--parameters--replace_invalid_characters))
- `storage_serialization_policy` (List of Object) (see [below for nested schema](#nestedobjatt--databases--parameters--storage_serialization_policy))
- `suspend_task_after_num_failures` (List of Object) (see [below for nested schema](#nestedobjatt--databases--parameters--suspend_task_after_num_failures))
- `task_auto_retry_attempts` (List of Object) (see [below for nested schema](#nestedobjatt--databases--parameters--task_auto_retry_attempts))
- `trace_level` (List of Object) (see [below for nested schema](#nestedobjatt--databases--parameters--trace_level))
- `user_task_managed_initial_warehouse_size` (List of Object) (see [below for nested schema](#nestedobjatt--databases--parameters--user_task_managed_initial_warehouse_size))
- `user_task_minimum_trigger_interval_in_seconds` (List of Object) (see [below for nested schema](#nestedobjatt--databases--parameters--user_task_minimum_trigger_interval_in_seconds))
- `user_task_timeout_ms` (List of Object) (see [below for nested schema](#nestedobjatt--databases--parameters--user_task_timeout_ms))

<a id="nestedobjatt--databases--parameters--catalog"></a>
### Nested Schema for `databases.parameters.catalog`

Read-Only:

- `default` (String)
- `description` (String)
- `key` (String)
- `level` (String)
- `value` (String)


<a id="nestedobjatt--databases--parameters--data_retention_time_in_days"></a>
### Nested Schema for `databases.parameters.data_retention_time_in_days`

Read-Only:

- `default` (String)
- `description` (String)
- `key` (String)
- `level` (String)
- `value` (String)


<a id="nestedobjatt--databases--parameters--default_ddl_collation"></a>
### Nested Schema for `databases.parameters.default_ddl_collation`

Read-Only:

- `default` (String)
- `description` (String)
- `key` (String)
- `level` (String)
- `value` (String)


<a id="nestedobjatt--databases--parameters--enable_console_output"></a>
### Nested Schema for `databases.parameters.enable_console_output`

Read-Only:

- `default` (String)
- `description` (String)
- `key` (String)
- `level` (String)
- `value` (String)


<a id="nestedobjatt--databases--parameters--external_volume"></a>
### Nested Schema for `databases.parameters.external_volume`

Read-Only:

- `default` (String)
- `description` (String)
- `key` (String)
- `level` (String)
- `value` (String)


<a id="nestedobjatt--databases--parameters--log_level"></a>
### Nested Schema for `databases.parameters.log_level`

Read-Only:

- `default` (String)
- `description` (String)
- `key` (String)
- `level` (String)
- `value` (String)


<a id="nestedobjatt--databases--parameters--max_data_extension_time_in_days"></a>
### Nested Schema for `databases.parameters.max_data_extension_time_in_days`

Read-Only:

- `default` (String)
- `description` (String)
- `key` (String)
- `level` (String)
- `value` (String)


<a id="nestedobjatt--databases--parameters--quoted_identifiers_ignore_case"></a>
### Nested Schema for `databases.parameters.quoted_identifiers_ignore_case`

Read-Only:

- `default` (String)
- `description` (String)
- `key` (String)
- `level` (String)
- `value` (String)


<a id="nestedobjatt--databases--parameters--replace_invalid_characters"></a>
### Nested Schema for `databases.parameters.replace_invalid_characters`

Read-Only:

- `default` (String)
- `description` (String)
- `key` (String)
- `level` (String)
- `value` (String)


<a id="nestedobjatt--databases--parameters--storage_serialization_policy"></a>
### Nested Schema for `databases.parameters.storage_serialization_policy`

Read-Only:

- `default` (String)
- `description` (String)
- `key` (String)
- `level` (String)
- `value` (String)


<a id="nestedobjatt--databases--parameters--suspend_task_after_num_failures"></a>
### Nested Schema for `databases.parameters.suspend_task_after_num_failures`

Read-Only:

- `default` (String)
- `description` (String)
- `key` (String)
- `level` (String)
- `value` (String)


<a id="nestedobjatt--databases--parameters--task_auto_retry_attempts"></a>
### Nested Schema for `databases.parameters.task_auto_retry_attempts`

Read-Only:

- `default` (String)
- `description` (String)
- `key` (String)
- `level` (String)
- `value` (String)


<a id="nestedobjatt--databases--parameters--trace_level"></a>
### Nested Schema for `databases.parameters.trace_level`

Read-Only:

- `default` (String)
- `description` (String)
- `key` (String)
- `level` (String)
- `value` (String)


<a id="nestedobjatt--databases--parameters--user_task_managed_initial_warehouse_size"></a>
### Nested Schema for `databases.parameters.user_task_managed_initial_warehouse_size`

Read-Only:

- `default` (String)
- `description` (String)
- `key` (String)
- `level` (String)
- `value` (String)


<a id="nestedobjatt--databases--parameters--user_task_minimum_trigger_interval_in_seconds"></a>
### Nested Schema for `databases.parameters.user_task_minimum_trigger_interval_in_seconds`

Read-Only:

- `default` (String)
- `description` (String)
- `key` (String)
- `level` (String)
- `value` (String)


<a id="nestedobjatt--databases--parameters--user_task_timeout_ms"></a>
### Nested Schema for `databases.parameters.user_task_timeout_ms`

Read-Only:

- `default` (String)
- `description` (String)
- `key` (String)
- `level` (String)
- `value` (String)



<a id="nestedobjatt--databases--show_output"></a>
### Nested Schema for `databases.show_output`

Read-Only:

- `comment` (String)
- `created_on` (String)
- `is_current` (Boolean)
- `is_default` (Boolean)
- `is_transient` (Boolean)
- `kind` (String)
- `name` (String)
- `options` (String)
- `origin` (String)
- `owner` (String)
- `owner_role_type` (String)
- `resource_group` (String)
- `retention_time` (Number)
2 changes: 1 addition & 1 deletion examples/data-sources/snowflake_databases/data-source.tf
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ output "limit_output" {

# Without additional data (to limit the number of calls make for every found database)
data "snowflake_databases" "only_show" {
# with_describe is turned on by default and it calls DESCRIBE DATABASE for every database found and attaches its output to databases.*.description field
# with_describe is turned on by default and it calls DESCRIBE DATABASE for every database found and attaches its output to databases.*.describe_output field
with_describe = false

# with_parameters is turned on by default and it calls SHOW PARAMETERS FOR DATABASE for every database found and attaches its output to databases.*.parameters field
Expand Down
Loading

0 comments on commit 6ccac59

Please sign in to comment.