Skip to content

Commit

Permalink
feat: Add groups to databricks-default-cluster-policies module (#655)
Browse files Browse the repository at this point in the history
  • Loading branch information
alldoami authored Oct 16, 2024
1 parent 347931c commit 94ed7e5
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
46 changes: 46 additions & 0 deletions databricks-default-cluster-policies/groups.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
locals {
ws_policy_name_prefixes = toset([
var.policy_name_prefix,
])

# Define the policies with existing groups mapped to each policy
policies = var.policy_map

# Generate full workspace policy names by prefixing policy names
all_ws_policy_names = flatten([
for prefix in local.ws_policy_name_prefixes : [
for policy_map in local.policies :
"${prefix}${keys(policy_map)[0]}"
]
])

# Create a flat map of policy names to associated groups
policy_group_map = merge([for policy_map in local.policies : policy_map]...)
}

# Create Databricks groups for each policy name
resource "databricks_group" "ws_policy_groups" {
for_each = toset(local.all_ws_policy_names)

display_name = each.key
workspace_access = true
}

# Retrieve the existing Databricks groups that need to be assigned
data "databricks_group" "groups" {
for_each = toset(flatten([
for group in local.policy_group_map : group
]))

display_name = each.value
}

# Assign the existing groups to the newly created policy groups
resource "databricks_group_member" "ws_policy_group_members" {
for_each = databricks_group.ws_policy_groups

group_id = each.value.id

# Assign all existing groups that correspond to this policy group
member_id = data.databricks_group.groups[local.policy_group_map[replace(each.key, var.policy_name_prefix, "")][0]].id
}
5 changes: 5 additions & 0 deletions databricks-default-cluster-policies/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,8 @@ variable "personal_compute_pool_ids" {
type = list(string)
default = []
}

variable "policy_map" {
description = "Map of policy names to groups"
type = list(map(list(string)))
}

0 comments on commit 94ed7e5

Please sign in to comment.