I'm trying to use <databricks.GroupMember> to add ...
# general
s
I'm trying to use databricks.GroupMember to add an existing Databricks User to an existing Group, but getting an error that I don't understand. Though I'm providing the args as strings as directed by the docs, the resource class seems to be expecting a different type of object. Code and error message in thread. What am I missing?
Copy code
def 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),
            )
After
pulumi up
Copy code
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
m
The return value of
get_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/
s
That helped explain and to fix, thank you!