Review subnet NSG associations

Check that the subnet has appropriate NSG associations and effective security rules.

Description

Check which network security group (NSG) is associated with the deployed subnet. Omitting security_group leaves a new subnet without a specified NSG, but an update can preserve an existing association.

Potential impact

A missing NSG can leave intended subnet restrictions unapplied. Leave the service subnets GatewaySubnet and AzureFirewallSubnet without an NSG.

Remediation

For an application subnet, set security_group to the existing NSG name or resource ID. Review the effective subnet and NIC rules and their priorities, then test both permitted and denied connections.

Examples

For the short module name, install azure.azcollection and include it in the play’s collections. The second task attaches mySecurityGroup in myResourceGroup to mySubnet in the existing VNet. Neither task creates the group or its rules.

Before

yaml
- name: Create a subnet
  azure_rm_subnet:
    resource_group: myResourceGroup
    virtual_network_name: myVirtualNetwork
    name: mySubnet
    address_prefix_cidr: "10.1.0.0/24"

After

yaml
- name: Create a subnet
  azure_rm_subnet:
    resource_group: myResourceGroup
    virtual_network_name: myVirtualNetwork
    name: mySubnet
    address_prefix_cidr: "10.1.0.0/24"
    security_group: mySecurityGroup

References