โ08-06-2022 07:28 AM
Hi, follow the example to create one user. It's working however I want to create multiple users, I have tried many ways but still cannot get it work, please share some idea.
https://registry.terraform.io/providers/databricks/databricks/latest/docs/resources/user
data "databricks_group" "admins" {
display_name = "admins"
}
resource "databricks_user" "me" {
user_name = "me@example.com"
}
resource "databricks_group_member" "i-am-admin" {
group_id = data.databricks_group.admins.id
member_id = databricks_user.me.id
}
โ08-10-2022 05:27 PM
as @Cedric Law Hing Pingโ mentioned, you can use `count` or `foreach` in Terraform to do this.
Here's a simple example:
```
locals {
user_emails = toset([
"user1@example.com",
"user2@example.com",
"user3@example.com"
])
}
resource "databricks_user" "engineers" {
for_each = local.user_emails
user_name = each.value
}
data "databricks_group" "admins" {
display_name = "admins"
}
resource "databricks_group_member" "engineer-admins" {
for_each = databricks_user.engineers
group_id = data.databricks_group.admins.id
member_id = each.value.id
}
```
โ08-07-2022 11:52 PM
count is one of the meta-parameters available to all resources. We can specify the number of identical resources to create.
โ08-10-2022 07:11 AM
โ08-10-2022 05:27 PM
as @Cedric Law Hing Pingโ mentioned, you can use `count` or `foreach` in Terraform to do this.
Here's a simple example:
```
locals {
user_emails = toset([
"user1@example.com",
"user2@example.com",
"user3@example.com"
])
}
resource "databricks_user" "engineers" {
for_each = local.user_emails
user_name = each.value
}
data "databricks_group" "admins" {
display_name = "admins"
}
resource "databricks_group_member" "engineer-admins" {
for_each = databricks_user.engineers
group_id = data.databricks_group.admins.id
member_id = each.value.id
}
```
โ08-10-2022 10:10 PM
Thanks @Zach Kingโ this solution work for me.
โ01-22-2024 11:10 PM
What if I want to give User Name along with the email ID?
I used below code but its not helping(code is not failing, but not adding user name)
It seems this code line: "display_name = each.key" is not working. Pls suggest.
Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you wonโt want to miss the chance to attend and share knowledge.
If there isnโt a group near you, start one and help create a community that brings people together.
Request a New Group