generated from getindata/terraform-module-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
165 lines (136 loc) · 3.52 KB
/
main.tf
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
resource "snowflake_database" "this" {
name = "TEST_DB"
}
resource "snowflake_schema" "this" {
database = snowflake_database.this.name
name = "BRONZE"
}
resource "snowflake_table" "table_1" {
database = snowflake_schema.this.database
schema = snowflake_schema.this.name
name = "TEST_TABLE_1"
column {
name = "identity"
type = "NUMBER(38,0)"
nullable = true
identity {
start_num = 1
step_num = 3
}
}
}
resource "snowflake_table" "table_2" {
database = snowflake_schema.this.database
schema = snowflake_schema.this.name
name = "TEST_TABLE_2"
column {
name = "identity"
type = "NUMBER(38,0)"
nullable = true
identity {
start_num = 1
step_num = 3
}
}
}
resource "snowflake_account_role" "role_1" {
name = "ROLE_1"
}
resource "snowflake_account_role" "role_2" {
name = "ROLE_2"
}
resource "snowflake_database_role" "db_role_1" {
database = snowflake_database.this.name
name = "DB_ROLE_1"
}
resource "snowflake_database_role" "db_role_2" {
database = snowflake_database.this.name
name = "DB_ROLE_2"
}
resource "snowflake_database_role" "db_role_3" {
database = snowflake_database.this.name
name = "DB_ROLE_3"
}
resource "snowflake_share" "this" {
name = "TEST_SHARE"
}
resource "snowflake_grant_privileges_to_share" "this" {
to_share = snowflake_share.this.name
privileges = ["USAGE"]
on_database = snowflake_database.this.name
}
module "snowflake_database_role_1" {
source = "../../"
database_name = snowflake_database.this.name
name = "TEST_DB_ROLE_1"
granted_to_roles = [
snowflake_account_role.role_1.name,
snowflake_account_role.role_2.name
]
granted_to_database_roles = [
"${snowflake_database.this.name}.${snowflake_database_role.db_role_1.name}"
]
granted_database_roles = [
"${snowflake_database.this.name}.${snowflake_database_role.db_role_2.name}",
"${snowflake_database.this.name}.${snowflake_database_role.db_role_3.name}"
]
database_grants = {
privileges = ["USAGE", "CREATE SCHEMA"]
}
schema_grants = [
{
schema_name = snowflake_schema.this.name
privileges = ["USAGE"]
},
{
future_schemas_in_database = true
all_schemas_in_database = true
privileges = ["USAGE"]
},
]
schema_objects_grants = {
"TABLE" = [
{
privileges = ["SELECT"]
object_name = snowflake_table.table_1.name
schema_name = snowflake_schema.this.name
},
{
all_privileges = true
object_name = snowflake_table.table_2.name
schema_name = snowflake_schema.this.name
}
]
"ALERT" = [
{
all_privileges = true
on_future = true
on_all = true
}
]
}
}
module "snowflake_database_role_2" {
source = "../../"
database_name = snowflake_database.this.name
name = "TEST_DB_ROLE_2"
name_scheme = {
context_template_name = "snowflake-schema-database-role"
extra_values = { schema = "BRONZE" }
}
context_templates = var.context_templates
granted_to_shares = [snowflake_share.this.name]
depends_on = [snowflake_grant_privileges_to_share.this]
}
module "snowflake_database_role_3" {
source = "../../"
database_name = snowflake_database.this.name
name = "TEST_DB_ROLE_3"
name_scheme = {
properties = ["environment", "project", "schema", "name"]
extra_values = {
project = "PROJECT"
schema = "BRONZE"
}
}
}