Hi all. General TypeScript related question. I nee...
# getting-started
c
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
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
And that did the trick. Thank you very much!
o
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
I still have nightmares because of ARM templates. So I don't complain too much. This is much better and quite refreshing. 😄
🙌 1