Terraform module for Snowflake database management.
- Creates Snowflake database
- Can create custom Snowflake database roles with role-to-role assignments
- Can create a set of default database roles to simplify access management:
READONLY
- grantedUSAGE
andMONITOR
privileges on the databaseTRANSFORMER
- allows creating schemas and some Snowflake objects in themADMIN
- full access, including database options likedata_retention_time_in_days
- Can create number of schemas in the database with their specific stages and access roles
- Can create database ownership to specified account role
module "snowflake_database" {
source = "getindata/database/snowflake"
# version = "x.x.x"
name = "MY_DB"
is_transient = false
data_retention_time_in_days = 1
create_default_roles = true
}
Due to breaking changes in Snowflake provider and additional code optimizations, breaking changes were introduced in v2.0.0
version of this module.
List of code and variable (API) changes:
- Switched to
snowflake_database_role
module to leverage newdatabase_roles
mechanism - database
default_roles
andcustom_roles
are now managed bygetindata/database_role/snowflake
module - snowflake_database resource was updated to use newly introduced changes in Snowflake provider
- snowflake_schema resource was updated to use newly introduced changes in Snowflake provider
- variable
add_grants_to_existing_objects
was removed as it is no longer needed - minimum Snowflake provider version is
0.90.0
For more information, refer to variables.tf, list of inputs below and Snowflake provider documentation
When upgrading from v1.x
, expect most of the resources to be recreated - if recreation is impossible, then it is possible to import some existing resources.
Name | Description | Type | Default | Required |
---|---|---|---|---|
additional_tag_map | Additional key-value pairs to add to each map in tags_as_list_of_maps . Not added to tags or id .This is for some rare cases where resources want additional configuration of tags and therefore take a list of maps with tag key, value, and additional configuration. |
map(string) |
{} |
no |
attributes | ID element. Additional attributes (e.g. workers or cluster ) to add to id ,in the order they appear in the list. New attributes are appended to the end of the list. The elements of the list are joined by the delimiter and treated as a single ID element. |
list(string) |
[] |
no |
catalog | The database parameter that specifies the default catalog to use for Iceberg tables | string |
null |
no |
comment | Specifies a comment for the database | string |
null |
no |
context | Single object for setting entire context at once. See description of individual variables for details. Leave string and numeric variables as null to use default value.Individual variable settings (non-null) override settings in context object, except for attributes, tags, and additional_tag_map, which are merged. |
any |
{ |
no |
create_default_roles | Whether the default roles should be created | bool |
false |
no |
data_retention_time_in_days | Number of days for which Snowflake retains historical data for performing Time Travel actions (SELECT, CLONE, UNDROP) on the object. A value of 0 effectively disables Time Travel for the specified database, schema, or table | number |
null |
no |
database_ownership_grant | The name of the account role to which database privileges will be granted | string |
null |
no |
default_ddl_collation | Specifies a default collation specification for all schemas and tables added to the database. | string |
null |
no |
delimiter | Delimiter to be used between ID elements. Defaults to - (hyphen). Set to "" to use no delimiter at all. |
string |
null |
no |
descriptor_formats | Describe additional descriptors to be output in the descriptors output map.Map of maps. Keys are names of descriptors. Values are maps of the form {<br> format = string<br> labels = list(string)<br>} (Type is any so the map values can later be enhanced to provide additional options.)format is a Terraform format string to be passed to the format() function.labels is a list of labels, in order, to pass to format() function.Label values will be normalized before being passed to format() so they will beidentical to how they appear in id .Default is {} (descriptors output will be empty). |
any |
{} |
no |
descriptor_name | Name of the descriptor used to form a resource name | string |
"snowflake-database" |
no |
enable_console_output | If true, enables stdout/stderr fast path logging for anonymous stored procedures | bool |
null |
no |
enabled | Set to false to prevent the module from creating any resources | bool |
null |
no |
environment | ID element. Usually used for region e.g. 'uw2', 'us-west-2', OR role 'prod', 'staging', 'dev', 'UAT' | string |
null |
no |
external_volume | The database parameter that specifies the default external volume to use for Iceberg tables | string |
null |
no |
id_length_limit | Limit id to this many characters (minimum 6).Set to 0 for unlimited length.Set to null for keep the existing setting, which defaults to 0 .Does not affect id_full . |
number |
null |
no |
is_transient | Specifies a database as transient. Transient databases do not have a Fail-safe period so they do not incur additional storage costs once they leave Time Travel; however, this means they are also not protected by Fail-safe in the event of a data loss | bool |
null |
no |
label_key_case | Controls the letter case of the tags keys (label names) for tags generated by this module.Does not affect keys of tags passed in via the tags input.Possible values: lower , title , upper .Default value: title . |
string |
null |
no |
label_order | The order in which the labels (ID elements) appear in the id .Defaults to ["namespace", "environment", "stage", "name", "attributes"]. You can omit any of the 6 labels ("tenant" is the 6th), but at least one must be present. |
list(string) |
null |
no |
label_value_case | Controls the letter case of ID elements (labels) as included in id ,set as tag values, and output by this module individually. Does not affect values of tags passed in via the tags input.Possible values: lower , title , upper and none (no transformation).Set this to title and set delimiter to "" to yield Pascal Case IDs.Default value: lower . |
string |
null |
no |
labels_as_tags | Set of labels (ID elements) to include as tags in the tags output.Default is to include all labels. Tags with empty values will not be included in the tags output.Set to [] to suppress all generated tags.Notes: The value of the name tag, if included, will be the id , not the name .Unlike other null-label inputs, the initial setting of labels_as_tags cannot bechanged in later chained modules. Attempts to change it will be silently ignored. |
set(string) |
[ |
no |
log_level | Specifies the severity level of messages that should be ingested and made available in the active event table. Valid options are: [TRACE DEBUG INFO WARN ERROR FATAL OFF] | string |
null |
no |
max_data_extension_time_in_days | Object parameter that specifies the maximum number of days for which Snowflake can extend the data retention period for tables in the database to prevent streams on the tables from becoming stale | number |
null |
no |
name | ID element. Usually the component or solution name, e.g. 'app' or 'jenkins'. This is the only ID element not also included as a tag .The "name" tag is set to the full id string. There is no tag with the value of the name input. |
string |
null |
no |
namespace | ID element. Usually an abbreviation of your organization name, e.g. 'eg' or 'cp', to help ensure generated IDs are globally unique | string |
null |
no |
quoted_identifiers_ignore_case | If true, the case of quoted identifiers is ignored | bool |
null |
no |
regex_replace_chars | Terraform regular expression (regex) string. Characters matching the regex will be removed from the ID elements. If not set, "/[^a-zA-Z0-9-]/" is used to remove all characters other than hyphens, letters and digits. |
string |
null |
no |
replace_invalid_characters | Specifies whether to replace invalid UTF-8 characters with the Unicode replacement character () in query results for an Iceberg table | bool |
null |
no |
roles | Roles created in the database scope | map(object({ |
{} |
no |
schemas | Schemas to be created in the database | map(object({ |
{} |
no |
stage | ID element. Usually used to indicate role, e.g. 'prod', 'staging', 'source', 'build', 'test', 'deploy', 'release' | string |
null |
no |
storage_serialization_policy | The storage serialization policy for Iceberg tables that use Snowflake as the catalog. Valid options are: [COMPATIBLE OPTIMIZED] | string |
null |
no |
suspend_task_after_num_failures | How many times a task must fail in a row before it is automatically suspended. 0 disables auto-suspending | number |
null |
no |
tags | Additional tags (e.g. {'BusinessUnit': 'XYZ'} ).Neither the tag keys nor the tag values will be modified by this module. |
map(string) |
{} |
no |
task_auto_retry_attempts | Maximum automatic retries allowed for a user task | number |
null |
no |
tenant | ID element _(Rarely used, not included by default)_. A customer identifier, indicating who this instance of a resource is for | string |
null |
no |
trace_level | Controls how trace events are ingested into the event table. Valid options are: [ALWAYS ON_EVENT OFF] | string |
null |
no |
user_task_managed_initial_warehouse_size | The initial size of warehouse to use for managed warehouses in the absence of history | string |
null |
no |
user_task_minimum_trigger_interval_in_seconds | Minimum amount of time between Triggered Task executions in seconds | number |
null |
no |
user_task_timeout_ms | User task execution timeout in milliseconds | number |
null |
no |
Name | Source | Version |
---|---|---|
database_label | cloudposse/label/null | 0.25.0 |
roles_deep_merge | Invicton-Labs/deepmerge/null | 0.1.5 |
snowflake_custom_role | getindata/database-role/snowflake | 1.1.1 |
snowflake_default_role | getindata/database-role/snowflake | 1.1.1 |
snowflake_schema | getindata/schema/snowflake | 2.0.2 |
this | cloudposse/label/null | 0.25.0 |
Name | Description |
---|---|
catalog | The database parameter that specifies the default catalog to use for Iceberg tables |
data_retention_time_in_days | Data retention days for the database |
database_ownership_grant | The name of the account role to which database ownership will be granted |
database_roles | Snowflake Database roles |
default_ddl_collation | Specifies a default collation specification for all schemas and tables added to the database. |
enable_console_output | If true, enables stdout/stderr fast path logging for anonymous stored procedures |
external_volume | The database parameter that specifies the default external volume to use for Iceberg tables |
is_transient | Specifies a database as transient. Transient databases do not have a Fail-safe period so they do not incur additional storage costs once they leave Time Travel; however, this means they are also not protected by Fail-safe in the event of a data loss |
log_level | Specifies the severity level of messages that should be ingested and made available in the active event table. Valid options are: [TRACE DEBUG INFO WARN ERROR FATAL OFF] |
max_data_extension_time_in_days | Object parameter that specifies the maximum number of days for which Snowflake can extend the data retention period for tables in the database to prevent streams on the tables from becoming stale |
name | Name of the database |
quoted_identifiers_ignore_case | If true, the case of quoted identifiers is ignored |
replace_invalid_characters | Specifies whether to replace invalid UTF-8 characters with the Unicode replacement character () in query results for an Iceberg table |
schemas | This database schemas |
storage_serialization_policy | The storage serialization policy for Iceberg tables that use Snowflake as the catalog. Valid options are: [COMPATIBLE OPTIMIZED] |
suspend_task_after_num_failures | How many times a task must fail in a row before it is automatically suspended. 0 disables auto-suspending |
task_auto_retry_attempts | Maximum automatic retries allowed for a user task |
trace_level | Controls how trace events are ingested into the event table. Valid options are: [ALWAYS ON_EVENT OFF] |
user_task_managed_initial_warehouse_size | The initial size of warehouse to use for managed warehouses in the absence of history |
user_task_minimum_trigger_interval_in_seconds | Minimum amount of time between Triggered Task executions in seconds |
user_task_timeout_ms | User task execution timeout in milliseconds |
Name | Version |
---|---|
snowflake | ~> 0.90 |
Name | Version |
---|---|
terraform | >= 1.3 |
snowflake | ~> 0.90 |
Name | Type |
---|---|
snowflake_database.this | resource |
snowflake_grant_ownership.database_ownership | resource |
Contributions are very welcomed!
Start by reviewing contribution guide and our code of conduct. After that, start coding and ship your changes by creating a new PR.
Apache 2 Licensed. See LICENSE for full details.
Made with contrib.rocks.