Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-jcieslak committed Jun 4, 2024
1 parent 2b5ccf0 commit 5a77aab
Show file tree
Hide file tree
Showing 57 changed files with 690 additions and 304 deletions.
8 changes: 7 additions & 1 deletion MIGRATION_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,20 @@ across different versions.
## v0.91.0 ➞ v0.92.0
### snowflake_database new alternatives
As part of the [preparation for v1](https://github.com/Snowflake-Labs/terraform-provider-snowflake/blob/main/ROADMAP.md#preparing-essential-ga-objects-for-the-provider-v1), we split up the database resource into multiple ones:
- Standard database (in progress)
- Standard database - can be used as `snowflake_standard_database` (used to create databases with optional ability to become a primary database ready for replication)
- Shared database - can be used as `snowflake_shared_database` (used to create databases from externally defined shares)
- Secondary database - can be used as `snowflake_secondary_database` (used to create replicas of databases from external sources)
From now on, please migrate and use the new database resources for their unique use cases. For more information, see the documentation for those resources on the [Terraform Registry](https://registry.terraform.io/providers/Snowflake-Labs/snowflake/latest/docs).

The split was done (and will be done for several objects during the refactor) to simplify the resource on maintainability and usage level.
Its purpose was also to divide the resources by their specific purpose rather than cramping every use case of an object into one resource.

### *(behavior change)* snowflake_databases
- The `pattern` was replaced by `like` field.
- Additional filtering options added (`limit`)
- Added missing fields returned by SHOW DATABASES
- 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**)

## v0.89.0 ➞ v0.90.0
### snowflake_table resource changes
#### *(behavior change)* Validation to column type added
Expand Down
80 changes: 69 additions & 11 deletions docs/data-sources/databases.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,44 +12,102 @@ description: |-
## Example Usage

```terraform
data "snowflake_databases" "this" {}
data "snowflake_databases" "test" {
with_describe = false
with_parameters = false
like = "database-name"
starts_with = "database-name"
limit {
rows = 20
from = "database-name"
}
lifecycle {
postcondition {
condition = length(self.databases) > 0
error_message = "there should be at least one database"
}
}
}
check "database_check" {
data "snowflake_databases" "test" {
like = "database-name"
}
assert {
condition = length(data.snowflake_databases.test.databases) == 1
error_message = "Databases fieltered by '${data.snowflake_databases.test.like}' returned ${length(data.snowflake_databases.test.databases)} databases where one was expected"
}
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Optional

- `history` (Boolean) Optionally includes dropped databases that have not yet been purged The output also includes an additional `dropped_on` column
- `pattern` (String) Optionally filters the databases by a pattern
- `starts_with` (String) Optionally filters the databases by a pattern
- `terse` (Boolean) Optionally returns only the columns `created_on` and `name` in the results
- `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, while also enabling "pagination" or the results. (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.

### Read-Only

- `databases` (List of Object) Snowflake databases (see [below for nested schema](#nestedatt--databases))
- `databases` (List of Object) Holds the output of SHOW DATABASES. (see [below for nested schema](#nestedatt--databases))
- `id` (String) The ID of this resource.

<a id="nestedblock--limit"></a>
### Nested Schema for `limit`

Required:

- `rows` (Number) The maximum number of rows to return.

Optional:

- `from` (String) Specifies a **case-sensitive** pattern that is used to match object name. After the first match, the limit on the number of rows will be applied.


<a id="nestedatt--databases"></a>
### Nested Schema for `databases`

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)
- `replication_configuration` (List of Object) (see [below for nested schema](#nestedobjatt--databases--replication_configuration))
- `owner_role_type` (String)
- `parameters` (List of Object) (see [below for nested schema](#nestedobjatt--databases--parameters))
- `resource_group` (String)
- `retention_time` (Number)

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

Read-Only:

- `created_on` (String)
- `kind` (String)
- `name` (String)


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

Read-Only:

- `accounts` (List of String)
- `ignore_edition_check` (Boolean)
- `default` (String)
- `description` (String)
- `key` (String)
- `level` (String)
- `value` (String)
4 changes: 2 additions & 2 deletions docs/data-sources/parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ description: |-
## Example Usage

```terraform
resource "snowflake_database" "d" {
resource "snowflake_standard_database" "d" {
name = "TEST_DB"
}
// read all object parameters in database TEST_DB
data "snowflake_parameters" "p" {
parameter_type = "OBJECT"
object_type = "DATABASE"
object_name = snowflake_database.d.name
object_name = snowflake_standard_database.d.name
}
// read all account parameters with the pattern '%TIMESTAMP%'
Expand Down
1 change: 1 addition & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ The Snowflake provider will use the following order of precedence when determini
## Currently deprecated resources

- [snowflake_account_grant](./docs/resources/account_grant) - use [snowflake_grant_privileges_to_account_role](./docs/resources/grant_privileges_to_account_role) instead
- [snowflake_database](./docs/resources/database)
- [snowflake_database_grant](./docs/resources/database_grant) - use [snowflake_grant_privileges_to_account_role](./docs/resources/grant_privileges_to_account_role) instead
- [snowflake_external_table_grant](./docs/resources/external_table_grant) - use [snowflake_grant_privileges_to_account_role](./docs/resources/grant_privileges_to_account_role) instead
- [snowflake_failover_group_grant](./docs/resources/failover_group_grant) - use [snowflake_grant_privileges_to_account_role](./docs/resources/grant_privileges_to_account_role) instead
Expand Down
2 changes: 1 addition & 1 deletion docs/resources/database.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ description: |-

# snowflake_database (Resource)


~> **Deprecation** This resource is deprecated and will be removed in a future major version release. Please use snowflake_standard_database or snowflake_shared_database or snowflake_secondary_database instead. <deprecation>

## Example Usage

Expand Down
6 changes: 3 additions & 3 deletions docs/resources/failover_group.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ description: |-
## Example Usage

```terraform
resource "snowflake_database" "db" {
resource "snowflake_standard_database" "db" {
name = "db1"
}
resource "snowflake_failover_group" "source_failover_group" {
name = "FG1"
object_types = ["WAREHOUSES", "DATABASES", "INTEGRATIONS", "ROLES"]
allowed_accounts = ["<org_name>.<target_account_name1>", "<org_name>.<target_account_name2>"]
allowed_databases = [snowflake_database.db.name]
allowed_databases = [snowflake_standard_database.db.name]
allowed_integration_types = ["SECURITY INTEGRATIONS"]
replication_schedule {
cron {
Expand All @@ -43,7 +43,7 @@ resource "snowflake_failover_group" "target_failover_group" {
from_replica {
organization_name = "..."
source_account_name = "..."
name = snowflake_failover_group.fg.name
name = snowflake_failover_group.source_failover_group.name
}
}
```
Expand Down
4 changes: 2 additions & 2 deletions docs/resources/function.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ provider "snowflake" {
}
// Create database
resource "snowflake_database" "db" {
resource "snowflake_standard_database" "db" {
name = "MY_DB"
data_retention_days = 1
}
// Create schema
resource "snowflake_schema" "schema" {
database = snowflake_database.db.name
database = snowflake_standard_database.db.name
name = "MY_SCHEMA"
data_retention_days = 1
}
Expand Down
44 changes: 22 additions & 22 deletions docs/resources/grant_ownership.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,48 +26,48 @@ resource "snowflake_role" "test" {
name = "test_role"
}
resource "snowflake_database" "test" {
resource "snowflake_standard_database" "test" {
name = "test_database"
}
resource "snowflake_schema" "test" {
name = "test_schema"
database = snowflake_database.test.name
database = snowflake_standard_database.test.name
}
resource "snowflake_grant_ownership" "test" {
account_role_name = snowflake_role.test.name
outbound_privileges = "COPY"
on {
object_type = "SCHEMA"
object_name = "\"${snowflake_database.test.name}\".\"${snowflake_schema.test.name}\""
object_name = "\"${snowflake_standard_database.test.name}\".\"${snowflake_schema.test.name}\""
}
}
##################################
### on object to database role
##################################
resource "snowflake_database" "test" {
resource "snowflake_standard_database" "test" {
name = "test_database"
}
resource "snowflake_schema" "test" {
name = "test_schema"
database = snowflake_database.test.name
database = snowflake_standard_database.test.name
}
resource "snowflake_database_role" "test" {
resource "snowflake_standard_database_role" "test" {
name = "test_database_role"
database = snowflake_database.test.name
database = snowflake_standard_database.test.name
}
resource "snowflake_grant_ownership" "test" {
database_role_name = "\"${snowflake_database_role.test.database}\".\"${snowflake_database_role.test.name}\""
database_role_name = "\"${snowflake_standard_database_role.test.database}\".\"${snowflake_standard_database_role.test.name}\""
outbound_privileges = "REVOKE"
on {
object_type = "SCHEMA"
object_name = "\"${snowflake_database.test.name}\".\"${snowflake_schema.test.name}\""
object_name = "\"${snowflake_standard_database.test.name}\".\"${snowflake_schema.test.name}\""
}
}
Expand All @@ -79,7 +79,7 @@ resource "snowflake_role" "test" {
name = "test_role"
}
resource "snowflake_database" "test" {
resource "snowflake_standard_database" "test" {
name = "test_database"
}
Expand All @@ -88,7 +88,7 @@ resource "snowflake_grant_ownership" "test" {
on {
all {
object_type_plural = "TABLES"
in_database = snowflake_database.test.name
in_database = snowflake_standard_database.test.name
}
}
}
Expand All @@ -101,21 +101,21 @@ resource "snowflake_role" "test" {
name = "test_role"
}
resource "snowflake_database" "test" {
resource "snowflake_standard_database" "test" {
name = "test_database"
}
resource "snowflake_schema" "test" {
name = "test_schema"
database = snowflake_database.test.name
database = snowflake_standard_database.test.name
}
resource "snowflake_grant_ownership" "test" {
account_role_name = snowflake_role.test.name
on {
all {
object_type_plural = "TABLES"
in_schema = "\"${snowflake_database.test.name}\".\"${snowflake_schema.test.name}\""
in_schema = "\"${snowflake_standard_database.test.name}\".\"${snowflake_schema.test.name}\""
}
}
}
Expand All @@ -128,7 +128,7 @@ resource "snowflake_role" "test" {
name = "test_role"
}
resource "snowflake_database" "test" {
resource "snowflake_standard_database" "test" {
name = "test_database"
}
Expand All @@ -137,7 +137,7 @@ resource "snowflake_grant_ownership" "test" {
on {
future {
object_type_plural = "TABLES"
in_database = snowflake_database.test.name
in_database = snowflake_standard_database.test.name
}
}
}
Expand All @@ -150,21 +150,21 @@ resource "snowflake_role" "test" {
name = "test_role"
}
resource "snowflake_database" "test" {
resource "snowflake_standard_database" "test" {
name = "test_database"
}
resource "snowflake_schema" "test" {
name = "test_schema"
database = snowflake_database.test.name
database = snowflake_standard_database.test.name
}
resource "snowflake_grant_ownership" "test" {
account_role_name = snowflake_role.test.name
on {
future {
object_type_plural = "TABLES"
in_schema = "\"${snowflake_database.test.name}\".\"${snowflake_schema.test.name}\""
in_schema = "\"${snowflake_standard_database.test.name}\".\"${snowflake_schema.test.name}\""
}
}
}
Expand All @@ -177,15 +177,15 @@ resource "snowflake_role" "test" {
name = "role"
}
resource "snowflake_database" "test" {
resource "snowflake_standard_database" "test" {
name = "database"
}
resource "snowflake_grant_ownership" "test" {
account_role_name = snowflake_role.test.name
on {
object_type = "DATABASE"
object_name = snowflake_database.test.name
object_name = snowflake_standard_database.test.name
}
}
Expand All @@ -204,7 +204,7 @@ provider "snowflake" {
resource "snowflake_schema" "test" {
depends_on = [snowflake_grant_ownership.test, snowflake_grant_account_role.test]
provider = snowflake.secondary
database = snowflake_database.test.name
database = snowflake_standard_database.test.name
name = "schema"
}
```
Expand Down
Loading

0 comments on commit 5a77aab

Please sign in to comment.