Azure Network Network Security Group Association
This page shows how to write Terraform and Azure Resource Manager for Network Network Security Group Association and write them securely.
azurerm_subnet_network_security_group_association (Terraform)
The Network Security Group Association in Network can be configured in Terraform with the resource name azurerm_subnet_network_security_group_association
. The following sections describe 10 examples of how to use the resource and its parameters.
Example Usage from GitHub
resource "azurerm_subnet_network_security_group_association" "jinwoo-nsgass-01" {
subnet_id = azurerm_subnet.jinwoo-subnet-01.id
network_security_group_id = azurerm_network_security_group.jinwoo-nsg-lb.id
}
resource "azurerm_subnet_network_security_group_association" "jinwoo-nsgass-02" {
resource "azurerm_subnet_network_security_group_association" "jisoo_nsgass1" {
subnet_id = azurerm_subnet.jisoo_sub1.id
network_security_group_id = azurerm_network_security_group.jisoo_nsg1.id
}
resource "azurerm_subnet_network_security_group_association" "jisoo_nsgass2" {
resource "azurerm_subnet_network_security_group_association" "ericassociation1" {
subnet_id = azurerm_subnet.subnet1.id
network_security_group_id = azurerm_network_security_group.ericnsg.id
}
resource "azurerm_subnet_network_security_group_association" "ericassociation2" {
resource "azurerm_subnet_network_security_group_association" "network_security_group_association_1" {
subnet_id = azurerm_subnet.subnet_2.id
network_security_group_id = azurerm_network_security_group.network_security_group_1.id
}
resource "azurerm_subnet_network_security_group_association" "network_security_group_association_2" {
resource "azurerm_subnet_network_security_group_association" "web-nsg-subnet" {
subnet_id = var.web_subnet_id
network_security_group_id = azurerm_network_security_group.web-nsg.id
}
resource "azurerm_subnet_network_security_group_association" "nsg_internal_subnet_association" {
subnet_id = data.azurerm_subnet.internal_subnet.id
network_security_group_id = azurerm_network_security_group.baseline_network_security_group.id
}
resource "azurerm_subnet_network_security_group_association" "nsg_external_subnet_association" {
resource "azurerm_subnet_network_security_group_association" "shyun_nsgass_lb" {
subnet_id = azurerm_subnet.shyun_sn1.id
network_security_group_id = azurerm_network_security_group.shyun_nsg_lb.id
}
resource "azurerm_subnet_network_security_group_association" "shyun_nsgass_web" {
resource "azurerm_subnet_network_security_group_association" "palo-mgmt" {
network_security_group_id = azurerm_network_security_group.default.id
subnet_id = azurerm_subnet.palo-mgmt.id
}
resource "azurerm_subnet" "palo-trusted" {
resource "azurerm_subnet_network_security_group_association" "shyun_snsgass1" {
subnet_id = azurerm_subnet.shyun_subnet1.id
network_security_group_id = azurerm_network_security_group.shyun_vnsg.id
}
resource "azurerm_subnet_network_security_group_association" "shyun_snsgass2" {
resource "azurerm_subnet_network_security_group_association" "jisoo_nsgass1" {
subnet_id = azurerm_subnet.jisoo_sub1.id
network_security_group_id = azurerm_network_security_group.jisoo_nsg1.id
}
resource "azurerm_subnet_network_security_group_association" "jisoo_nsgass2" {
Parameters
-
id
optional computed - string -
network_security_group_id
required - string -
subnet_id
required - string -
timeouts
single block
Explanation in Terraform Registry
Associates a Network Security Group with a Subnet within a Virtual Network.
Tips: Best Practices for The Other Azure Network Resources
In addition to the azurerm_network_security_group, Azure Network has the other resources that should be configured for security reasons. Please check some examples of those resources and precautions.
azurerm_network_security_group
Ensure to disable RDP port from the Internet
It is better to disable the RDP port from the Internet. RDP access should not be accepted from the Internet (*, 0.0.0.0, /0, internet, any), and consider using the Azure Bastion Service.
azurerm_network_security_rule
Ensure to set a more restrictive CIDR range for ingress from the internet
It is better to set a more restrictive CIDR range not to use very broad subnets. If possible, segments should be divided into smaller subnets.
azurerm_network_watcher_flow_log
Ensure to enable Retention policy for flow logs and set it to enough duration
It is better to enable a retention policy for flow logs. Flow logs show us all network activity in the cloud environment and support us when we face critical incidents.
Microsoft.Network/virtualNetworks/subnets (Azure Resource Manager)
The virtualNetworks/subnets in Microsoft.Network can be configured in Azure Resource Manager with the resource name Microsoft.Network/virtualNetworks/subnets
. The following sections describe how to use the resource and its parameters.
Example Usage from GitHub
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"functions": [],
"variables": {
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"adminPassword": {
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"networkSecurityGroupName": {
Parameters
name
required - stringtype
required - stringapiVersion
required - stringproperties
requiredaddressPrefix
required - stringThe address prefix for the subnet.
addressPrefixes
optional - arrayList of address prefixes for the subnet.
networkSecurityGroup
optionalid
required - stringResource ID.
routeTable
optionalid
required - stringResource ID.
natGateway
optionalid
required - stringResource ID.
serviceEndpoints
optional arrayservice
optional - stringThe type of the endpoint service.
locations
optional - arrayA list of locations.
serviceEndpointPolicies
optional arrayid
required - stringResource ID.
ipAllocations
optional arrayid
required - stringResource ID.
delegations
optional arrayproperties
optionalserviceName
optional - stringThe name of the service to whom the subnet should be delegated (e.g. Microsoft.Sql/servers).
name
required - stringThe name of the resource that is unique within a subnet. This name can be used to access the resource.
privateEndpointNetworkPolicies
optional - stringEnable or Disable apply network policies on private end point in the subnet.
privateLinkServiceNetworkPolicies
optional - stringEnable or Disable apply network policies on private link service in the subnet.
Frequently asked questions
What is Azure Network Network Security Group Association?
Azure Network Network Security Group Association is a resource for Network of Microsoft Azure. Settings can be wrote in Terraform.
Where can I find the example code for the Azure Network Network Security Group Association?
For Terraform, the WhiteHair-H/Eruza_terraform, ICANDOITTT/azurpract and yuericyu/terraform-azure-labs source code examples are useful. See the Terraform Example section for further details.
For Azure Resource Manager, the INGourav/bicep, INGourav/bicep and ruchipalchopra/AzureDevopsSelfHostedAgents source code examples are useful. See the Azure Resource Manager Example section for further details.