-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add groups to databricks-default-cluster-policies module (#655)
- Loading branch information
Showing
2 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters