Terraform module for managing Snowflake roles. Additionally, this module allows creating multiple grants on different Snowflake resources, specifying other roles to be granted and grantees (other roles and users).
module "snowflake_role" {
source = "github.com/getindata/terraform-snowflake-role"
name = "LOGS_DATABASE_READER"
granted_to_users = ["JANE_SMITH", "JOHN_DOE"]
granted_application_roles = ["SNOWFLAKE.BUDGET_VIEWER", "SNOWFLAKE.COST_INSIGHTS_USER"]
account_grants = [
{
privileges = ["CREATE DATABASE"]
}
]
account_objects_grants = {
"DATABASE" = [
{
privileges = ["USAGE"]
object_name = "LOGS_DB"
}
]
}
schema_grants = [
{
database_name = "LOGS_DB"
schema_name = "BRONZE"
privileges = ["USAGE"]
}
]
schema_objects_grants = {
TABLE = [
{
database_name = "LOGS_DB"
schema_name = "BRONZE"
on_future = true
privileges = ["SELECT"]
}
]
VIEW = [
{
database_name = snowflake_database.this.name
on_future = true
all_privileges = 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_account_roleresource instead of provider-deprecatedsnowflake_role - Switched to
snowflake_grant_privileges_to_account_roleresource instead of provider-removedsnowflake_*_grant - Switched to
snowflake_grant_account_roleresource instead of provider-removedsnowflake_role_grants - Switched to
snowflake_grant_ownershipresource instead of provider-removedsnowflake_role_ownership_grant - Variable
account_grantstype changed fromlist(string)tolist(object({..})) - Variable
schema_grantstype changed - Below variables were removed and replaced with aggregated / complex
account_object_grantsandschema_object_grants:database_grantstable_grantsexternal_table_grantsview_grantsdynamic_table_grants
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.
For more information, refer to variables.tf, list of inputs below and Snowflake provider documentation
Due to replacement of nulllabel (context.tf) with context provider, some breaking changes were introduced in v3.0.0 version of this module.
List od code and variable (API) changes:
- Removed
context.tffile (a single-file module with additonal variables), which implied a removal of all its variables (exceptname):descriptor_formatslabel_value_caselabel_key_caseid_length_limitregex_replace_charslabel_orderadditional_tag_maptagslabels_as_tagsattributesdelimiterstageenvironmenttenantnamespaceenabledcontext
- Remove support
enabledflag - that might cause some backward compatibility issues with terraform state (please take into account that propermoveclauses were added to minimize the impact), but proceed with caution - Additional
contextprovider configuration - New variables were added, to allow naming configuration via
contextprovider:context_templatesname_schema
Due to rename of Snowflake terraform provider source, all versions.tf files were updated accordingly.
Please keep in mind to mirror this change in your own repos also.
For more information about provider rename, refer to Snowflake documentation.
| Name | Description | Type | Default | Required |
|---|---|---|---|---|
| account_grants | Grants on a account level | list(object({ |
[] |
no |
| account_objects_grants | Grants on account object level. Account objects list: USER | RESOURCE MONITOR | WAREHOUSE | COMPUTE POOL | DATABASE | INTEGRATION | FAILOVER GROUP | REPLICATION GROUP | EXTERNAL VOLUME Object type is used as a key in the map. Exmpale usage: account_object_grants = {Note: You can find a list of all object types here |
map(list(object({ |
{} |
no |
| comment | Role description | string |
null |
no |
| context_templates | Map of context templates used for naming conventions - this variable supersedes naming_scheme.properties and naming_scheme.delimiter configuration |
map(string) |
{} |
no |
| granted_application_roles | Application Roles granted to this role | list(string) |
[] |
no |
| granted_database_roles | Database Roles granted to this role | list(string) |
[] |
no |
| granted_roles | Roles granted to this role | list(string) |
[] |
no |
| granted_to_roles | Roles which this role is granted to | list(string) |
[] |
no |
| granted_to_users | Users which this role is granted to | list(string) |
[] |
no |
| name | Name of the resource | string |
n/a | yes |
| name_scheme | Naming scheme configuration for the resource. This configuration is used to generate names using context provider: - properties - list of properties to use when creating the name - is superseded by var.context_templates- delimiter - delimited used to create the name from properties - is superseded by var.context_templates- context_template_name - name of the context template used to create the name- replace_chars_regex - regex to use for replacing characters in property-values created by the provider - any characters that match the regex will be removed from the name- extra_values - map of extra label-value pairs, used to create a name- uppercase - convert name to uppercase |
object({ |
{} |
no |
| role_ownership_grant | The name of the role to grant ownership | string |
null |
no |
| schema_grants | Grants on a schema level | list(object({ |
[] |
no |
| schema_objects_grants | Grants on a schema object level Example usage: schema_objects_grants = {Note: If you don't provide a schema_name, the grants will be created for all objects of that type in the database.You can find a list of all object types here |
map(list(object({ |
{} |
no |
No modules.
| Name | Description |
|---|---|
| name | Name of the role |
| Name | Version |
|---|---|
| context | >=0.4.0 |
| snowflake | >= 0.94 |
| Name | Version |
|---|---|
| terraform | >= 1.3 |
| context | >=0.4.0 |
| snowflake | >= 0.94 |
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.