Skip to content

Commit 3a65ada

Browse files
committed
feat: cluster and clsuter policy permission assignments
1 parent 35d7b06 commit 3a65ada

File tree

3 files changed

+82
-25
lines changed

3 files changed

+82
-25
lines changed

iam.tf

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -83,21 +83,3 @@ resource "databricks_entitlements" "this" {
8383

8484
depends_on = [databricks_group_member.this]
8585
}
86-
87-
resource "databricks_permissions" "sql_endpoint" {
88-
for_each = { for entry in databricks_sql_endpoint.this : (entry.name) => (entry.id) }
89-
90-
sql_endpoint_id = each.value
91-
92-
dynamic "access_control" {
93-
for_each = { for entry in flatten([for resource, permissions in var.iam_permissions : [for permission, groups in permissions : [for group in groups : {
94-
resource = resource, permission = permission, group = group
95-
} if resource == "sql_endpoint"]]]) : "${entry.resource}.${entry.permission}.${entry.group}" => entry }
96-
content {
97-
group_name = access_control.value.group
98-
permission_level = access_control.value.permission
99-
}
100-
}
101-
102-
depends_on = [databricks_group.this]
103-
}

permissions.tf

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
resource "databricks_permissions" "default_cluster" {
2+
for_each = length(var.default_cluster_id) == 0 ? {} : {
3+
for k, v in var.iam : k => v.default_cluster_permission
4+
if v.default_cluster_permission != null
5+
}
6+
7+
cluster_id = var.default_cluster_id
8+
9+
access_control {
10+
group_name = databricks_group.this[each.key].display_name
11+
permission_level = each.value
12+
}
13+
}
14+
15+
resource "databricks_permissions" "cluster_policy" {
16+
for_each = {
17+
for policy in var.cluster_policies_object : (policy.name) => policy
18+
if policy.can_use != null
19+
}
20+
21+
cluster_policy_id = each.value.id
22+
23+
dynamic "access_control" {
24+
for_each = each.value.can_use
25+
content {
26+
group_name = databricks_group.this[access_control.value].display_name
27+
permission_level = "CAN_USE"
28+
}
29+
}
30+
}
31+
32+
resource "databricks_permissions" "sql_endpoint" {
33+
for_each = { for entry in databricks_sql_endpoint.this : (entry.name) => (entry.id) }
34+
35+
sql_endpoint_id = each.value
36+
37+
dynamic "access_control" {
38+
for_each = { for entry in flatten([for resource, permissions in var.iam_permissions : [for permission, groups in permissions : [for group in groups : {
39+
resource = resource, permission = permission, group = group
40+
} if resource == "sql_endpoint"]]]) : "${entry.resource}.${entry.permission}.${entry.group}" => entry }
41+
content {
42+
group_name = access_control.value.group
43+
permission_level = access_control.value.permission
44+
}
45+
}
46+
47+
depends_on = [databricks_group.this]
48+
}
49+
50+

variables.tf

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ variable "workspace_id" {
1818
description = "Id of Azure Databricks workspace"
1919
}
2020

21+
variable "ip_rules" {
22+
type = map(string)
23+
description = "Map of IP addresses permitted for access to DB"
24+
default = {}
25+
}
26+
27+
# Identity Access Management variables
2128
variable "user_object_ids" {
2229
type = map(string)
2330
description = "Map of AD usernames and corresponding object IDs"
@@ -38,9 +45,10 @@ variable "workspace_admins" {
3845

3946
variable "iam" {
4047
type = map(object({
41-
user = optional(list(string))
42-
service_principal = optional(list(string))
43-
entitlements = optional(list(string))
48+
user = optional(list(string))
49+
service_principal = optional(list(string))
50+
entitlements = optional(list(string))
51+
default_cluster_permission = optional(string)
4452
}))
4553
description = "Used to create workspace group. Map of group name and its parameters, such as users and service principals added to the group. Also possible to configure group entitlements."
4654
default = {}
@@ -67,12 +75,28 @@ variable "iam_permissions" {
6775
}
6876
}
6977

70-
variable "ip_rules" {
71-
type = map(string)
72-
description = "Map of IP addresses permitted for access to DB"
73-
default = {}
78+
# Default Cluster and Cluster Policy variables
79+
variable "default_cluster_id" {
80+
type = string
81+
description = "Single value of default Cluster id created by 'databricks-runtime' module"
82+
default = ""
83+
}
84+
85+
variable "cluster_policies_object" {
86+
type = list(object({
87+
id = string
88+
name = string
89+
can_use = list(string)
90+
}))
91+
description = "List of objects that provides an ability to grant custom workspace group a permission to use(CAN_USE) cluster policy"
92+
default = [{
93+
id = null
94+
name = null
95+
can_use = null
96+
}]
7497
}
7598

99+
# SQL Endpoint variables
76100
variable "sql_endpoint" {
77101
type = map(object({
78102
cluster_size = string
@@ -106,6 +130,7 @@ variable "default_values_sql_endpoint" {
106130
}
107131
}
108132

133+
# Unity Catalog variables
109134
variable "create_metastore" {
110135
type = bool
111136
description = "Boolean flag for Unity Catalog Metastore current in this environment. One Metastore per region"

0 commit comments

Comments
 (0)