Skip to content

Commit 78b87ac

Browse files
authored
Merge pull request #10 from getindata/fix/default_secondary_roles
fix: Remove grants for secondary roles + add proper validation to default_secondary_roles input variable
2 parents 32d0bcc + 895a5c8 commit 78b87ac

File tree

4 files changed

+11
-15
lines changed

4 files changed

+11
-15
lines changed

README.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ module "terraform_snowflake_user" {
4545
| <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 |
4646
| <a name="input_default_namespace"></a> [default\_namespace](#input\_default\_namespace) | Specifies the namespace (database only or database and schema) that is active by default for the user's session upon login. | `string` | `null` | no |
4747
| <a name="input_default_role"></a> [default\_role](#input\_default\_role) | Specifies the role that is active by default for the user's session upon login. | `string` | `null` | no |
48-
| <a name="input_default_secondary_roles"></a> [default\_secondary\_roles](#input\_default\_secondary\_roles) | Specifies the set of secondary roles that are active for the user's session upon login. | `list(string)` | `[]` | no |
48+
| <a name="input_default_secondary_roles"></a> [default\_secondary\_roles](#input\_default\_secondary\_roles) | Specifies the set of secondary roles that are active for the user's session upon login. <br> Secondary roles are a set of roles that authorize any SQL action other than the execution of CREATE <object> statements. <br> Currently only ["ALL"] value is supported | `list(string)` | `[]` | no |
4949
| <a name="input_default_warehouse"></a> [default\_warehouse](#input\_default\_warehouse) | Specifies the virtual warehouse that is active by default for the user's session upon login. | `string` | `null` | no |
5050
| <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 |
5151
| <a name="input_descriptor_formats"></a> [descriptor\_formats](#input\_descriptor\_formats) | Describe additional descriptors to be output in the `descriptors` output map.<br>Map of maps. Keys are names of descriptors. Values are maps of the form<br>`{<br> format = string<br> labels = list(string)<br>}`<br>(Type is `any` so the map values can later be enhanced to provide additional options.)<br>`format` is a Terraform format string to be passed to the `format()` function.<br>`labels` is a list of labels, in order, to pass to `format()` function.<br>Label values will be normalized before being passed to `format()` so they will be<br>identical to how they appear in `id`.<br>Default is `{}` (`descriptors` output will be empty). | `any` | `{}` | no |
@@ -122,7 +122,6 @@ module "terraform_snowflake_user" {
122122
|------|------|
123123
| [random_password.this](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/password) | resource |
124124
| [snowflake_role_grants.default_role](https://registry.terraform.io/providers/Snowflake-Labs/snowflake/latest/docs/resources/role_grants) | resource |
125-
| [snowflake_role_grants.default_secondary_roles](https://registry.terraform.io/providers/Snowflake-Labs/snowflake/latest/docs/resources/role_grants) | resource |
126125
| [snowflake_user.this](https://registry.terraform.io/providers/Snowflake-Labs/snowflake/latest/docs/resources/user) | resource |
127126
| [tls_private_key.this](https://registry.terraform.io/providers/hashicorp/tls/latest/docs/resources/private_key) | resource |
128127
<!-- END_TF_DOCS -->

examples/complete/main.tf

+1-5
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@ resource "snowflake_role" "user_role" {
22
name = "SNOWFLAKE_USER_ROLE"
33
}
44

5-
resource "snowflake_role" "secondary_role" {
6-
name = "SNOWFLAKE_SECOND_ROLE"
7-
}
8-
95
module "terraform_snowflake_user" {
106
source = "../../"
117
context = module.this.context
@@ -14,5 +10,5 @@ module "terraform_snowflake_user" {
1410
generate_password = true
1511

1612
default_role = resource.snowflake_role.user_role.name
17-
default_secondary_roles = [resource.snowflake_role.secondary_role.name]
13+
default_secondary_roles = ["ALL"]
1814
}

main.tf

-7
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,3 @@ resource "snowflake_role_grants" "default_role" {
5353
role_name = var.default_role
5454
users = [one(resource.snowflake_user.this[*].name)]
5555
}
56-
57-
resource "snowflake_role_grants" "default_secondary_roles" {
58-
for_each = module.this.enabled && var.grant_default_roles ? toset(var.default_secondary_roles) : []
59-
60-
role_name = each.key
61-
users = [one(resource.snowflake_user.this[*].name)]
62-
}

variables.tf

+9-1
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,17 @@ variable "default_role" {
5353
}
5454

5555
variable "default_secondary_roles" {
56-
description = "Specifies the set of secondary roles that are active for the user's session upon login."
56+
description = <<EOT
57+
Specifies the set of secondary roles that are active for the user's session upon login.
58+
Secondary roles are a set of roles that authorize any SQL action other than the execution of CREATE <object> statements.
59+
Currently only ["ALL"] value is supported
60+
EOT
5761
type = list(string)
5862
default = []
63+
validation {
64+
condition = var.default_secondary_roles == null || contains([0, 1], length(var.default_secondary_roles)) || contains(var.default_secondary_roles, "ALL")
65+
error_message = "Currently only [\"ALL\"] value is supported by Snowflake provider."
66+
}
5967
}
6068

6169
variable "rsa_public_key" {

0 commit comments

Comments
 (0)