Skip to content

Commit 7e25e3a

Browse files
authored
fix: allow multiple cidr blocks (#3)
1 parent 6d574f8 commit 7e25e3a

File tree

3 files changed

+31
-21
lines changed

3 files changed

+31
-21
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ This module **does not** create a reader role that can be used to view the data.
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 |
2424
| <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 |
25+
| <a name="input_fullstory_cidr_ipv4"></a> [fullstory\_cidr\_ipv4](#input\_fullstory\_cidr\_ipv4) | DEPRECATED: Use fullstory\_cidr\_ipv4s. The CIDR block that Fullstory will use to connect to Snowflake. | `string` | `""` | no |
26+
| <a name="input_fullstory_cidr_ipv4s"></a> [fullstory\_cidr\_ipv4s](#input\_fullstory\_cidr\_ipv4s) | The CIDR blocks that Fullstory will use to connect to Snowflake. | `list(string)` | `[]` | no |
2627
| <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 |
2728
| <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 |
2829
| <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 |

main.tf

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
locals {
2-
fullstory_cidr_ipv4 = var.fullstory_cidr_ipv4 != "" ? var.fullstory_cidr_ipv4 : (var.fullstory_data_center == "EU1" ? "34.89.210.80/29" : "8.35.195.0/29")
3-
suffix = upper(var.suffix)
2+
fullstory_default_cidr_ip4 = var.fullstory_data_center == "EU1" ? "34.89.210.80/29" : "8.35.195.0/29"
3+
fullstory_cidr_ipv4 = var.fullstory_cidr_ipv4 != "" ? var.fullstory_cidr_ipv4 : local.fullstory_default_cidr_ip4
4+
fullstory_cidr_ipv4s = length(var.fullstory_cidr_ipv4s) > 0 ? var.fullstory_cidr_ipv4s : [local.fullstory_cidr_ipv4]
5+
6+
suffix = upper(var.suffix)
47
}
58

69
provider "snowflake" {
@@ -41,7 +44,7 @@ resource "snowflake_grant_privileges_to_role" "warehouse" {
4144
}
4245

4346
resource "random_password" "main" {
44-
count = (var.disable_password || var.password != null) ? 0 : 1
47+
count = (var.disable_password || var.password != null) ? 0 : 1
4548
length = 16
4649
special = true
4750
override_special = "!#$%&*()-_=+[]{}<>:?"
@@ -53,8 +56,8 @@ resource "snowflake_user" "main" {
5356
default_warehouse = var.warehouse_name
5457
default_role = snowflake_role.main.name
5558
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
59+
rsa_public_key = var.rsa_public_key
60+
rsa_public_key_2 = var.rsa_public_key_2
5861
}
5962

6063
resource "snowflake_grant_privileges_to_role" "user" {
@@ -99,7 +102,7 @@ resource "snowflake_grant_privileges_to_role" "integration" {
99102
resource "snowflake_network_policy" "main" {
100103
provider = snowflake.security_admin
101104
name = "FULLSTORY_NETWORK_POLICY_${local.suffix}"
102-
allowed_ip_list = [local.fullstory_cidr_ipv4]
105+
allowed_ip_list = local.fullstory_cidr_ipv4s
103106
}
104107

105108
resource "snowflake_network_policy_attachment" "main" {

variables.tf

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,36 @@ variable "database_name" {
44
}
55

66
variable "role_name" {
7-
type = string
7+
type = string
88
description = "The name of the Snowflake role to create."
9-
default = null
9+
default = null
1010
}
1111

1212
variable "stage_name" {
13-
type = string
13+
type = string
1414
description = "The name of the Snowflake stage to create."
15-
default = null
15+
default = null
1616
}
1717

1818
variable "password" {
19-
type = string
19+
type = string
2020
description = "The password to use for the Snowflake user."
21-
default = null
22-
sensitive = true
21+
default = null
22+
sensitive = true
2323
}
2424

2525
variable "fullstory_cidr_ipv4" {
2626
type = string
27-
description = "The CIDR block that Fullstory will use to connect to Snowflake."
27+
description = "DEPRECATED: Use fullstory_cidr_ipv4s. The CIDR block that Fullstory will use to connect to Snowflake."
2828
default = ""
2929
}
3030

31+
variable "fullstory_cidr_ipv4s" {
32+
type = list(string)
33+
description = "The CIDR blocks that Fullstory will use to connect to Snowflake."
34+
default = []
35+
}
36+
3137
variable "fullstory_data_center" {
3238
type = string
3339
description = "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."
@@ -69,19 +75,19 @@ variable "warehouse_name" {
6975
}
7076

7177
variable "disable_password" {
72-
type = bool
73-
default = false
78+
type = bool
79+
default = false
7480
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."
7581
}
7682

7783
variable "rsa_public_key" {
78-
type = string
84+
type = string
7985
description = "The RSA public key to use for the Snowflake user. Must be on 1 line without header and trailer."
80-
default = null
86+
default = null
8187
}
8288

8389
variable "rsa_public_key_2" {
84-
type = string
90+
type = string
8591
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
92+
default = null
8793
}

0 commit comments

Comments
 (0)