Skip to content

Commit

Permalink
Resolve merge conflicts and adjust docs for databases
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-jcieslak committed Jun 10, 2024
1 parent 7bc0613 commit 460bab4
Show file tree
Hide file tree
Showing 15 changed files with 203 additions and 28 deletions.
8 changes: 4 additions & 4 deletions docs/data-sources/databases.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ 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 it's 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.*.description field
with_describe = false
# with_parameters is turned on by default and it calls SHOW PARAMETERS FOR DATABASE for every database found and attaches it's output to databases.*.parameters field
# 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
with_parameters = false
}
Expand All @@ -74,7 +74,7 @@ data "snowflake_databases" "assert_with_postcondition" {
}
}
# Ensure the number of databases is equal to at exatly one element (with the use of check block)
# Ensure the number of databases is equal to at exactly one element (with the use of check block)
check "database_check" {
data "snowflake_databases" "assert_with_check_block" {
like = "database-name"
Expand All @@ -93,7 +93,7 @@ check "database_check" {
### Optional

- `like` (String) Filters the output with **case-insensitive** pattern, with support for SQL wildcard characters (`%` and `_`).
- `limit` (Block List, Max: 1) Limits the number of rows returned. The limit may start from the first element matched by from which is optional. (see [below for nested schema](#nestedblock--limit))
- `limit` (Block List, Max: 1) Limits the number of rows returned. If the `limit.from` is set, then the limit wll start from the first element matched by the expression. The expression is only used to match with the first element, later on the elements are not matched by the prefix, but you can enforce a certain pattern with `starts_with` or `like`. (see [below for nested schema](#nestedblock--limit))
- `starts_with` (String) Filters the output with **case-sensitive** characters indicating the beginning of the object name.
- `with_describe` (Boolean) Runs DESC DATABASE for each database returned by SHOW DATABASES. The output of describe is saved to the description field. By default this value is set to true.
- `with_parameters` (Boolean) Runs SHOW PARAMETERS FOR DATABASE for each database returned by SHOW DATABASES. The output of describe is saved to the parameters field as a map. By default this value is set to true.
Expand Down
35 changes: 33 additions & 2 deletions docs/resources/secondary_database.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "snowflake_secondary_database Resource - terraform-provider-snowflake"
subcategory: ""
description: |-
Expand All @@ -7,6 +8,8 @@ description: |-

# snowflake_secondary_database (Resource)

~> **Note** The snowflake_secondary_database resource doesn't refresh itself, as the best practice is to use tasks scheduled for a certain interval. Check out the examples to see how to set up the refresh task. For SQL-based replication guide, see the [official documentation](https://docs.snowflake.com/en/user-guide/db-replication-config#replicating-a-database-to-another-account).

A secondary database creates a replica of an existing primary database (i.e. a secondary database). For more information about database replication, see [Introduction to database replication across multiple accounts](https://docs.snowflake.com/en/user-guide/db-replication-intro).

## Example Usage
Expand All @@ -17,7 +20,7 @@ resource "snowflake_standard_database" "primary" {
provider = primary_account # notice the provider fields
name = "database_name"
replication {
enable_for_account {
enable_to_account {
account_identifier = "<secondary_account_organization_name>.<secondary_account_name>"
with_failover = true
}
Expand All @@ -26,6 +29,14 @@ resource "snowflake_standard_database" "primary" {
}
# 2. Creating secondary database
## 2.1. Minimal version
resource "snowflake_secondary_database" "test" {
provider = secondary_account
name = snowflake_standard_database.primary.name # It's recommended to give a secondary database the same name as its primary database
as_replica_of = "<primary_account_organization_name>.<primary_account_name>.${snowflake_standard_database.primary.name}"
}
## 2.2. Complete version (with every optional set)
resource "snowflake_secondary_database" "test" {
provider = secondary_account
name = snowflake_standard_database.primary.name # It's recommended to give a secondary database the same name as its primary database
Expand All @@ -36,7 +47,7 @@ resource "snowflake_secondary_database" "test" {
data_retention_time_in_days = 10
max_data_extension_time_in_days = 20
external_volume = "<external_volume_name>"
catalog = "<external_volume_name>"
catalog = "<catalog_name>"
replace_invalid_characters = false
default_ddl_collation = "en_US"
storage_serialization_policy = "COMPATIBLE"
Expand All @@ -50,6 +61,26 @@ resource "snowflake_secondary_database" "test" {
quoted_identifiers_ignore_case = false
enable_console_output = false
}
# The snowflake_secondary_database resource doesn't refresh itself, as the best practice is to use tasks scheduled for a certain interval.
# To create the refresh tasks, use separate database and schema.
resource "snowflake_standard_database" "tasks" {
name = "database_for_tasks"
}
resource "snowflake_schema" "tasks" {
name = "schema_for_tasks"
database = snowflake_standard_database.tasks.name
}
resource "snowflake_task" "refresh_secondary_database" {
database = snowflake_standard_database.tasks.name
name = "refresh_secondary_database"
schema = snowflake_schema.tasks.name
schedule = "10 minute"
sql_statement = "ALTER DATABASE ${snowflake_secondary_database.test.name} REFRESH"
}
```

<!-- schema generated by tfplugindocs -->
Expand Down
11 changes: 10 additions & 1 deletion docs/resources/shared_database.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ resource "snowflake_grant_privileges_to_share" "test" {
}
# 2. Creating shared database
## 2.1. Minimal version
resource "snowflake_shared_database" "test" {
provider = secondary_account
depends_on = [snowflake_grant_privileges_to_share.test]
name = snowflake_standard_database.test.name # shared database should have the same as the "imported" one
from_share = "<primary_account_organization_name>.<primary_account_name>.${snowflake_share.test.name}"
}
## 2.2. Complete version (with every optional set)
resource "snowflake_shared_database" "test" {
provider = secondary_account
depends_on = [snowflake_grant_privileges_to_share.test]
Expand All @@ -43,7 +52,7 @@ resource "snowflake_shared_database" "test" {
data_retention_time_in_days = 10
max_data_extension_time_in_days = 20
external_volume = "<external_volume_name>"
catalog = "<external_volume_name>"
catalog = "<catalog_name>"
replace_invalid_characters = false
default_ddl_collation = "en_US"
storage_serialization_policy = "COMPATIBLE"
Expand Down
41 changes: 36 additions & 5 deletions docs/resources/standard_database.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,22 @@ Represents a standard database. If replication configuration is specified, the d
## Example Usage

```terraform
## Minimal
resource "snowflake_standard_database" "primary" {
name = "database_name"
}
## Complete (with every optional set)
resource "snowflake_standard_database" "primary" {
name = "database_name"
is_transient = false
comment = "my standard database"
data_retention_time_in_days = 10
data_retention_time_in_days_save = 10
max_data_extension_time_in_days = 20
external_volume = "<external_volume_name>"
catalog = "<external_volume_name>"
catalog = "<catalog_name>"
replace_invalid_characters = false
default_ddl_collation = "en_US"
storage_serialization_policy = "COMPATIBLE"
Expand All @@ -35,13 +42,37 @@ resource "snowflake_standard_database" "primary" {
enable_console_output = false
replication {
enable_for_account {
enable_to_account {
account_identifier = "<secondary_account_organization_name>.<secondary_account_name>"
with_failover = true
}
ignore_edition_check = true
}
}
## Replication with for_each
locals {
replication_configs = [
{
account_identifier = "<secondary_account_organization_name>.<secondary_account_name>"
with_failover = true
},
{
account_identifier = "<secondary_account_organization_name>.<secondary_account_name>"
with_failover = true
},
]
}
resource "snowflake_standard_database" "primary" {
name = "database_name"
for_each = local.replication_configs
replication {
enable_to_account = each.value
ignore_edition_check = true
}
}
```

<!-- schema generated by tfplugindocs -->
Expand Down Expand Up @@ -82,14 +113,14 @@ resource "snowflake_standard_database" "primary" {

Required:

- `enable_for_account` (Block List, Min: 1) Entry to enable replication and optionally failover for a given account identifier. (see [below for nested schema](#nestedblock--replication--enable_for_account))
- `enable_to_account` (Block List, Min: 1) Entry to enable replication and optionally failover for a given account identifier. (see [below for nested schema](#nestedblock--replication--enable_to_account))

Optional:

- `ignore_edition_check` (Boolean) Allows replicating data to accounts on lower editions in either of the following scenarios: 1. The primary database is in a Business Critical (or higher) account but one or more of the accounts approved for replication are on lower editions. Business Critical Edition is intended for Snowflake accounts with extremely sensitive data. 2. The primary database is in a Business Critical (or higher) account and a signed business associate agreement is in place to store PHI data in the account per HIPAA and HITRUST regulations, but no such agreement is in place for one or more of the accounts approved for replication, regardless if they are Business Critical (or higher) accounts. Both scenarios are prohibited by default in an effort to help prevent account administrators for Business Critical (or higher) accounts from inadvertently replicating sensitive data to accounts on lower editions.

<a id="nestedblock--replication--enable_for_account"></a>
### Nested Schema for `replication.enable_for_account`
<a id="nestedblock--replication--enable_to_account"></a>
### Nested Schema for `replication.enable_to_account`

Required:

Expand Down
6 changes: 3 additions & 3 deletions examples/data-sources/snowflake_databases/data-source.tf
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ 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 it's 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.*.description field
with_describe = false

# with_parameters is turned on by default and it calls SHOW PARAMETERS FOR DATABASE for every database found and attaches it's output to databases.*.parameters field
# 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
with_parameters = false
}

Expand All @@ -60,7 +60,7 @@ data "snowflake_databases" "assert_with_postcondition" {
}
}

# Ensure the number of databases is equal to at exatly one element (with the use of check block)
# Ensure the number of databases is equal to at exactly one element (with the use of check block)
check "database_check" {
data "snowflake_databases" "assert_with_check_block" {
like = "database-name"
Expand Down
32 changes: 30 additions & 2 deletions examples/resources/snowflake_secondary_database/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ resource "snowflake_standard_database" "primary" {
provider = primary_account # notice the provider fields
name = "database_name"
replication {
enable_for_account {
enable_to_account {
account_identifier = "<secondary_account_organization_name>.<secondary_account_name>"
with_failover = true
}
Expand All @@ -12,6 +12,14 @@ resource "snowflake_standard_database" "primary" {
}

# 2. Creating secondary database
## 2.1. Minimal version
resource "snowflake_secondary_database" "test" {
provider = secondary_account
name = snowflake_standard_database.primary.name # It's recommended to give a secondary database the same name as its primary database
as_replica_of = "<primary_account_organization_name>.<primary_account_name>.${snowflake_standard_database.primary.name}"
}

## 2.2. Complete version (with every optional set)
resource "snowflake_secondary_database" "test" {
provider = secondary_account
name = snowflake_standard_database.primary.name # It's recommended to give a secondary database the same name as its primary database
Expand All @@ -22,7 +30,7 @@ resource "snowflake_secondary_database" "test" {
data_retention_time_in_days = 10
max_data_extension_time_in_days = 20
external_volume = "<external_volume_name>"
catalog = "<external_volume_name>"
catalog = "<catalog_name>"
replace_invalid_characters = false
default_ddl_collation = "en_US"
storage_serialization_policy = "COMPATIBLE"
Expand All @@ -36,3 +44,23 @@ resource "snowflake_secondary_database" "test" {
quoted_identifiers_ignore_case = false
enable_console_output = false
}

# The snowflake_secondary_database resource doesn't refresh itself, as the best practice is to use tasks scheduled for a certain interval.
# To create the refresh tasks, use separate database and schema.

resource "snowflake_standard_database" "tasks" {
name = "database_for_tasks"
}

resource "snowflake_schema" "tasks" {
name = "schema_for_tasks"
database = snowflake_standard_database.tasks.name
}

resource "snowflake_task" "refresh_secondary_database" {
database = snowflake_standard_database.tasks.name
name = "refresh_secondary_database"
schema = snowflake_schema.tasks.name
schedule = "10 minute"
sql_statement = "ALTER DATABASE ${snowflake_secondary_database.test.name} REFRESH"
}
11 changes: 10 additions & 1 deletion examples/resources/snowflake_shared_database/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ resource "snowflake_grant_privileges_to_share" "test" {
}

# 2. Creating shared database
## 2.1. Minimal version
resource "snowflake_shared_database" "test" {
provider = secondary_account
depends_on = [snowflake_grant_privileges_to_share.test]
name = snowflake_standard_database.test.name # shared database should have the same as the "imported" one
from_share = "<primary_account_organization_name>.<primary_account_name>.${snowflake_share.test.name}"
}

## 2.2. Complete version (with every optional set)
resource "snowflake_shared_database" "test" {
provider = secondary_account
depends_on = [snowflake_grant_privileges_to_share.test]
Expand All @@ -29,7 +38,7 @@ resource "snowflake_shared_database" "test" {
data_retention_time_in_days = 10
max_data_extension_time_in_days = 20
external_volume = "<external_volume_name>"
catalog = "<external_volume_name>"
catalog = "<catalog_name>"
replace_invalid_characters = false
default_ddl_collation = "en_US"
storage_serialization_policy = "COMPATIBLE"
Expand Down
35 changes: 33 additions & 2 deletions examples/resources/snowflake_standard_database/resource.tf
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
## Minimal
resource "snowflake_standard_database" "primary" {
name = "database_name"
}

## Complete (with every optional set)
resource "snowflake_standard_database" "primary" {
name = "database_name"
is_transient = false
comment = "my standard database"

data_retention_time_in_days = 10
data_retention_time_in_days_save = 10
max_data_extension_time_in_days = 20
external_volume = "<external_volume_name>"
catalog = "<external_volume_name>"
catalog = "<catalog_name>"
replace_invalid_characters = false
default_ddl_collation = "en_US"
storage_serialization_policy = "COMPATIBLE"
Expand All @@ -21,10 +28,34 @@ resource "snowflake_standard_database" "primary" {
enable_console_output = false

replication {
enable_for_account {
enable_to_account {
account_identifier = "<secondary_account_organization_name>.<secondary_account_name>"
with_failover = true
}
ignore_edition_check = true
}
}

## Replication with for_each
locals {
replication_configs = [
{
account_identifier = "<secondary_account_organization_name>.<secondary_account_name>"
with_failover = true
},
{
account_identifier = "<secondary_account_organization_name>.<secondary_account_name>"
with_failover = true
},
]
}

resource "snowflake_standard_database" "primary" {
name = "database_name"
for_each = local.replication_configs

replication {
enable_to_account = each.value
ignore_edition_check = true
}
}
2 changes: 1 addition & 1 deletion pkg/datasources/databases.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var databasesSchema = map[string]*schema.Schema{
"limit": {
Type: schema.TypeList,
Optional: true,
Description: `Limits the number of rows returned. The limit may start from the first element matched by from which is optional.`,
Description: "Limits the number of rows returned. If the `limit.from` is set, then the limit wll start from the first element matched by the expression. The expression is only used to match with the first element, later on the elements are not matched by the prefix, but you can enforce a certain pattern with `starts_with` or `like`.",
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ resource "snowflake_standard_database" "test" {
name = var.name
comment = var.comment
replication {
enable_for_account {
enable_to_account {
account_identifier = var.account_identifier
with_failover = true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ resource "snowflake_standard_database" "test" {
name = var.name
comment = var.comment
replication {
enable_for_account {
enable_to_account {
account_identifier = var.account_identifier
with_failover = true
}
Expand Down
Loading

0 comments on commit 460bab4

Please sign in to comment.