https://pulumi.com logo
#getting-started
Title
# getting-started
c

creamy-fall-88031

05/24/2022, 2:39 PM
Hi all. General TypeScript related question. I need to reference user managed identity as seen in the following code snippet taken from the docs:
Copy code
identity: {
        type: azure_native.network.ResourceIdentityType.UserAssigned,
        userAssignedIdentities: {
            "/subscriptions/subid/resourceGroups/rg1/providers/Microsoft.ManagedIdentity/userAssignedIdentities/identity1": {},
        },
    },
Now, I'm trying to change resource path in the example above with something more dynamic, so did the following:
Copy code
let userIdentity = pulumi.all([subscriptionId, resourceGroup.name, userAssignedIdentity.id])
                   .apply(([subscriptionId, resourceGroup, usrAssignedIdentity]) => `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroup}/providers/Microsoft.ManagedIdentity/userAssignedIdentities/${usrAssignedIdentity}`)
And then used it as follows:
Copy code
identity: {
    type: azure_native.network.ResourceIdentityType.UserAssigned,
    userAssignedIdentities: {
        ${userIdentity} : {},
    },
},
But this doesn't seem to be working when the variable
{$userIdentity}
is on the left of the colon sign. I'm getting the following error:
Copy code
error: Code="LinkedInvalidPropertyId" Message="Property id 'userIdentity' at path '' is invalid. Expect fully qualified resource Id that start with '/subscriptions/{subscriptionId}' or '/providers/{resourceProviderNamespace}/'."
Can someone please help me with the proper way to do this ?
o

orange-policeman-59119

05/24/2022, 4:13 PM
You're using typescript? Try creating the object that has the key (the object after "userAssignedIdentities:") inside an Apply block
Like:
Copy code
userAssignedIdentities: userIdentity.apply(x => ({
  [x]: {}
})
c

creamy-fall-88031

05/24/2022, 4:25 PM
And that did the trick. Thank you very much!
o

orange-policeman-59119

05/24/2022, 4:26 PM
Yeah! That Azure API is a weird one, a map with keys and empty objects 🤦‍♂️
In case it ever comes up again or you see something similar, the Pulumi engine generally expects keys of objects or maps in all languages to be strings, not Output<string>
1
c

creamy-fall-88031

05/24/2022, 4:28 PM
I still have nightmares because of ARM templates. So I don't complain too much. This is much better and quite refreshing. 😄
🙌 1
5 Views