-
Notifications
You must be signed in to change notification settings - Fork 353
/
databricks.tf
234 lines (197 loc) · 5.59 KB
/
databricks.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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
provider "databricks" {
azure_workspace_resource_id = azurerm_databricks_workspace.this.id
}
resource "databricks_secret_scope" "terraform" {
name = "terraform"
initial_manage_principal = "users"
}
resource "databricks_secret" "storage_key" {
key = "blob_storage_key"
string_value = azurerm_storage_account.blobaccount.primary_access_key
scope = databricks_secret_scope.terraform.name
}
resource "databricks_azure_blob_mount" "sample" {
container_name = azurerm_storage_container.sample.name
storage_account_name = azurerm_storage_account.blobaccount.name
mount_name = "sample"
auth_type = "ACCESS_KEY"
token_secret_scope = databricks_secret_scope.terraform.name
token_secret_key = databricks_secret.storage_key.key
}
resource "databricks_instance_pool" "this" {
instance_pool_name = "Sample pool"
min_idle_instances = 0
max_capacity = 10
node_type_id = "Standard_DS3_v2"
idle_instance_autotermination_minutes = 10
preloaded_spark_versions = ["6.6.x-scala2.11"]
custom_tags = {
Team = "Contributors"
Aything = "Works"
}
}
resource "databricks_cluster_policy" "fair_use" {
name = "Fair Use Policy"
definition = jsonencode({
"dbus_per_hour" : {
"type" : "range",
"maxValue" : 20
},
"autotermination_minutes" : {
"type" : "fixed",
"value" : 10,
"hidden" : true
},
"custom_tags.Department" : {
"type" : "fixed",
"value" : "Marketing",
"hidden" : true
}
})
}
resource "databricks_permissions" "use_policy" {
cluster_policy_id = databricks_cluster_policy.fair_use.id
access_control {
group_name = databricks_group.marketing.display_name
permission_level = "CAN_USE"
}
}
resource "databricks_dbfs_file" "show_variables" {
source = "${path.module}/init.sh"
content_b64_md5 = md5(filebase64("${path.module}/init.sh"))
path = "/init-scripts/show-variables.sh"
overwrite = true
mkdirs = true
}
resource "databricks_cluster" "shared_autoscaling" {
cluster_name = "Shared Autoscaling"
instance_pool_id = databricks_instance_pool.this.id
spark_version = "6.6.x-scala2.11"
policy_id = databricks_cluster_policy.fair_use.id
autotermination_minutes = 10
autoscale {
min_workers = 1
max_workers = 10
}
spark_conf = {
"spark.databricks.delta.preview.enabled": true,
"spark.databricks.io.cache.enabled" : true,
"spark.databricks.io.cache.maxDiskUsage" : "50g",
"spark.databricks.io.cache.maxMetaDataCache" : "1g"
}
library {
pypi {
package = "fbprophet==0.6"
}
}
library {
maven {
coordinates = "com.amazon.deequ:deequ:1.0.4"
}
}
cluster_log_conf {
dbfs {
destination = "dbfs:/mnt/sample/cluster-logs"
}
}
init_scripts {
dbfs {
destination = databricks_dbfs_file.show_variables.path
}
}
custom_tags = {
Department = "Marketing"
Order = "New"
}
}
resource "databricks_permissions" "shared_autoscaling" {
cluster_id = databricks_cluster.shared_autoscaling.id
access_control {
group_name = databricks_group.marketing.display_name
permission_level = "CAN_ATTACH_TO"
}
access_control {
group_name = databricks_group.support.display_name
permission_level = "CAN_ATTACH_TO"
}
}
resource "databricks_group" "marketing" {
display_name = "Marketing"
}
resource "databricks_user" "first" {
user_name = "marketing-member@example.com"
display_name = "Marketing Member"
default_roles = []
set_admin = false
}
resource "databricks_group_member" "first" {
group_id = databricks_group.marketing.id
member_id = databricks_user.first.id
}
resource "databricks_group" "support" {
display_name = "Support"
}
resource "databricks_user" "second" {
user_name = "support-member@example.com"
display_name = "Support Member"
default_roles = []
set_admin = false
}
resource "databricks_group_member" "second" {
group_id = databricks_group.support.id
member_id = databricks_user.second.id
}
resource "databricks_notebook" "simple" {
content = filebase64("${path.module}/notebook.py")
path = "/Production/Something"
overwrite = true
mkdirs = true
language = "PYTHON"
}
resource "databricks_job" "featurization" {
name = "Featurization"
timeout_seconds = 3600
max_retries = 1
max_concurrent_runs = 1
new_cluster {
num_workers = 3
instance_pool_id = databricks_instance_pool.this.id
spark_version = "6.6.x-scala2.11"
cluster_log_conf {
dbfs {
destination = "dbfs:/mnt/sample/cluster-logs"
}
}
init_scripts {
dbfs {
destination = databricks_dbfs_file.show_variables.path
}
}
}
notebook_task {
notebook_path = databricks_notebook.simple.path
base_parameters = {
"department": "Set From Terraform"
}
}
library {
pypi {
package = "fbprophet==0.6"
}
}
email_notifications {
no_alert_for_skipped_runs = true
}
}
resource "databricks_permissions" "featurization" {
job_id = databricks_job.featurization.id
access_control {
group_name = databricks_group.support.display_name
permission_level = "CAN_MANAGE"
}
}
resource "databricks_secret_acl" "support_reads" {
principal = databricks_group.support.display_name
scope = databricks_secret_scope.terraform.name
permission = "READ"
}