/// <summary>
 /// Set user assigned identity ids to the given virtual machine inner model
 /// </summary>
 /// <param name="virtualMachineInner">the virtual machine inner model</param>
 /// <param name="vmTaskGroup">the virtual machine task group</param>
 internal void HandleUserAssignedIdentities(VirtualMachineInner virtualMachineInner, CreatorTaskGroup <IHasId> vmTaskGroup)
 {
     try
     {
         if (virtualMachineInner.Identity == null || virtualMachineInner.Identity.Type == null)
         {
             return;
         }
         var parsedIdentityType = virtualMachineInner.Identity.Type;
         if (parsedIdentityType.Equals(ResourceIdentityType.None) ||
             parsedIdentityType.Equals(ResourceIdentityType.SystemAssigned))
         {
             return;
         }
         foreach (var key in this.userAssignedIdentityCreatableKeys)
         {
             var identity = (IIdentity)vmTaskGroup.CreatedResource(key);
             if (!this.userAssignedIdentityIdsToAssociate.Contains(identity.Id))
             {
                 this.userAssignedIdentityIdsToAssociate.Add(identity.Id);
             }
         }
         if (virtualMachineInner.Identity.IdentityIds == null)
         {
             virtualMachineInner.Identity.IdentityIds = new List <string>();
         }
         foreach (var identityId in this.userAssignedIdentityIdsToAssociate)
         {
             if (!virtualMachineInner.Identity.IdentityIds.Contains(identityId))
             {
                 virtualMachineInner.Identity.IdentityIds.Add(identityId);
             }
         }
         foreach (var identityId in this.userAssignedIdentityIdsToRemove)
         {
             if (virtualMachineInner.Identity.IdentityIds.Contains(identityId))
             {
                 virtualMachineInner.Identity.IdentityIds.Remove(identityId);
             }
         }
         if (virtualMachineInner.Identity.IdentityIds.Any())
         {
             this.installExtensionIfNotInstalled = true;
         }
     }
     finally
     {
         this.userAssignedIdentityCreatableKeys.Clear();
         this.userAssignedIdentityIdsToAssociate.Clear();
         this.userAssignedIdentityIdsToRemove.Clear();
     }
 }
Exemple #2
0
 /// <summary>
 /// Set user assigned identity ids to the given VMSS inner model
 /// </summary>
 /// <param name="vmssInner">the VMSS inner model</param>
 /// <param name="vmTaskGroup">the VMSS task group</param>
 internal void HandleUserAssignedIdentities(VirtualMachineScaleSetInner vmssInner, CreatorTaskGroup <IHasId> vmTaskGroup)
 {
     try
     {
         if (vmssInner.Identity == null || vmssInner.Identity.Type == null)
         {
             return;
         }
         ResourceIdentityType?parsedIdentityType = ResourceIdentityTypeEnumExtension.ParseResourceIdentityType(vmssInner.Identity.Type);
         if (parsedIdentityType.Equals(ResourceIdentityType.None) ||
             parsedIdentityType.Equals(ResourceIdentityType.SystemAssigned))
         {
             return;
         }
         foreach (var key in this.userAssignedIdentityCreatableKeys)
         {
             var identity = (IIdentity)vmTaskGroup.CreatedResource(key);
             if (!this.userAssignedIdentityIdsToAssociate.Contains(identity.Id))
             {
                 this.userAssignedIdentityIdsToAssociate.Add(identity.Id);
             }
         }
         if (vmssInner.Identity.IdentityIds == null)
         {
             vmssInner.Identity.IdentityIds = new List <string>();
         }
         foreach (var identityId in this.userAssignedIdentityIdsToAssociate)
         {
             if (!vmssInner.Identity.IdentityIds.Contains(identityId))
             {
                 vmssInner.Identity.IdentityIds.Add(identityId);
             }
         }
         foreach (var identityId in this.userAssignedIdentityIdsToRemove)
         {
             if (vmssInner.Identity.IdentityIds.Contains(identityId))
             {
                 vmssInner.Identity.IdentityIds.Remove(identityId);
             }
         }
     }
     finally
     {
         this.userAssignedIdentityCreatableKeys.Clear();
         this.userAssignedIdentityIdsToAssociate.Clear();
         this.userAssignedIdentityIdsToRemove.Clear();
     }
 }