steep-pager-77235
08/01/2024, 10:49 PMsteep-pager-77235
08/01/2024, 10:49 PMdef add_users_to_groups(user_data: list[dict]) -> None:
"""Sample user_data entry:
[{"email":"<mailto:foo@gmail.com|foo@gmail.com>","groups":["bar","baz"]}]
"""
for user in user_data:
user_resource = dbx.get_user(user_name=user["email"])
print(type(user_resource.id),user_resource.id)
groups = user["groups"]
for group in groups:
group_resource = dbx.get_group(display_name=group)
print(type(group_resource.id),group_resource.id)
dbx.GroupMember(
f"{group}>{user['email']}",
group_id=group_resource.id,
member_id=user_resource.id,
opts=ResourceOptions(parent=user_resource),
)
steep-pager-77235
08/01/2024, 10:50 PMpulumi up
Diagnostics:
pulumi:pulumi:Stack (infra-databricks-account-account):
error: Program failed with an unhandled exception:
Traceback (most recent call last):
File "/home/ubuntu/infra-databricks/infra-databricks-account/./__main__.py", line 12, in <module>
users.add_users_to_groups(USER_CONFIG)
File "/home/ubuntu/infra-databricks/infra-databricks-account/./users.py", line 16, in add_users_to_groups
dbx.GroupMember(
File "/home/ubuntu/.virtualenvs/infra-databricks/lib/python3.10/site-packages/pulumi_databricks/group_member.py", line 167, in __init__
__self__._internal_init(resource_name, *args, **kwargs)
File "/home/ubuntu/.virtualenvs/infra-databricks/lib/python3.10/site-packages/pulumi_databricks/group_member.py", line 189, in _internal_init
super(GroupMember, __self__).__init__(
File "/home/ubuntu/.virtualenvs/infra-databricks/lib/python3.10/site-packages/pulumi/resource.py", line 1124, in __init__
Resource.__init__(self, t, name, True, props, opts, False, dependency)
File "/home/ubuntu/.virtualenvs/infra-databricks/lib/python3.10/site-packages/pulumi/resource.py", line 897, in __init__
(parent._transformations or []) if parent is not None else []
AttributeError: 'AwaitableGetUserResult' object has no attribute '_transformations'
<class 'str'> 620280062601644
<class 'str'> 83101122065962
modern-zebra-45309
08/03/2024, 9:35 AMget_user
is not a dbx.User resource that could serve as a parent resource within Pulumi, but more like a "view" of the Databricks user that allows you to access information about it.
Parent-child relationships can only exist between resources within the same stack, with the pulumi:pulumi:Stack
resource being the top-most parent.
You're not losing any functionality if you omit opts=ResourceOptions(parent=user_resource)
since the main effect (aside from creating a hierarchy within a stack) is that children inherit certain resource options from their parents.
See https://www.pulumi.com/docs/concepts/options/parent/steep-pager-77235
08/20/2024, 10:56 PM