Associate NSGs or clean them up

March 21, 2025 ยท View on GitHub

SYNOPSIS

Network Security Groups (NSGs) should be associated to a subnet or network interface.

DESCRIPTION

NSGs are basic stateful firewalls that are deployed as separate resources within your subscriptions. Each NSG can be associated to one or more network interfaces or subnets. NSGs that are not associated with a network interface or subnet perform no purpose and add to administration overhead.

RECOMMENDATION

Consider cleaning up NSGs that are not required to reduce technical debt. Also consider using Resource Groups to help manage the lifecycle of related resources together. Apply tags to all resources to help identify resources that are attached to specific workloads.

EXAMPLES

Configure with Azure CLI

To find orphaned NSG's run the following Azure CLI command:

az network nsg list -g $rgName --query "[?(subnets==null) && (networkInterfaces==null)].id" -o tsv