|
1 |
| -# Example resource that outputs the input value and |
2 |
| -# echoes it's base64 encoded version locally |
| 1 | +/* |
| 2 | +* # Snowflake User |
| 3 | +* |
| 4 | +* Terraform module can: |
| 5 | +* * Create and manage Snowflake Users |
| 6 | +* * Automatically generate RSA private and public keys for the user |
| 7 | +*/ |
| 8 | +module "user_label" { |
| 9 | + source = "cloudposse/label/null" |
| 10 | + version = "0.25.0" |
| 11 | + context = module.this.context |
3 | 12 |
|
4 |
| -resource "null_resource" "output_input" { |
5 |
| - count = local.enabled ? 1 : 0 |
| 13 | + delimiter = coalesce(module.this.context.delimiter, "_") |
| 14 | + regex_replace_chars = coalesce(module.this.context.regex_replace_chars, "/[^_a-zA-Z0-9]/") |
| 15 | + label_value_case = coalesce(module.this.context.label_value_case, "upper") |
| 16 | + name = "snowflake-user" |
6 | 17 |
|
7 |
| - triggers = { |
8 |
| - name = local.name_from_descriptor |
9 |
| - input = var.example_var |
10 |
| - } |
| 18 | +} |
| 19 | + |
| 20 | +resource "tls_private_key" "this" { |
| 21 | + count = local.generate_rsa_key ? 1 : 0 |
| 22 | + |
| 23 | + algorithm = "RSA" |
| 24 | + rsa_bits = 4096 |
| 25 | +} |
| 26 | +resource "random_password" "this" { |
| 27 | + count = local.generate_password ? 1 : 0 |
| 28 | + length = 16 |
| 29 | + special = true |
| 30 | + override_special = "!#$%&*()-_=+[]{}<>:?" |
| 31 | +} |
| 32 | + |
| 33 | +resource "snowflake_user" "this" { |
| 34 | + count = module.this.enabled ? 1 : 0 |
| 35 | + |
| 36 | + name = local.name_from_descriptor |
| 37 | + login_name = var.login_name |
| 38 | + display_name = var.display_name |
| 39 | + comment = var.comment |
| 40 | + |
| 41 | + password = one(random_password.this[*].result) |
| 42 | + must_change_password = true # When password set here - always change password on login |
| 43 | + |
| 44 | + email = var.email |
| 45 | + first_name = var.first_name |
| 46 | + last_name = var.last_name |
| 47 | + |
| 48 | + default_namespace = var.default_namespace |
| 49 | + default_warehouse = var.default_warehouse |
| 50 | + default_role = var.default_role |
| 51 | + default_secondary_roles = var.default_secondary_roles |
11 | 52 |
|
12 |
| - provisioner "local-exec" { |
13 |
| - command = "echo ${var.example_var} | base64" |
14 |
| - } |
| 53 | + rsa_public_key = local.rsa_public_key |
| 54 | + rsa_public_key_2 = var.rsa_public_key_2 |
15 | 55 | }
|
0 commit comments