Skip to content

Commit

Permalink
redo for_each
Browse files Browse the repository at this point in the history
  • Loading branch information
alldoami committed Oct 16, 2024
1 parent 3c0da1c commit da54e0c
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions databricks-default-cluster-policies/groups.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@ locals {

# 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
Expand All @@ -25,9 +28,9 @@ resource "databricks_group" "ws_policy_groups" {

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

display_name = each.value
}
Expand All @@ -39,5 +42,5 @@ resource "databricks_group_member" "ws_policy_group_members" {
group_id = each.value.id

# Assign all existing groups that correspond to this policy group
member_id = data.databricks_group.groups[local.policies[*][each.key]].id
member_id = data.databricks_group.groups[local.policy_group_map[replace(each.key, var.policy_name_prefix, "")][0]].id
}

0 comments on commit da54e0c

Please sign in to comment.