File tree Expand file tree Collapse file tree 3 files changed +46
-0
lines changed Expand file tree Collapse file tree 3 files changed +46
-0
lines changed Original file line number Diff line number Diff line change @@ -41,12 +41,24 @@ resource "azurerm_role_assignment" "this" {
41
41
principal_id = each. value . object_id
42
42
}
43
43
44
+ resource "databricks_cluster_policy" "this" {
45
+ for_each = {
46
+ for param in var . custom_cluster_policies : (param. name ) => param . definition
47
+ if param . definition != null
48
+ }
49
+
50
+ name = each. key
51
+ definition = jsonencode (each. value )
52
+ }
53
+
44
54
resource "databricks_cluster" "this" {
45
55
cluster_name = " shared autoscaling"
46
56
spark_version = var. spark_version
47
57
spark_conf = var. spark_conf
48
58
spark_env_vars = var. spark_env_vars
49
59
60
+ policy_id = one ([for policy in var . custom_cluster_policies : databricks_cluster_policy . this [policy . name ]. id if policy . assigned ])
61
+
50
62
data_security_mode = var. data_security_mode
51
63
node_type_id = var. node_type
52
64
autotermination_minutes = var. autotermination_minutes
Original file line number Diff line number Diff line change @@ -7,3 +7,11 @@ output "cluster_id" {
7
7
value = databricks_cluster. this . id
8
8
description = " Databricks Cluster Id"
9
9
}
10
+
11
+ output "cluster_policies_object" {
12
+ value = [for policy in var . custom_cluster_policies : {
13
+ id = databricks_cluster_policy.this[policy.name].id
14
+ name = databricks_cluster_policy.this[policy.name].name
15
+ can_use = policy.can_use
16
+ }]
17
+ }
Original file line number Diff line number Diff line change @@ -101,6 +101,32 @@ variable "permissions" {
101
101
]
102
102
}
103
103
104
+ variable "custom_cluster_policies" {
105
+ type = list (object ({
106
+ name = string
107
+ can_use = list (string )
108
+ definition = any
109
+ assigned = bool
110
+ }))
111
+ description = <<- EOT
112
+ Provides an ability to create custom cluster policy, assign it to cluster and grant CAN_USE permissions on it to certain custom groups
113
+ name - name of custom policy;
114
+ can_use - list of string, where values are custom group names, there groups have to be created with Terraform
115
+ definition - JSON document expressed in Databricks Policy Definition Language. No need to call 'jsonencode()' function on it when providing a value
116
+ assigned - boolean flag which assigns policy to default 'shared autoscaling' cluster, only single custom policy could be assigned
117
+ EOT
118
+ default = [{
119
+ name = null
120
+ can_use = null
121
+ definition = null
122
+ assigned = null
123
+ }]
124
+ validation {
125
+ condition = length ([for policy in var . custom_cluster_policies : policy . assigned if policy . assigned ]) <= 1
126
+ error_message = " Only single cluster policy assignment allowed. Please set 'assigned' parameter to 'true' for exact one or none policy"
127
+ }
128
+ }
129
+
104
130
variable "data_security_mode" {
105
131
type = string
106
132
description = " Security features of the cluster"
You can’t perform that action at this time.
0 commit comments