Hey, can somebody help me? I use Azure with pulumi...
# azure
e
Hey, can somebody help me? I use Azure with pulumi.python. i try to assigne a user_assigned_identity to my virtual machine, as well like a system assigned one. just a system one is no problem, but how do i add a userassigned one? i just get Python exception. more in 🧵
to test just take the vm-azure-python template and add
Copy code
identity=azure_native.compute.VirtualMachineIdentityArgs(
        type="UserAssigned, SystemAssigned",
        user_assigned_identities={
            user_assigned_identity.id: {}
        }
    ),
to the virtual machine, as well like the identity before the vm:
Copy code
user_assigned_identity = azure_native.managedidentity.UserAssignedIdentity("exampleUserAssignedIdentity",
    resource_group_name=resource_group.name,
    location=resource_group.location
)
Error:
Copy code
pulumi:pulumi:Stack (project):
    error: Program failed with an unhandled exception:
    Traceback (most recent call last):
      File "/home/user/.pulumi/bin/pulumi-language-python-exec", line 198, in <module>
        loop.run_until_complete(coro)
      File "/usr/lib/python3.10/asyncio/base_events.py", line 649, in run_until_complete
        return future.result()
      File "/home/user/project/venv/lib/python3.10/site-packages/pulumi/runtime/stack.py", line 143, in run_in_stack
        await run_pulumi_func(run)
      File "/home/user/project/venv/lib/python3.10/site-packages/pulumi/runtime/stack.py", line 55, in run_pulumi_func
        await wait_for_rpcs()
      File "/home/user/project/venv/lib/python3.10/site-packages/pulumi/runtime/stack.py", line 119, in wait_for_rpcs
        await task
      File "/home/user/project/venv/lib/python3.10/site-packages/pulumi/runtime/resource.py", line 936, in do_register
        resolver = await prepare_resource(
      File "/home/user/project/venv/lib/python3.10/site-packages/pulumi/runtime/resource.py", line 196, in prepare_resource
        serialized_props = await rpc.serialize_properties(
      File "/home/user/project/venv/lib/python3.10/site-packages/pulumi/runtime/rpc.py", line 247, in serialize_properties
        struct[translated_name] = result
      File "/home/user/project/venv/lib/python3.10/site-packages/google/protobuf/internal/well_known_types.py", line 471, in __setitem__
        _SetStructValue(self.fields[key], value)
      File "/home/user/project/venv/lib/python3.10/site-packages/google/protobuf/internal/well_known_types.py", line 433, in _SetStructValue
        struct_value.struct_value.update(value)
      File "/home/user/project/venv/lib/python3.10/site-packages/google/protobuf/internal/well_known_types.py", line 507, in update
        _SetStructValue(self.fields[key], value)
      File "/home/user/project/venv/lib/python3.10/site-packages/google/protobuf/internal/well_known_types.py", line 433, in _SetStructValue
        struct_value.struct_value.update(value)
      File "/home/user/project/venv/lib/python3.10/site-packages/google/protobuf/internal/well_known_types.py", line 507, in update
        _SetStructValue(self.fields[key], value)
    TypeError: bad argument type for built-in operation
a
Shouldn't the
user_assigned_identities
parameter be a
Sequence[str]
?
Copy code
user_assigned_identities=[
    user_assigned_identity.id
]
e
congratulations! that worked as expected! i don't even know what i've tried already.... i tried what pulumi AI gave me (didn't work):
Copy code
identity=azure_native.compute.VirtualMachineIdentityArgs(
        type="UserAssigned, SystemAssigned",
        user_assigned_identities={
            user_assigned_identity.id: {}
        }
    ),
i tried both datatype that are given in the VirtualMachine constructor:
Copy code
identity: Input[VirtualMachineIdentityArgs | VirtualMachineIdentityArgsDict] | None = None,
mostly i got the error:
user_assigned_identity should be an object
. i just couldn't figure out which kind of object. Docu of the virtualmachine:
Copy code
identity VirtualMachineIdentityArgs
    The identity of the virtual machine, if configured.
Docu of VirtualMachineIdentityArgs:
Copy code
user_assigned_identities Sequence[str]
    The list of user identities associated with the Virtual Machine. The user identity dictionary key references will be ARM resource ids in the form: '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ManagedIdentity/userAssignedIdentities/{identityName}'.
i tried
'/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ManagedIdentity/userAssignedIdentities/{identityName}'
as value with key
user_assigned_identities:
that was the problem.. thank you for your help!