Skip to content

Commit

Permalink
counts and for_each are mutually exclusive
Browse files Browse the repository at this point in the history
  • Loading branch information
jayengee committed Jul 17, 2024
1 parent 1961e58 commit 1e672c4
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions databricks-s3-volume/grants.tf
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
locals {
# Only set the grant principals if the catalog and/or schema doesn't already exist
catalog_r_grant_principals = var.create_catalog ? var.catalog_r_grant_principals : []
catalog_rw_grant_principals = var.create_catalog ? var.catalog_rw_grant_principals : []
schema_r_grant_principals = var.create_schema ? var.schema_r_grant_principals : []
schema_rw_grant_principals = var.create_schema ? var.schema_rw_grant_principals : []
}

# catalog
resource "databricks_grant" "catalog_r" {
count = var.create_catalog ? 1 : 0
depends_on = [databricks_catalog[0].volume]
for_each = toset(var.catalog_r_grant_principals)
for_each = toset(local.catalog_r_grant_principals)

catalog = local.catalog_name
principal = each.value
privileges = ["USE_CATALOG", "USE_SCHEMA", "SELECT"]
}

resource "databricks_grant" "catalog_rw" {
count = var.create_catalog ? 1 : 0
depends_on = [databricks_catalog[0].volume]
for_each = toset(var.catalog_rw_grant_principals)
for_each = toset(local.catalog_rw_grant_principals)

catalog = local.catalog_name
principal = "Data Scientists"
Expand All @@ -35,19 +41,17 @@ resource "databricks_grant" "catalog_rw" {

# schema
resource "databricks_grant" "schema_r" {
count = var.create_schema ? 1 : 0
depends_on = [databricks_schema[0].volume]
for_each = toset(var.schema_r_grant_principals)
for_each = toset(local.schema_r_grant_principals)

schema = local.schema_name
principal = each.value
privileges = ["USE_SCHEMA", "SELECT", "READ_VOLUME"]
}

resource "databricks_grant" "schema_rw" {
count = var.create_schema ? 1 : 0
depends_on = [databricks_schema[0].volume]
for_each = toset(var.schema_rw_grant_principals)
for_each = toset(local.schema_rw_grant_principals)

schema = local.schema_name
principal = each.value
Expand Down

0 comments on commit 1e672c4

Please sign in to comment.