Thanks for reaching Microsoft Q&A.
The issue is because VMSS manages NICs dynamically. Here's how to fix it:
Solutions
- Target VMSS Directly: Create a policy for
Microsoft.Compute/virtualMachineScaleSets
to ensure NICs inherit tags. - Policy Timing: Use a custom policy for NICs and ensure it evaluates after VMSS creation.
- Remediation Task: Periodically reapply tags using a remediation task.
- 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
- Target VMSS Directly: Create a policy for
Microsoft.Compute/virtualMachineScaleSets
to ensure NICs inherit tags. - Policy Timing: Use a custom policy for NICs and ensure it evaluates after VMSS creation.
- Remediation Task: Periodically reapply tags using a remediation task.
- ARM Templates: Embed tags in ARM templates or deployment scripts.
- Scope: Assign the policy at the correct scope.
- Existing VMSS: Update the existing VMSS instances.
- Testing: Test your policy and remediation tasks thoroughly.
- Target VMSS Directly: Create a policy for
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.