Skip to content

Commit 6d574f8

Browse files
feat: RSA key configuration and more (#2)
Adds the ability to configure an RSA key for the snowflake user. Also adds the ability to configure the names for the resources in case the user wants to use a specific naming scheme.
1 parent 6c8108a commit 6d574f8

File tree

5 files changed

+55
-9
lines changed

5 files changed

+55
-9
lines changed

README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,23 @@ This module **does not** create a reader role that can be used to view the data.
1414
| Name | Version |
1515
|------|---------|
1616
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13 |
17-
| <a name="requirement_snowflake"></a> [snowflake](#requirement\_snowflake) | >= 0.83.1 |
17+
| <a name="requirement_snowflake"></a> [snowflake](#requirement\_snowflake) | ~> 0.83.1 |
1818

1919
## Inputs
2020

2121
| Name | Description | Type | Default | Required |
2222
|------|-------------|------|---------|:--------:|
2323
| <a name="input_database_name"></a> [database\_name](#input\_database\_name) | The name of the Snowflake database to use | `string` | n/a | yes |
24-
| <a name="input_fullstory_cidr_ipv4"></a> [fullstory\_cidr\_ipv4](#input\_fullstory\_cidr\_ipv4) | The CIDR block that Fullstory will use to connect to the Redshift cluster. | `string` | `""` | no |
24+
| <a name="input_disable_password"></a> [disable\_password](#input\_disable\_password) | Whether to disable the password for the Snowflake user. If true, the user will only be able to authenticate using the RSA public key. | `bool` | `false` | no |
25+
| <a name="input_fullstory_cidr_ipv4"></a> [fullstory\_cidr\_ipv4](#input\_fullstory\_cidr\_ipv4) | The CIDR block that Fullstory will use to connect to Snowflake. | `string` | `""` | no |
2526
| <a name="input_fullstory_data_center"></a> [fullstory\_data\_center](#input\_fullstory\_data\_center) | The data center where your Fullstory account is hosted. Either 'NA1' or 'EU1'. See https://help.fullstory.com/hc/en-us/articles/8901113940375-Fullstory-Data-Residency for more information. | `string` | `"NA1"` | no |
2627
| <a name="input_fullstory_storage_allowed_locations"></a> [fullstory\_storage\_allowed\_locations](#input\_fullstory\_storage\_allowed\_locations) | The list of allowed locations for the storage provider. This is an advanced option and should only be changed if instructed by Fullstory. Ex. <cloud>://<bucket>/<path>/ | `list(string)` | <pre>[<br> "gcs://fullstoryapp-warehouse-sync-bundles"<br>]</pre> | no |
2728
| <a name="input_fullstory_storage_provider"></a> [fullstory\_storage\_provider](#input\_fullstory\_storage\_provider) | The storage provider to use. Either 'S3', 'GCS' or 'AZURE'. This is an advanced option and should only be changed if instructed by Fullstory. | `string` | `"GCS"` | no |
29+
| <a name="input_password"></a> [password](#input\_password) | The password to use for the Snowflake user. | `string` | `null` | no |
30+
| <a name="input_role_name"></a> [role\_name](#input\_role\_name) | The name of the Snowflake role to create. | `string` | `null` | no |
31+
| <a name="input_rsa_public_key"></a> [rsa\_public\_key](#input\_rsa\_public\_key) | The RSA public key to use for the Snowflake user. Must be on 1 line without header and trailer. | `string` | `null` | no |
32+
| <a name="input_rsa_public_key_2"></a> [rsa\_public\_key\_2](#input\_rsa\_public\_key\_2) | The second RSA public key to use for the Snowflake user. Used when rotating keys. Must be on 1 line without header and trailer. | `string` | `null` | no |
33+
| <a name="input_stage_name"></a> [stage\_name](#input\_stage\_name) | The name of the Snowflake stage to create. | `string` | `null` | no |
2834
| <a name="input_suffix"></a> [suffix](#input\_suffix) | The suffix to append to the names of the resources created by this module so that the module can be instantiated many times. Must only contain letters. | `string` | n/a | yes |
2935
| <a name="input_warehouse_name"></a> [warehouse\_name](#input\_warehouse\_name) | The name of the Snowflake warehouse to use. | `string` | n/a | yes |
3036

@@ -33,7 +39,7 @@ This module **does not** create a reader role that can be used to view the data.
3339
| Name | Description |
3440
|------|-------------|
3541
| <a name="output_gcs_storage_integration"></a> [gcs\_storage\_integration](#output\_gcs\_storage\_integration) | The name of the GCS storage integration that can be used in the Fullstory app when configuring the Snowflake integration. |
36-
| <a name="output_password"></a> [password](#output\_password) | The Fullstory password that can be used in the Fullstory app when configuring the Snowflake integration. |
42+
| <a name="output_password"></a> [password](#output\_password) | The password for the configured user that can be used in the Fullstory app when configuring the Snowflake integration. Will be empty if `disable_password` is true. |
3743
| <a name="output_role"></a> [role](#output\_role) | The Fullstory role that can be used in the Fullstory app when configuring the Snowflake integration. |
3844
| <a name="output_username"></a> [username](#output\_username) | The Fullstory username that can be used in the Fullstory app when configuring the Snowflake integration. |
3945

config.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ terraform {
44
required_providers {
55
snowflake = {
66
source = "Snowflake-Labs/snowflake"
7-
version = ">= 0.83.1"
7+
version = "~> 0.83.1"
88
configuration_aliases = [
99
snowflake.account_admin,
1010
snowflake.security_admin,

main.tf

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ provider "snowflake" {
1717

1818
resource "snowflake_role" "main" {
1919
provider = snowflake.security_admin
20-
name = "FULLSTORY_WAREHOUSE_SETUP_${local.suffix}"
20+
name = coalesce(var.role_name, "FULLSTORY_WAREHOUSE_SETUP_${local.suffix}")
2121
}
2222

2323
resource "snowflake_grant_privileges_to_role" "database" {
@@ -41,6 +41,7 @@ resource "snowflake_grant_privileges_to_role" "warehouse" {
4141
}
4242

4343
resource "random_password" "main" {
44+
count = (var.disable_password || var.password != null) ? 0 : 1
4445
length = 16
4546
special = true
4647
override_special = "!#$%&*()-_=+[]{}<>:?"
@@ -51,7 +52,9 @@ resource "snowflake_user" "main" {
5152
name = "FULLSTORY_WAREHOUSE_SETUP_${local.suffix}"
5253
default_warehouse = var.warehouse_name
5354
default_role = snowflake_role.main.name
54-
password = random_password.main.result
55+
password = var.disable_password ? "" : (var.password != null ? var.password : random_password.main[0].result)
56+
rsa_public_key = var.rsa_public_key
57+
rsa_public_key_2 = var.rsa_public_key_2
5558
}
5659

5760
resource "snowflake_grant_privileges_to_role" "user" {
@@ -74,7 +77,7 @@ resource "snowflake_role_grants" "main" {
7477

7578
resource "snowflake_storage_integration" "main" {
7679
provider = snowflake.account_admin
77-
name = "FULLSTORY_STAGE_${local.suffix}"
80+
name = coalesce(var.stage_name, "FULLSTORY_STAGE_${local.suffix}")
7881
comment = "Stage for FullStory data"
7982
type = "EXTERNAL_STAGE"
8083
enabled = true

outputs.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ output "username" {
99
}
1010

1111
output "password" {
12-
description = "The Fullstory password that can be used in the Fullstory app when configuring the Snowflake integration."
12+
description = "The password for the configured user that can be used in the Fullstory app when configuring the Snowflake integration. Will be empty if `disable_password` is true."
1313
value = snowflake_user.main.password
1414
sensitive = true
1515
}

variables.tf

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,28 @@ variable "database_name" {
33
description = "The name of the Snowflake database to use"
44
}
55

6+
variable "role_name" {
7+
type = string
8+
description = "The name of the Snowflake role to create."
9+
default = null
10+
}
11+
12+
variable "stage_name" {
13+
type = string
14+
description = "The name of the Snowflake stage to create."
15+
default = null
16+
}
17+
18+
variable "password" {
19+
type = string
20+
description = "The password to use for the Snowflake user."
21+
default = null
22+
sensitive = true
23+
}
24+
625
variable "fullstory_cidr_ipv4" {
726
type = string
8-
description = "The CIDR block that Fullstory will use to connect to the Redshift cluster."
27+
description = "The CIDR block that Fullstory will use to connect to Snowflake."
928
default = ""
1029
}
1130

@@ -48,3 +67,21 @@ variable "warehouse_name" {
4867
type = string
4968
description = "The name of the Snowflake warehouse to use."
5069
}
70+
71+
variable "disable_password" {
72+
type = bool
73+
default = false
74+
description = "Whether to disable the password for the Snowflake user. If true, the user will only be able to authenticate using the RSA public key."
75+
}
76+
77+
variable "rsa_public_key" {
78+
type = string
79+
description = "The RSA public key to use for the Snowflake user. Must be on 1 line without header and trailer."
80+
default = null
81+
}
82+
83+
variable "rsa_public_key_2" {
84+
type = string
85+
description = "The second RSA public key to use for the Snowflake user. Used when rotating keys. Must be on 1 line without header and trailer."
86+
default = null
87+
}

0 commit comments

Comments
 (0)