Microsoft.Network networkSecurityGroups

Remarks

For guidance on creating network security groups, see Create virtual network resources by using Bicep.

Bicep resource definition

The networkSecurityGroups resource type can be deployed with operations that target:

For a list of changed properties in each API version, see change log.

Usage Examples

Bicep Samples

A basic example of deploying network security group that contains a list of network security rules. Network security groups enable inbound or outbound traffic to be enabled or denied.

param resourceName string = 'acctest0001'
param location string = 'westeurope'

resource networkSecurityGroup 'Microsoft.Network/networkSecurityGroups@2022-07-01' = {
  name: resourceName
  location: location
  properties: {
    securityRules: []
  }
}

Azure Verified Modules

The following Azure Verified Modules can be used to deploy this resource type.

Module Description
Network Security Group AVM Resource Module for Network Security Group

Azure Quickstart Samples

The following Azure Quickstart templates contain Bicep samples for deploying this resource type.

Bicep File Description
101-1vm-2nics-2subnets-1vnet Creates a new VM with two NICs which connect to two different subnets within the same VNet.
2 VMs in a Load Balancer and configure NAT rules on the LB This template allows you to create 2 Virtual Machines in an Availability Set and configure NAT rules through the load balancer. This template also deploys a Storage Account, Virtual Network, Public IP address and Network Interfaces. In this template, we use the resource loops capability to create the network interfaces and virtual machines
AKS Cluster with a NAT Gateway and an Application Gateway This sample shows how to a deploy an AKS cluster with NAT Gateway for outbound connections and an Application Gateway for inbound connections.
AKS cluster with the Application Gateway Ingress Controller This sample shows how to deploy an AKS cluster with Application Gateway, Application Gateway Ingress Controller, Azure Container Registry, Log Analytics and Key Vault
Application Gateway with internal API Management and Web App Application Gateway routing Internet traffic to a virtual network (internal mode) API Management instance which services a web API hosted in an Azure Web App.
Azure Application Gateway Log Analyzer using GoAccess This template uses the Azure Linux CustomScript extension to deploy an Azure Application Gateway Log Analyzer using GoAccess. The deployment template creates an Ubuntu VM, installs Application Gateway Log Processor, GoAccess, Apache WebServer and configures it to analyze Azure Application Gateway access logs.
Azure Bastion as a Service with NSG This template provisions Azure Bastion in a Virtual Network
Azure Batch pool without public IP addresses This template creates Azure Batch simplified node communication pool without public IP addresses.
Azure Cloud Shell - VNet This template deploys Azure Cloud Shell resources into an Azure virtual network.
Azure Databricks All-in-one Templat VNetInjection-Pvtendpt This template allows you to create a network security group, a virtual network and an Azure Databricks workspace with the virtual network, and Private Endpoint.
Azure Game Developer Virtual Machine Azure Game Developer Virtual Machine includes Licencsed Engines like Unreal.
Azure Game Developer Virtual Machine Scale Set Azure Game Developer Virtual Machine Scale Set includes Licencsed Engines like Unreal.
Azure Machine Learning end-to-end secure setup This set of Bicep templates demonstrates how to set up Azure Machine Learning end-to-end in a secure set up. This reference implementation includes the Workspace, a compute cluster, compute instance and attached private AKS cluster.
Azure Machine Learning end-to-end secure setup (legacy) This set of Bicep templates demonstrates how to set up Azure Machine Learning end-to-end in a secure set up. This reference implementation includes the Workspace, a compute cluster, compute instance and attached private AKS cluster.
Azure Traffic Manager VM example This template shows how to create an Azure Traffic Manager profile load-balancing across multiple virtual machines.
AzureDatabricks Template for Default Storage Firewall This template allows you to create a network security group, a virtual network, private endpoint, and a default storage firewall enabled Azure Databricks workspace with the virtual network and the system-assigned access connector.
AzureDatabricks Template for VNet Injection with NAT Gateway This template allows you to create a NAT gateway, network security group, a virtual network and an Azure Databricks workspace with the virtual network.
AzureDatabricks Template for VNetInjection and Load Balancer This template allows you to create a a load balancer, network security group, a virtual network and an Azure Databricks workspace with the virtual network.
CentOS/UbuntuServer Auto Dynamic Disks & Docker 1.12(cs) This is a common template for creating single instance CentOS 7.2/7.1/6.5 or Ubuntu Server 16.04.0-LTS with configurable number of data disks (configurable sizes). Maximum 16 disks can be mentioned in the portal parameters and maximum size of each disk should be less than 1023 GB. The MDADM RAID0 Array is automounted and survives restarts. Latest Docker 1.12(cs3) (Swarm), docker-compose 1.9.0 & docker-machine 0.8.2 is available for usage from user azure-cli is auto running as a docker container. This single instance template is an offshoot of the HPC/GPU Clusters Template @ https://github.com/azurebigcompute/BigComputeBench
Create a cross-region load balancer This template creates a cross-region load balancer with a backend pool containing two regional load balancers. Cross-region load balancer is currently available in limited regions. The regional load balancers behind the cross-region load balancer can be in any region.
Create a Private AKS Cluster This sample shows how to create a private AKS cluster in a virtual network along with a jumpbox virtual machine.
Create a sandbox setup of Azure Firewall with Linux VMs This template creates a virtual network with 3 subnets (server subnet, jumpbox subet and AzureFirewall subnet), a jumpbox VM with public IP, A server VM, UDR route to point to Azure Firewall for the Server Subnet and an Azure Firewall with 1 or more Public IP addresses, 1 sample application rule, 1 sample network rule and default private ranges
Create a sandbox setup of Azure Firewall with Zones This template creates a virtual network with three subnets (server subnet, jumpbox subnet, and Azure Firewall subnet), a jumpbox VM with public IP, A server VM, UDR route to point to Azure Firewall for the ServerSubnet,an Azure Firewall with one or more Public IP addresses, one sample application rule, and one sample network rule and Azure Firewall in Availability Zones 1, 2, and 3.
Create a standard load-balancer This template creates an Internet-facing load-balancer, load balancing rules, and three VMs for the backend pool with each VM in a redundant zone.
Create a VM with multiple empty StandardSSD_LRS Data Disks This template allows you to create a Windows Virtual Machine from a specified image. It also attaches multiple empty StandardSSD data disks by default. Note that you can specify the size and the Storage type (Standard_LRS, StandardSSD_LRS and Premium_LRS) of the empty data disks.
Create a VM with multiple NICs and RDP accessible This template allows you to create a Virtual Machines with multiple (2) network interfaces (NICs), and RDP connectable with a configured load balancer and an inbound NAT rule. More NICs can easily be added with this template. This template also deploys a Storage Account, Virtual Network, Public IP address, and 2 Network Interfaces (front-end and back-end).
Create an AppServicePlan and App in an ASEv3 Create an AppServicePlan and App in an ASEv3
Create an Azure Application Gateway v2 This template creates an Azure Application Gateway with two Windows Server 2016 servers in the backend pool
Create an Azure Firewall with IpGroups This template creates an Azure Firewall with Application and Network Rules referring to IP Groups. Also, includes a Linux Jumpbox vm setup
Create an Azure Firewall with multiple IP public addresses This template creates an Azure Firewall with two public IP addresses and two Windows Server 2019 servers to test.
Create an Azure WAF v2 on Azure Application Gateway This template creates an Azure Web Application Firewall v2 on Azure Application Gateway with two Windows Server 2016 servers in the backend pool
Create an Ubuntu GNOME desktop This template creates an ubuntu desktop machine. This works great for use as a jumpbox behind a NAT.
Create sandbox of Azure Firewall, client VM, and server VM This template creates a virtual network with 2 subnets (server subnet and AzureFirewall subnet), A server VM, a client VM, a public IP address for each VM, and a route table to send traffic between VMs through the firewall.
Create SQL MI inside the new virtual network Deploy Azure Sql Database Managed Instance (SQL MI) inside new Virtual Network.
Deploy a Linux or Windows VM with MSI This template allows you to deploy a Linux or Windows VM with a Managed Service Identity.
Deploy a Nextflow genomics cluster This template deploys a scalable Nextflow cluster with a Jumpbox, n cluster nodes, docker support and shared storage.
Deploy a simple Ubuntu Linux VM 20.04-LTS This template deploys an Ubuntu Server with a few options for the VM. You can provide the VM Name, OS Version, VM size, and admin username and password. As default the VM size is Standard_D2s_v3 and OS version is 20.04-LTS.
Deploy a simple Windows VM This template allows you to deploy a simple Windows VM using a few different options for the Windows version, using the latest patched version. This will deploy an A2 size VM in the resource group location and return the FQDN of the VM.
Deploy a simple Windows VM with tags This template will deploy a D2_v3 Windows VM, NIC, Storage Account, Virtual Network, Public IP Address, and Network Security Group. The tag object is created in the variables and will be applied on all resources, where applicable.
Deploy a trusted launch capable Linux virtual machine This template allows you to deploy a trusted launch capable Linux virtual machine using a few different options for the Linux version, using the latest patched version. If you enable Secureboot and vTPM, the Guest Attestation extension will be installed on your VM. This extension will perform remote attestation by the cloud. By default, this will deploy an Standard_D2_v3 size virtual machine in the resource group location and return the FQDN of the virtual machine.
Deploy a trusted launch capable Windows virtual machine This template allows you to deploy a trusted launch capable Windows virtual machine using a few different options for the Windows version, using the latest patched version. If you enable Secureboot and vTPM, the Guest Attestation extension will be installed on your VM. This extension will perform remote attestation by the cloud. By default, this will deploy an Standard_D2_v3 size virtual machine in the resource group location and return the FQDN of the virtual machine.
Deploy a Ubuntu Linux DataScience VM 18.04 This template deploy a Ubuntu Server with some tools for Data Science. You can provide the username, password, virtual machine name and select between CPU or GPU computing.
Deploy a Virtual Machine with Custom Data This template allows you to create a Virtual Machine with Custom Data passed down to the VM. This template also deploys a Storage Account, Virtual Network, Public IP addresses and a Network Interface.
Deploy a Windows VM and enable backup using Azure Backup This template allows you to deploy a Windows VM and Recovery Services Vault configured with the DefaultPolicy for Protection.
Deploy a Windows VM with Windows Admin Center extension This template allows you to deploy a Windows VM with Windows Admin Center extension to manage the VM directly from Azure Portal.
Deploy Anbox Cloud This template deploys Anbox Cloud on an Ubuntu VM. Completing the installation of Anbox Cloud requires user interaction following the deployment; please consult the README for instructions. The template supports both launching of a VM from an Ubuntu Pro image and association of an Ubuntu Pro token with a VM launched from a non-Pro image. The former is the default behaviour; users seeking to attach a token to a VM launched from a non-Pro image must override the default arguments for the ubuntuImageOffer, ubuntuImageSKU, and ubuntuProToken parameters. The template is also parametric in the VM size and disk sizes. Non-default argument values for these parameters must comply with https://documentation.ubuntu.com/anbox-cloud/reference/requirements/#anbox-cloud-appliance-4.
Deploy API Management in external VNet with public IP This template demonstrates how to create an instance of Azure API Management in the Premium tier within your virtual network's subnet in external mode and configure recommended NSG rules on the subnet. The instance is deployed to two availability zones. The template also configures a public IP address from your subscription.
Deploy API Management in internal VNet with public IP This template demonstrates how to create an instance of Azure API Management in the Premium tier within your virtual network's subnet in internal mode and configure recommended NSG rules on the subnet. The instance is deployed to two availability zones. The template also configures a public IP address from your subscription.
Deploy Darktrace vSensors This template allows you to deploy one or more stand-alone Darktrace vSensors
Deploy Secure AI Foundry with a managed virtual network This template creates a secure Azure AI Foundry environment with robust network and identity security restrictions.
Deploy Shibboleth Identity Provider cluster on Windows This template deploys Shibboleth Identity Provider on Windows in a clustered configuration. After the deployment is successful, you can go to https://your-domain:8443/idp/profile/status (note port number) to check success.
Deploy Ubuntu VM with Open JDK and Tomcat This template allows you to create a Ubuntu VM with OpenJDK and Tomcat. Currently custom script file is pulled temporarily from https link on raw.githubusercontent.com/snallami/templates/master/ubuntu/java-tomcat-install.sh. Once the VM is successfully provisioned, tomcat installation can be verified by accessing the http link [FQDN name or public IP]:8080/
ExpressRoute circuit with private peering and Azure VNet This template configure ExpressRoute Microsoft peering, deploy an Azure VNet with Expressroute gateway and link the VNet to the ExpressRoute circuit
FinOps hub This template creates a new FinOps hub instance, including Data Explorer, Data Lake storage, and Data Factory.
Front Door Standard/Premium with API Management origin This template creates a Front Door Premium and an API Management instance, and uses an NSG and global API Management policy to validate that traffic has come through the Front Door origin.
Front Door Standard/Premium with Application Gateway origin This template creates a Front Door Standard/Premium and an Application Gateway instance, and uses an NSG and WAF policy to validate that traffic has come through the Front Door origin.
Front Door with Container Instances and Application Gateway This template creates a Front Door Standard/Premium with a container group and Application Gateway.
GitLab Omnibus This template simplifies the deployment of GitLab Omnibus on a Virtual Machine with a public DNS, leveraging the public IP's DNS. It utilizes the Standard_F8s_v2 instance size, which aligns with reference architecture and supports up to 1000 users (20 RPS). The instance is pre-configured to use HTTPS with a Let's Encrypt certificate for secure connections.
Hub-Spoke Network with NAT Gateway and Azure Firewall Deploy a hub-spoke network topology with NAT gateway, Azure Firewall, and virtual machine
Hyper-V Host Virtual Machine with nested VMs Deploys a Virtual Machine to by a Hyper-V Host and all dependent resources including virtual network, public IP address and route tables.
IIS Server using DSC extension on a Windows VM This template creates a Windows VM and sets up an IIS server using the DSC extension. Note, the DSC configuration module needs a SAS token to be passed in if you are using Azure Storage. For DSC module link from GitHub (default in this template), this is not needed.
IIS VMs & SQL Server 2014 VM Create 1 or 2 IIS Windows 2012 R2 Web Servers and one back end SQL Server 2014 in VNET.
Linux VM with Gnome Desktop RDP VS Code and Azure CLI This template deploys an Ubuntu Server VM, then uses the Linux CustomScript extension to install the Ubuntu Gnome Desktop and Remote Desktop support (via xrdp). The final provisioned Ubuntu VM support remote connections over RDP.
Linux VM with MSI Accessing Storage This template deploys a linux VM with a system assigned managed identity that has access to a storage account in a different resource group.
Managed Azure Active Directory Domain Services This template deploys an Managed Azure Active Directory Domain Service with required VNet and NSG configurations.
Multi VM Template with Managed Disk This template will create N number of VM's with managed disks, public IPs and network interfaces. It will create the VMs in a single Availability Set. They will be provisioned in a Virtual Network which will also be created as part of the deployment
Network Security Group with diagnostic logs This template creates a Network Security Group with diagnostic logs and a resource lock
OpenScholar This template deploys a OpenScholar to the ubuntu VM 16.04
Public Load Balancer chained to a Gateway Load Balancer This template allows you to deploy a Public Standard Load Balancer chained to a Gateway Load Balancer. The traffic incoming from internet is routed to the Gateway Load Balancer with linux VMs (NVAs) in the backend pool.
Push a certificate onto a Windows VM Push a certificate onto a Windows VM. Create the Key Vault using the template at https://github.com/Azure/azure-quickstart-templates/tree/master/quickstarts/microsoft.keyvault/key-vault-create
Secured virtual hubs This template creates a secured virtual hub using Azure Firewall to secure your cloud network traffic destined to the Internet.
Self-host Integration Runtime on Azure VMs This template creates a selfhost integration runtime and registers it on Azure virtual machines
Site-to-Site VPN with active-active VPN Gateways with BGP This template allows you to deploy a site-to-site VPN between two VNets with VPN Gateways in configuration active-active with BGP. Each Azure VPN Gateway resolves the FQDN of the remote peers to determine the public IP of the remote VPN Gateway. Template runs as expected in Azure regions with availability zones.
SQL Server VM with performance optimized storage settings Create a SQL Server Virtual Machine with performance optimized storage settings on PremiumSSD
Ubuntu Mate Desktop VM with VS Code This template allows you to deploy a simple Linux VM using a few different options for the Ubuntu version, using the latest patched version. This will deploy a A1 size VM in the resource group location and return the FQDN of the VM.
Use Azure Firewall as a DNS Proxy in a Hub & Spoke topology This sample show how to deploy a hub-spoke topology in Azure using the Azure Firewall. The hub virtual network acts as a central point of connectivity to many spoke virtual networks that are connected to hub virtual network via virtual network peering.
Virtual machine with an RDP port Creates a virtual machine and creates a NAT rule for RDP to the VM in load balancer
Virtual Machine with Conditional Resources This template allows deploying a linux VM using new or existing resources for the Virtual Network, Storage and Public IP Address. It also allows for choosing between SSH and Password authenticate. The templates uses conditions and logic functions to remove the need for nested deployments.
Virtual Network NAT with VM Deploy a NAT gateway and virtual machine
VMs in Availability Zones with a Load Balancer and NAT This template allows you to create Virtual Machines distributed across Availability Zones with a Load Balancer and configure NAT rules through the load balancer. This template also deploys a Virtual Network, Public IP address and Network Interfaces. In this template, we use the resource loops capability to create the network interfaces and virtual machines
VMSS Flexible Orchestration Mode Quickstart Linux This template deploys a simple VM Scale Set with instances behind an Azure Load Balancer. The VM Scale set is in Flexible Orchestration Mode. Use the os parameter to choose Linux (Ubuntu) or Windows (Windows Server Datacenter 2019) deployment. NOTE: This quickstart template enables network access to VM management ports (SSH, RDP) from any internet address, and should not be used for production deployments.
Windows Docker Host with Portainer and Traefik pre-installed Windows Docker Host with Portainer and Traefik pre-installed
Windows Server VM with SSH Deploy a single Windows VM with Open SSH enabled so that you can connect through SSH using key-based authentication.
Windows VM with Azure secure baseline The template creates a virtual machine running Windows Server in a new virtual network, with a public IP address. Once the machine has deployed, the guest configuration extension is installed and the Azure secure baseline for Windows Server is applied. If the configuration of the machines drifts, you can re-apply the settings by deploying the template again.

Resource format

To create a Microsoft.Network/networkSecurityGroups resource, add the following Bicep to your template.

resource symbolicname 'Microsoft.Network/networkSecurityGroups@2025-07-01' = {
  location: 'string'
  name: 'string'
  properties: {
    flushConnection: bool
    securityRules: [
      {
        id: 'string'
        name: 'string'
        properties: {
          access: 'string'
          description: 'string'
          destinationAddressPrefix: 'string'
          destinationAddressPrefixes: [
            'string'
          ]
          destinationApplicationSecurityGroups: [
            {
              id: 'string'
              location: 'string'
              properties: {}
              tags: {
                {customized property}: 'string'
              }
            }
          ]
          destinationPortRange: 'string'
          destinationPortRanges: [
            'string'
          ]
          direction: 'string'
          priority: int
          protocol: 'string'
          sourceAddressPrefix: 'string'
          sourceAddressPrefixes: [
            'string'
          ]
          sourceApplicationSecurityGroups: [
            {
              id: 'string'
              location: 'string'
              properties: {}
              tags: {
                {customized property}: 'string'
              }
            }
          ]
          sourcePortRange: 'string'
          sourcePortRanges: [
            'string'
          ]
        }
      }
    ]
  }
  tags: {
    {customized property}: 'string'
  }
}

Property Values

Microsoft.Network/networkSecurityGroups

Name Description Value
location Resource location. string
name The resource name string (required)
properties Properties of the network security group. CommonNetworkSecurityGroupPropertiesFormat
tags Resource tags Dictionary of tag names and values. See Tags in templates

CommonApplicationSecurityGroup

Name Description Value
id Resource ID. string
location Resource location. string
properties Properties of the application security group. CommonApplicationSecurityGroupPropertiesFormat
tags Resource tags. CommonResourceTags

CommonApplicationSecurityGroupPropertiesFormat

Name Description Value

CommonNetworkSecurityGroupPropertiesFormat

Name Description Value
flushConnection When enabled, flows created from Network Security Group connections will be re-evaluated when rules are updates. Initial enablement will trigger re-evaluation. bool
securityRules A collection of security rules of the network security group. CommonSecurityRule[]

CommonResourceTags

Name Description Value

CommonResourceTags

Name Description Value

CommonSecurityRule

Name Description Value
id Resource ID. string
name Name of the resource. string
properties Properties of the security rule. CommonSecurityRulePropertiesFormat

CommonSecurityRulePropertiesFormat

Name Description Value
access The network traffic is allowed or denied. 'Allow'
'Deny' (required)
description A description for this rule. Restricted to 140 chars. string
destinationAddressPrefix The destination address prefix. CIDR or destination IP range. Asterisk '*' can also be used to match all source IPs. Default tags such as 'VirtualNetwork', 'AzureLoadBalancer' and 'Internet' can also be used. string
destinationAddressPrefixes The destination address prefixes. CIDR or destination IP ranges. string[]
destinationApplicationSecurityGroups The application security group specified as destination. CommonApplicationSecurityGroup[]
destinationPortRange The destination port or range. Integer or range between 0 and 65535. Asterisk '*' can also be used to match all ports. string
destinationPortRanges The destination port ranges. string[]
direction The direction of the rule. The direction specifies if rule will be evaluated on incoming or outgoing traffic. 'Inbound'
'Outbound' (required)
priority The priority of the rule. The value can be between 100 and 4096. The priority number must be unique for each rule in the collection. The lower the priority number, the higher the priority of the rule. int (required)
protocol Network protocol this rule applies to. '*'
'Ah'
'Esp'
'Icmp'
'Tcp'
'Udp' (required)
sourceAddressPrefix The CIDR or source IP range. Asterisk '*' can also be used to match all source IPs. Default tags such as 'VirtualNetwork', 'AzureLoadBalancer' and 'Internet' can also be used. If this is an ingress rule, specifies where network traffic originates from. string
sourceAddressPrefixes The CIDR or source IP ranges. string[]
sourceApplicationSecurityGroups The application security group specified as source. CommonApplicationSecurityGroup[]
sourcePortRange The source port or range. Integer or range between 0 and 65535. Asterisk '*' can also be used to match all ports. string
sourcePortRanges The source port ranges. string[]

ARM template resource definition

The networkSecurityGroups resource type can be deployed with operations that target:

Usage Examples

Azure Quickstart Templates

The following Azure Quickstart templates deploy this resource type.

Template Description
1 VM in vNet - Multiple data disks

Deploy to Azure
This template creates a single VM running Windows Server 2016 with multiple data disks attached.
101-1vm-2nics-2subnets-1vnet

Deploy to Azure
Creates a new VM with two NICs which connect to two different subnets within the same VNet.
2 VMs in a Load Balancer and configure NAT rules on the LB

Deploy to Azure
This template allows you to create 2 Virtual Machines in an Availability Set and configure NAT rules through the load balancer. This template also deploys a Storage Account, Virtual Network, Public IP address and Network Interfaces. In this template, we use the resource loops capability to create the network interfaces and virtual machines
201-vnet-2subnets-service-endpoints-storage-integration

Deploy to Azure
Creates 2 new VMs with a NIC each, in two different subnets within the same VNet. Sets service endpoint on one of the subnets and secures storage account to that subnet.
Add an NSG with Redis security rules to an existing subnet

Deploy to Azure
This template allows you to add an NSG with preconfigured Azure Redis Cache security rules to an existing subnet within a VNET. Deploy into the resource group of the existing VNET.
Add multiple VMs into a Virtual Machine Scale Set

Deploy to Azure
This template will create N number of VM's with managed disks, public IPs and network interfaces. It will create the VMs in a Virtual Machine Scale Set in Flexible Orchestration mode. They will be provisioned in a Virtual Network which will also be created as part of the deployment
AKS Cluster with a NAT Gateway and an Application Gateway

Deploy to Azure
This sample shows how to a deploy an AKS cluster with NAT Gateway for outbound connections and an Application Gateway for inbound connections.
AKS cluster with the Application Gateway Ingress Controller

Deploy to Azure
This sample shows how to deploy an AKS cluster with Application Gateway, Application Gateway Ingress Controller, Azure Container Registry, Log Analytics and Key Vault
Apache Webserver on Ubuntu VM

Deploy to Azure
This template uses the Azure Linux CustomScript extension to deploy an Apache web server. The deployment template creates an Ubuntu VM, installs Apache2 and creates a simple HTML file. Go to ../demo.html to see the deployed page.
App Gateway with WAF, SSL, IIS and HTTPS redirection