-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.tf
More file actions
82 lines (63 loc) · 2.88 KB
/
main.tf
File metadata and controls
82 lines (63 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
module "monitor_label" {
source = "cloudposse/label/null"
version = "0.25.0"
context = module.this.context
delimiter = coalesce(module.this.context.delimiter, "_")
regex_replace_chars = coalesce(module.this.context.regex_replace_chars, "/[^_a-zA-Z0-9]/")
label_value_case = coalesce(module.this.context.label_value_case, "upper")
}
resource "snowflake_resource_monitor" "this" {
count = local.enabled ? 1 : 0
name = local.name_from_descriptor
credit_quota = var.credit_quota
frequency = var.frequency
start_timestamp = var.start_timestamp
end_timestamp = var.end_timestamp
notify_triggers = var.notify_triggers
suspend_triggers = var.suspend_triggers
suspend_immediate_triggers = var.suspend_immediate_triggers
notify_users = var.notify_users
set_for_account = var.set_for_account
warehouses = var.warehouses
}
module "snowflake_default_role" {
for_each = local.default_roles
source = "getindata/role/snowflake"
version = "1.3.0"
context = module.this.context
name = each.key
attributes = ["RMN", one(snowflake_resource_monitor.this[*].name)]
enabled = local.create_default_roles && lookup(each.value, "enabled", true)
descriptor_name = lookup(each.value, "descriptor_name", "snowflake-role")
role_ownership_grant = lookup(each.value, "role_ownership_grant", "SYSADMIN")
granted_to_users = lookup(each.value, "granted_to_users", [])
granted_to_roles = lookup(each.value, "granted_to_roles", [])
granted_roles = lookup(each.value, "granted_roles", [])
}
module "snowflake_custom_role" {
for_each = local.custom_roles
source = "getindata/role/snowflake"
version = "1.3.0"
context = module.this.context
name = each.key
attributes = ["RMN", one(snowflake_resource_monitor.this[*].name)]
enabled = local.create_default_roles && lookup(each.value, "enabled", true)
descriptor_name = lookup(each.value, "descriptor_name", "snowflake-role")
role_ownership_grant = lookup(each.value, "role_ownership_grant", "SYSADMIN")
granted_to_users = lookup(each.value, "granted_to_users", [])
granted_to_roles = lookup(each.value, "granted_to_roles", [])
granted_roles = lookup(each.value, "granted_roles", [])
}
resource "snowflake_resource_monitor_grant" "this" {
for_each = local.enabled ? transpose({ for role_name, role in local.roles : local.roles[role_name].name =>
lookup(local.roles_definition[role_name], "resource_monitor_grants", [])
if lookup(local.roles_definition[role_name], "enabled", true)
}) : {}
monitor_name = one(resource.snowflake_resource_monitor.this[*]).name
privilege = each.key
roles = each.value
# Whole configuration should be maintained "as Code" so below
# options should be disabled in all use-cases
enable_multiple_grants = false
with_grant_option = false
}