Home > Mobile >  Using Local values to define Azure Databricks User block
Using Local values to define Azure Databricks User block

Time:11-13

I would like to give access to two users to use Azure Databricks using the below block :

resource "databricks_user" "dbuser" {
  display_name     = local.name.display_name
  user_name        = local.name.user_name
  workspace_access = true
}

I have locals defined as below :

locals {
  name = {
    display_name = ["Vincent Casinha",
      "Susan Young"
    ]
    user_name = ["[email protected]",
    "[email protected]"]
  }
}

While trying to run terraform enter image description hereplan i get the error attached. How do i use the local values properly in the databricks_user block for the argumens display_name & user_name?

CodePudding user response:

locals {
    display_name = ["Vincent Casinha", "Susan Young"]
    user_name = ["[email protected]","[email protected]"]
}


#assuming length of display_name and user_name are same
resource "databricks_user" "dbuser" {
  count            = length(local.display_name)
  display_name     = local.display_name[count.index]
  user_name        = local.user_name[count.index]
  workspace_access = true
}

#or you can do like below

locals {
    name = [
    {
        display_name = "Vincent Casinha"
        user_name = "[email protected]"
    },
    {
        display_name = "Susan Young"
        user_name = "[email protected]"
    }
  ] 
}

resource "databricks_user" "dbuser" {
    for_each         = local.name
    display_name     = each.value.display_name
    user_name        = each.value.user_name
    workspace_access = true
}
  • Related