Skip to content

Commit 80e5dcc

Browse files
author
Daniel Noworyta
committed
chore: added enabled flag (bool) to database role creation
1 parent 44a72f6 commit 80e5dcc

File tree

5 files changed

+27
-21
lines changed

5 files changed

+27
-21
lines changed

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
Terraform module for Snowflake stage management.
1616

1717
* Creates Snowflake stage
18-
* Can create custom Snowflake databse-roles with role-to-role assignments
18+
* Can create custom Snowflake database-roles with role-to-role assignments
1919
* Can create a set of default roles to simplify access management:
2020
* `READONLY` - granted `USAGE` or `READ` privilages
21-
* `READWRITE` - granted `WRITE` privilages
22-
* `ADMIN` - granted `READ`, `WRITE` privilages (role can be additionally granted with `OWNER` attribute when specified)
21+
* `READWRITE` - granted `WRITE` privileges
22+
* `ADMIN` - granted `READ`, `WRITE` privileges (role can be additionally granted with `OWNER` attribute when specified)
2323

2424
## USAGE
2525

@@ -35,7 +35,7 @@ module "snowflake_stage" {
3535
url = "s3://com.example.bucket/prefix"
3636
credentials = "AWS_KEY_ID='${var.example_aws_key_id}' AWS_SECRET_KEY='${var.example_aws_secret_key}'"
3737
38-
create_default_roles = true
38+
create_default_database_roles = true
3939
}
4040
```
4141

@@ -48,11 +48,11 @@ module "snowflake_stage" {
4848
## Breaking changes in v2.x of the module
4949
Due to breaking changes in Snowflake provider and additional code optimizations, **breaking changes** were introduced in `v2.0.0` version of this module.
5050

51-
Lst of code and variable (API) changes:
51+
List of code and variable (API) changes:
5252
- Switched to `snowflake_grant_ownership` resource instead of provider-removed `snowflake_role_ownership_grant`
5353
- Switched to `snowflake_database_role` module to leverage new `database_roles` mechanism
5454
- `default_roles` and `custom_roles` are now combined and managed by single module
55-
- `create_default_roles` variable was renamed to `create_default_databse_roles`
55+
- `create_default_roles` variable was renamed to `create_default_database_roles`
5656
- `roles` variable map received following additions:
5757
- `all_privileges` - optional, bool
5858
- `on_all` - optional, bool, defaults to false
@@ -88,7 +88,7 @@ For more information, refer to [variables.tf](variables.tf), list of inputs belo
8888
| <a name="input_comment"></a> [comment](#input\_comment) | Specifies a comment for the stage | `string` | `null` | no |
8989
| <a name="input_context"></a> [context](#input\_context) | Single object for setting entire context at once.<br>See description of individual variables for details.<br>Leave string and numeric variables as `null` to use default value.<br>Individual variable settings (non-null) override settings in context object,<br>except for attributes, tags, and additional\_tag\_map, which are merged. | `any` | <pre>{<br> "additional_tag_map": {},<br> "attributes": [],<br> "delimiter": null,<br> "descriptor_formats": {},<br> "enabled": true,<br> "environment": null,<br> "id_length_limit": null,<br> "label_key_case": null,<br> "label_order": [],<br> "label_value_case": null,<br> "labels_as_tags": [<br> "unset"<br> ],<br> "name": null,<br> "namespace": null,<br> "regex_replace_chars": null,<br> "stage": null,<br> "tags": {},<br> "tenant": null<br>}</pre> | no |
9090
| <a name="input_copy_options"></a> [copy\_options](#input\_copy\_options) | Specifies the copy options for the stage | `string` | `null` | no |
91-
| <a name="input_create_default_databse_roles"></a> [create\_default\_databse\_roles](#input\_create\_default\_databse\_roles) | Whether the default database roles should be created | `bool` | `false` | no |
91+
| <a name="input_create_default_database_roles"></a> [create\_default\_database\_roles](#input\_create\_default\_database\_roles) | Whether the default database roles should be created | `bool` | `false` | no |
9292
| <a name="input_credentials"></a> [credentials](#input\_credentials) | Specifies the credentials for the stage | `string` | `null` | no |
9393
| <a name="input_database"></a> [database](#input\_database) | The database in which to create the stage | `string` | n/a | yes |
9494
| <a name="input_delimiter"></a> [delimiter](#input\_delimiter) | Delimiter to be used between ID elements.<br>Defaults to `-` (hyphen). Set to `""` to use no delimiter at all. | `string` | `null` | no |
@@ -107,7 +107,7 @@ For more information, refer to [variables.tf](variables.tf), list of inputs belo
107107
| <a name="input_name"></a> [name](#input\_name) | ID element. Usually the component or solution name, e.g. 'app' or 'jenkins'.<br>This is the only ID element not also included as a `tag`.<br>The "name" tag is set to the full `id` string. There is no tag with the value of the `name` input. | `string` | `null` | no |
108108
| <a name="input_namespace"></a> [namespace](#input\_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 |
109109
| <a name="input_regex_replace_chars"></a> [regex\_replace\_chars](#input\_regex\_replace\_chars) | Terraform regular expression (regex) string.<br>Characters matching the regex will be removed from the ID elements.<br>If not set, `"/[^a-zA-Z0-9-]/"` is used to remove all characters other than hyphens, letters and digits. | `string` | `null` | no |
110-
| <a name="input_roles"></a> [roles](#input\_roles) | Database roles created in the stage scope | <pre>map(object({<br> with_grant_option = optional(bool)<br> granted_to_roles = optional(list(string))<br> granted_to_database_roles = optional(list(string))<br> granted_database_roles = optional(list(string))<br> stage_grants = optional(list(string))<br> all_privileges = optional(bool)<br> on_all = optional(bool, false)<br> schema_name = optional(string)<br> on_future = optional(bool, false)<br> }))</pre> | `{}` | no |
110+
| <a name="input_roles"></a> [roles](#input\_roles) | Database roles created in the stage scope | <pre>map(object({<br> enabled = optional(bool, true)<br> with_grant_option = optional(bool)<br> granted_to_roles = optional(list(string))<br> granted_to_database_roles = optional(list(string))<br> granted_database_roles = optional(list(string))<br> stage_grants = optional(list(string))<br> all_privileges = optional(bool)<br> on_all = optional(bool, false)<br> schema_name = optional(string)<br> on_future = optional(bool, false)<br> }))</pre> | `{}` | no |
111111
| <a name="input_schema"></a> [schema](#input\_schema) | The schema in which to create the stage | `string` | n/a | yes |
112112
| <a name="input_snowflake_iam_user"></a> [snowflake\_iam\_user](#input\_snowflake\_iam\_user) | Specifies the Snowflake IAM user | `string` | `null` | no |
113113
| <a name="input_stage"></a> [stage](#input\_stage) | ID element. Usually used to indicate role, e.g. 'prod', 'staging', 'source', 'build', 'test', 'deploy', 'release' | `string` | `null` | no |
@@ -130,7 +130,7 @@ For more information, refer to [variables.tf](variables.tf), list of inputs belo
130130

131131
| Name | Description |
132132
|------|-------------|
133-
| <a name="output_databse_roles"></a> [databse\_roles](#output\_databse\_roles) | This stage access roles |
133+
| <a name="output_database_roles"></a> [database\_roles](#output\_database\_roles) | This stage access roles |
134134
| <a name="output_name"></a> [name](#output\_name) | Name of the stage |
135135

136136
## Providers

examples/complete/main.tf

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ module "internal_stage" {
3636

3737
comment = "This is my ingest stage"
3838

39-
create_default_databse_roles = true
39+
create_default_database_roles = true
4040

4141
roles = {
42-
readonly = { # Modifies readonly default role
42+
readonly = { # Modifies readonly default database role
4343
granted_to_database_roles = [
4444
"${snowflake_database.this.name}.${snowflake_database_role.db_role_1.name}"
4545
]
@@ -49,20 +49,23 @@ module "internal_stage" {
4949
]
5050
stage_grants = ["READ", "WRITE"]
5151
}
52-
admin = { # Modifies admin default role
52+
admin = { # Modifies admin default database role
5353
granted_database_roles = [
5454
"${snowflake_database.this.name}.${snowflake_database_role.db_role_2.name}",
5555
]
5656
}
57-
role_1 = { # User created database role
57+
readwrite = {
58+
enabled = false # Disables readwrite default database role creation
59+
}
60+
role_1 = { # Database role created by user input
5861
granted_to_roles = [snowflake_role.role_1.name]
5962
granted_to_database_roles = ["${snowflake_database.this.name}.${snowflake_database_role.db_role_3.name}"]
6063
all_privileges = true
6164
with_grant_option = true
6265
on_future = true
6366
on_all = true
6467
}
65-
role_2 = { # User created database role
68+
role_2 = { # Database role created by user input
6669
granted_to_database_roles = ["${snowflake_database.this.name}.${snowflake_database_role.db_role_3.name}"]
6770
stage_grants = ["READ", "WRITE"]
6871
with_grant_option = false
@@ -71,5 +74,5 @@ module "internal_stage" {
7174
}
7275
}
7376

74-
stage_ownership_grant = "role_1"
77+
stage_ownership_grant = "role_1" # When destroying, please read README.md
7578
}

locals.tf

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,17 @@ locals {
99

1010
is_internal = var.url == null
1111

12-
default_roles_definition = var.create_default_databse_roles ? {
12+
default_roles_definition = var.create_default_database_roles ? {
1313
readonly = {
14+
enabled = true
1415
stage_grants = local.is_internal ? ["READ"] : ["USAGE"]
1516
}
1617
readwrite = {
18+
enabled = true
1719
stage_grants = local.is_internal ? ["READ", "WRITE"] : ["USAGE"]
1820
}
1921
admin = {
22+
enabled = true
2023
stage_grants = local.is_internal ? ["READ", "WRITE"] : ["USAGE"]
2124
}
2225
} : {}
@@ -26,10 +29,9 @@ locals {
2629
if v != null
2730
} }
2831

29-
roles_definition = module.roles_deep_merge.merged
30-
3132
roles = {
32-
for role_name, role in local.roles_definition : role_name => role
33+
for role_name, role in module.roles_deep_merge.merged : role_name => role
34+
if role_name != null && role.enabled
3335
}
3436
}
3537

outputs.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ output "name" {
33
value = one(snowflake_stage.this[*].name)
44
}
55

6-
output "databse_roles" {
6+
output "database_roles" {
77
description = "This stage access roles"
88
value = local.roles
99
}

variables.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ variable "url" {
7474
default = null
7575
}
7676

77-
variable "create_default_databse_roles" {
77+
variable "create_default_database_roles" {
7878
description = "Whether the default database roles should be created"
7979
type = bool
8080
default = false
@@ -83,6 +83,7 @@ variable "create_default_databse_roles" {
8383
variable "roles" {
8484
description = "Database roles created in the stage scope"
8585
type = map(object({
86+
enabled = optional(bool, true)
8687
with_grant_option = optional(bool)
8788
granted_to_roles = optional(list(string))
8889
granted_to_database_roles = optional(list(string))

0 commit comments

Comments
 (0)