Skip to content

Commit 338b242

Browse files
authored
Merge pull request #31 from data-platform-hq/fix_precondition
fix: create precondition
2 parents 4cc8ba5 + aedda3b commit 338b242

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

permissions.tf

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,21 @@ resource "databricks_permissions" "clusters" {
2121
permission_level = access_control.value.permission_level
2222
}
2323
}
24+
25+
lifecycle {
26+
precondition {
27+
condition = length(var.iam_account_groups) != 0 ? alltrue([
28+
for permission in each.value.permissions : contains(
29+
var.iam_account_groups[*].group_name, permission.group_name
30+
)
31+
]) : true
32+
error_message = <<-EOT
33+
Databricks Account group mentioned in 'permissions' parameter of 'cluster_config' variable doesn't exists or wasn't assigned to Workspace.
34+
Please make sure provided group exist within Databricks Account and then check if it assigned to target Workspace (look for 'iam_account_groups' variable).
35+
These are valid Account Groups on Workspace: ${join(", ", var.iam_account_groups[*].group_name)}
36+
EOT
37+
}
38+
}
2439
}
2540

2641
resource "databricks_permissions" "sql_endpoint" {
@@ -38,6 +53,21 @@ resource "databricks_permissions" "sql_endpoint" {
3853
permission_level = access_control.value.permission_level
3954
}
4055
}
56+
57+
lifecycle {
58+
precondition {
59+
condition = length(var.iam_account_groups) != 0 ? alltrue([
60+
for permission in each.value.permissions : contains(
61+
var.iam_account_groups[*].group_name, permission.group_name
62+
)
63+
]) : true
64+
error_message = <<-EOT
65+
Databricks Account group mentioned in 'permissions' parameter of 'sql_endpoint' variable doesn't exists or wasn't assigned to Workspace.
66+
Please make sure provided group exist within Databricks Account and then check if it assigned to target Workspace (look for 'iam_account_groups' variable).
67+
These are valid Account Groups on Workspace: ${join(", ", var.iam_account_groups[*].group_name)}
68+
EOT
69+
}
70+
}
4171
}
4272

4373
resource "databricks_secret_acl" "this" {
@@ -46,4 +76,15 @@ resource "databricks_secret_acl" "this" {
4676
scope = databricks_secret_scope.this[each.value.scope].name
4777
principal = length(var.iam_account_groups) != 0 ? data.databricks_group.account_groups[each.value.principal].display_name : databricks_group.this[each.value.principal].display_name
4878
permission = each.value.permission
79+
80+
lifecycle {
81+
precondition {
82+
condition = length(var.iam_account_groups) != 0 ? contains(var.iam_account_groups[*].group_name, each.value.principal) : true
83+
error_message = <<-EOT
84+
Databricks Account group mentioned in 'acl' parameter of 'secret_scope' variable doesn't exists or wasn't assigned to Workspace.
85+
Please make sure provided group exist within Databricks Account and then check if it assigned to target Workspace (look for 'iam_account_groups' variable).
86+
These are valid Account Groups on Workspace: ${join(", ", var.iam_account_groups[*].group_name)}
87+
EOT
88+
}
89+
}
4990
}

0 commit comments

Comments
 (0)