Having an issue retrieving the string representation of a user object via data "databricks_group"
:
The data source:
data "databricks_group" "all" {
for_each = toset(["group1", "group2", "group2"])
display_name = each.key
}
The resource:
resource "databricks_group" "this" {
for_each = data.databricks_group.all
display_name = each.key
}
My attempt to retrieve the users:
locals {
allusers = [for group in data.databricks_group.all : group.users]
}
When I later iterate allusers
, the user object appears to be id
and not, say, "user@foo.com".
I've also tried to obtain a mapping of group -> users, and then to transpose that to have a lookup from user->group:
g_to_u = {for group in data.databricks_group.all : group.display_name => group.users}
u_to_g = transpose(g_to_u)
But again, I retrieve only long integers (assumedly the id
).
Any ideas appreciated - thanks!
Based on the discussion in the comments, the goal is to get all the users in the required format. This should be done in the local variable. To make this work, you need the following:
data "databricks_group" "all" {
for_each = toset(["group1", "group2", "group2"])
display_name = each.key
}
locals {
allusers = values(data.databricks_group.all)[*].users
}
Since you are querying the data source using the for_each
meta-argument, you can use the built-in values
function [1] to fetch all the values for all the keys and then get only the required attribute.
[1] https://developer.hashicorp.com/terraform/language/functions/values