Trying to create a WebApp with a system assigned i...
# getting-started
q
Trying to create a WebApp with a system assigned identity in C#:
Copy code
UserAssignedIdentity identity = new UserAssignedIdentity($"{name}ManagedIdentity",
  new UserAssignedIdentityArgs
  {
    ResourceGroupName = resourceGroup.Name,
    ResourceName = $"{name}ManagedIdentity",
  });

new WebApp(name, new WebAppArgs
{
  Kind = "app,linux",
  ResourceGroupName = resourceGroup.Name,
  ServerFarmId = appServicePlan.Id,
  Reserved = true,
  Identity = new Pulumi.AzureNative.Web.Inputs.ManagedServiceIdentityArgs
  {
    Type = Pulumi.AzureNative.Web.ManagedServiceIdentityType.UserAssigned,
    UserAssignedIdentities =
    {
      {  identity.Id , "resource" }
    }
  },
  ...
My problem is in this part:
Copy code
UserAssignedIdentities =
    {
      {  identity.Id , "resource" }
    }
[Documentation](https://www.pulumi.com/docs/reference/pkg/azure-native/web/webapp/#managedserviceidentity) of
userAssignedIdentities
states: The list of user assigned identities associated with the resource. The user identity dictionary key references will be ARM resource ids in the form: ‘/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ManagedIdentity/userAssignedIdentities/{identityName} So the key needs to be the Id of the identity you want to use. Given that
UserAssignedIdentities
is of type
InputMap<object>
, which consists of a
string
and an
object
as a key-value pair. Now, I can't use
identity.Id
since that is an
Input<string>
rather than a string. And a string is expected as the first type of the collection initializer of the
InputMap<object>
. I must be missing something. How do I pass the Id of a newly created User Assigned Identity to the WebApp?
b
Hey Thomas, I think you'll have to use an
Apply
here. I'm not a dotnet expert myself, but if a resource requires a string rather than an
Input<string>
you'll need to use
Apply
q
Yeah, I figured that. But couldn't see how for this case. I got a reply from @brave-planet-10645 which pointed me to this Github issue: https://github.com/pulumi/pulumi-azure-native/issues/812#issuecomment-842456058