Skip to content

Commit c0f9f06

Browse files
Adding Sentniel user creation to the module
1 parent 03c38e4 commit c0f9f06

File tree

5 files changed

+49
-19
lines changed

5 files changed

+49
-19
lines changed

terraform/snowflake/environments/prd/main.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ module "policies" {
112112
# inputs
113113
okta_integration_name = var.okta_integration_name # or null to skip Okta/SAML policies
114114
policies_database_name = "POLICIES"
115+
116+
# Pass the outputs from the elt module as inputs to the policies module
117+
logging_warehouse_name = module.elt.logging_warehouse_name
118+
logger_role_name = module.elt.logger_role_name
115119
}
116120

117121
##############################################################
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
output "logger_role_name" {
2+
description = "The name of the logger role."
3+
value = snowflake_account_role.logger.name
4+
}
5+
6+
output "logging_warehouse_name" {
7+
description = "The name of the logging warehouse."
8+
value = module.logging.name
9+
}

terraform/snowflake/modules/elt/users.tf

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,6 @@ resource "snowflake_service_user" "github_ci" {
5050
default_role = snowflake_account_role.reader.name
5151
}
5252

53-
resource "snowflake_legacy_service_user" "sentinel" {
54-
provider = snowflake.useradmin
55-
name = "SENTINEL_SVC_USER_${var.environment}"
56-
comment = "Service user for Sentinel"
57-
lifecycle {
58-
ignore_changes = [rsa_public_key]
59-
}
60-
61-
default_warehouse = module.logging.name
62-
default_role = snowflake_account_role.logger.name
63-
}
64-
6553
######################################
6654
# Role Grants #
6755
######################################
@@ -89,9 +77,3 @@ resource "snowflake_grant_account_role" "reader_to_github_ci" {
8977
role_name = snowflake_account_role.reader.name
9078
user_name = snowflake_service_user.github_ci.name
9179
}
92-
93-
resource "snowflake_grant_account_role" "logger_to_sentinel" {
94-
provider = snowflake.useradmin
95-
role_name = snowflake_account_role.logger.name
96-
user_name = snowflake_legacy_service_user.sentinel.name
97-
}

terraform/snowflake/modules/policies/main.tf

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
######################################
22
# Terraform #
33
######################################
4-
4+
# This module enforces Snowflake security by creating a POLICIES database,
5+
# defining strong default password/authentication policies for different user types,
6+
# setting Okta-only auth as the default (when enabled), and provisioning a Sentinel
7+
# legacy service user with the required role grants.
58
############################
69
# Providers #
710
############################
@@ -118,3 +121,25 @@ resource "snowflake_account_authentication_policy_attachment" "default_policy" {
118121
provider = snowflake.accountadmin
119122
authentication_policy = snowflake_authentication_policy.odi_okta_only[0].fully_qualified_name // using the first and only instance that gets created
120123
}
124+
125+
# Create a sentinel service user with password authentication (legacy service user)
126+
resource "snowflake_legacy_service_user" "sentinel" {
127+
provider = snowflake.useradmin
128+
name = "SENTINEL_SVC_USER"
129+
comment = "Service user for Sentinel"
130+
lifecycle {
131+
ignore_changes = [rsa_public_key]
132+
}
133+
134+
# Use the input variable here
135+
default_warehouse = var.logging_warehouse_name
136+
# Use the input variable here
137+
default_role = var.logger_role_name
138+
}
139+
140+
resource "snowflake_grant_account_role" "logger_to_sentinel" {
141+
provider = snowflake.useradmin
142+
# Use the input variable here
143+
role_name = var.logger_role_name
144+
user_name = snowflake_legacy_service_user.sentinel.name
145+
}

terraform/snowflake/modules/policies/variables.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,13 @@ variable "policies_database_name" {
99
type = string
1010
default = "POLICIES"
1111
}
12+
13+
variable "logging_warehouse_name" {
14+
description = "The name of the warehouse to be used by the Sentinel service user."
15+
type = string
16+
}
17+
18+
variable "logger_role_name" {
19+
description = "The name of the role to be granted to the Sentinel service user."
20+
type = string
21+
}

0 commit comments

Comments
 (0)