Tags not getting applied to VMSS NICs by BuiltIn Policy

Ravi Sheoran 0 Reputation points
2025-02-20T13:14:31.6266667+00:00

We have a BuiltIn Policy Add or replace a tag on resources that is supposed to add a moniker tag on all resources. It is not working for NICs created within Virtual Machine Scale Sets. We've noticed that initially the tag gets applied, but once the VM creation is complete the tag for the NICs vanish.

Azure Virtual Machine Scale Sets
Azure Virtual Machine Scale Sets
Azure compute resources that are used to create and manage groups of heterogeneous load-balanced virtual machines.
431 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Vidya Viraktamath 550 Reputation points Microsoft Employee
    2025-02-20T15:25:05.2733333+00:00

    Thanks for reaching Microsoft Q&A.

    The issue is because VMSS manages NICs dynamically. Here's how to fix it:

    Solutions

    1. Target VMSS Directly: Create a policy for Microsoft.Compute/virtualMachineScaleSets to ensure NICs inherit tags.
    2. Policy Timing: Use a custom policy for NICs and ensure it evaluates after VMSS creation.
    3. Remediation Task: Periodically reapply tags using a remediation task.
    4. ARM Templates: Embed tags in ARM templates or deployment scripts.

    Key Considerations

    • Scope: Assign the policy at the correct scope.
    • Existing VMSS: Update or redeploy existing VMSS instances.
    • Testing: Test your policy and remediation tasks thoroughly. You're encountering an issue where tags on VMSS NICs are lost after VM creation. This happens because VMSS manages NICs dynamically. Here's how to fix it: Solutions
      1. Target VMSS Directly: Create a policy for Microsoft.Compute/virtualMachineScaleSets to ensure NICs inherit tags.
      2. Policy Timing: Use a custom policy for NICs and ensure it evaluates after VMSS creation.
      3. Remediation Task: Periodically reapply tags using a remediation task.
      4. ARM Templates: Embed tags in ARM templates or deployment scripts.
      Key Considerations
      • Scope: Assign the policy at the correct scope.
      • Existing VMSS: Update the existing VMSS instances.
      • Testing: Test your policy and remediation tasks thoroughly.

    Please refer below documentation tagging policies and policy remediation.

    Please 'Accept as answer' and ‘Upvote’ if it helped so that it can help others in the community looking for help on similar topics.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.