Azure Network Interface Security Group Association
This page shows how to write Terraform and Azure Resource Manager for Network Interface Security Group Association and write them securely.
azurerm_network_interface_security_group_association (Terraform)
The Interface Security Group Association in Network can be configured in Terraform with the resource name azurerm_network_interface_security_group_association
. The following sections describe 10 examples of how to use the resource and its parameters.
Example Usage from GitHub
resource "azurerm_network_interface_security_group_association" "mySecGroupAssociation1" {
network_interface_id = azurerm_network_interface.myNic1.id
network_security_group_id = azurerm_network_security_group.mySecGroup.id
}
resource "azurerm_network_interface_security_group_association" "sqlhagrpAsso-sql1" {
network_interface_id = azurerm_network_interface.sqlserver-nic-1.id
network_security_group_id = data.azurerm_network_security_group.sqlhagrp.id
}
resource "azurerm_network_interface_security_group_association" "sqlhagrpAsso-sql2" {
resource "azurerm_network_interface_security_group_association" "sgNFS" {
network_interface_id = azurerm_network_interface.interfazNFS.id
network_security_group_id = azurerm_network_security_group.mySecGroup.id
}
resource "azurerm_network_interface_security_group_association" "association_SG_HaProxy" {
network_interface_id = azurerm_network_interface.NIC_HaProxy.id
network_security_group_id = azurerm_network_security_group.Allow_SSH_HTTP_HTTPS_Paris_FRONT.id
}
# resource "azurerm_network_interface_security_group_association" "association_SG_HaProxy_backup" {
# network_interface_id = azurerm_network_interface.NIC_HaProxy_backup.id
resource "azurerm_network_interface_security_group_association" "primary_port1_nsg" {
depends_on = [azurerm_network_interface.primary_port1]
network_interface_id = azurerm_network_interface.primary_port1.id
network_security_group_id = azurerm_network_security_group.outside_nsg.id
}
resource "azurerm_network_interface_security_group_association" "nsg_nic" {
network_interface_id = azurerm_network_interface.nic1.id
network_security_group_id = azurerm_network_security_group.public.id
}
resource "azurerm_network_interface_security_group_association" "mySecGroupAssociationMaster" {
network_interface_id = azurerm_network_interface.myNicMaster.id
network_security_group_id = azurerm_network_security_group.mySecGroupMaster.id
}
# Security group Worker01
resource "azurerm_network_interface_security_group_association" "master" {
network_interface_id = azurerm_network_interface.myNic1.id
network_security_group_id = azurerm_network_security_group.mynsg.id
}
# Connect the security group to the network interface
resource "azurerm_network_interface_security_group_association" "SecGroupAssociationMaster" {
network_interface_id = azurerm_network_interface.nic-master.id
network_security_group_id = azurerm_network_security_group.mySecGroup.id
}
resource "azurerm_network_interface_security_group_association" "lpsc_SecGroupAssociation1" {
network_interface_id = azurerm_network_interface.lpsc_Nic1.id
network_security_group_id = azurerm_network_security_group.lpsc_SecGroup.id
}
# hacemos la relacion con el grupo de seguridad y la interface de red del NIC 2
Parameters
-
id
optional computed - string -
network_interface_id
required - string -
network_security_group_id
required - string -
timeouts
single block
Explanation in Terraform Registry
Manages the association between a Network Interface and a Network Security Group.
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/networkSecurityGroups (Azure Resource Manager)
The networkSecurityGroups in Microsoft.Network can be configured in Azure Resource Manager with the resource name Microsoft.Network/networkSecurityGroups
. The following sections describe how to use the resource and its parameters.
Example Usage from GitHub
"type": "Microsoft.Network/networkSecurityGroups",
"location": "eastus",
"properties": {
"provisioningState": "Succeeded",
"resourceGuid": "94a0c0a4-cdba-45b0-b2b1-b6f602d8981e",
"securityRules": [
"type": "Microsoft.Network/networkSecurityGroups",
"location": "eastus",
"properties": {
"provisioningState": "Succeeded",
"resourceGuid": "94a0c0a4-cdba-45b0-b2b1-b6f602d8981e",
"securityRules": [
"type": "Microsoft.Network/networkSecurityGroups",
"location": "eastus",
"properties": {
"provisioningState": "Succeeded",
"resourceGuid": "94a0c0a4-cdba-45b0-b2b1-b6f602d8981e",
"securityRules": [
"type": "Microsoft.Network/networkSecurityGroups",
"location": "eastus",
"properties": {
"provisioningState": "Succeeded",
"resourceGuid": "94a0c0a4-cdba-45b0-b2b1-b6f602d8981e",
"securityRules": [
"type": "Microsoft.Network/networkSecurityGroups",
"location": "eastus",
"properties": {
"provisioningState": "Succeeded",
"resourceGuid": "94a0c0a4-cdba-45b0-b2b1-b6f602d8981e",
"securityRules": [
"type": "Microsoft.Network/networkSecurityGroups",
"location": "eastus",
"properties": {
"provisioningState": "Succeeded",
"resourceGuid": "94a0c0a4-cdba-45b0-b2b1-b6f602d8981e",
"securityRules": [
"type": "Microsoft.Network/networkSecurityGroups",
"location": "eastus",
"properties": {
"provisioningState": "Succeeded",
"resourceGuid": "94a0c0a4-cdba-45b0-b2b1-b6f602d8981e",
"securityRules": [
"type": "Microsoft.Network/networkSecurityGroups",
"location": "eastus",
"properties": {
"provisioningState": "Succeeded",
"resourceGuid": "94a0c0a4-cdba-45b0-b2b1-b6f602d8981e",
"securityRules": [
"type": "Microsoft.Network/networkSecurityGroups",
"apiVersion": "2020-11-01",
"location": "[resourceGroup().location]",
"properties": {
"securityRules": [
{
"type": "Microsoft.Network/networkSecurityGroups",
"location": "eastus",
"properties": {
"provisioningState": "Succeeded",
"resourceGuid": "94a0c0a4-cdba-45b0-b2b1-b6f602d8981e",
"securityRules": [
Parameters
name
required - stringtype
required - stringapiVersion
required - stringlocation
required - stringResource location.
tags
optional - stringResource tags.
properties
requiredsecurityRules
optional arrayproperties
optionaldescription
optional - stringA description for this rule. Restricted to 140 chars.
protocol
required - stringNetwork protocol this rule applies to.
sourcePortRange
optional - stringThe source port or range. Integer or range between 0 and 65535. Asterisk '*' can also be used to match all ports.
destinationPortRange
optional - stringThe destination port or range. Integer or range between 0 and 65535. Asterisk '*' can also be used to match all ports.
sourceAddressPrefix
optional - stringThe 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.
sourceAddressPrefixes
optional - arrayThe CIDR or source IP ranges.
sourceApplicationSecurityGroups
optional arrayid
required - stringResource ID.
destinationAddressPrefix
optional - stringThe 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.
destinationAddressPrefixes
optional - arrayThe destination address prefixes. CIDR or destination IP ranges.
destinationApplicationSecurityGroups
optional arrayid
required - stringResource ID.
sourcePortRanges
optional - arrayThe source port ranges.
destinationPortRanges
optional - arrayThe destination port ranges.
access
required - stringThe network traffic is allowed or denied.
priority
required - integerThe 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.
direction
required - stringThe direction of the rule. The direction specifies if rule will be evaluated on incoming or outgoing traffic.
name
optional - stringThe name of the resource that is unique within a resource group. This name can be used to access the resource.
Frequently asked questions
What is Azure Network Interface Security Group Association?
Azure Network Interface 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 Interface Security Group Association?
For Terraform, the Heliotropo/casopractico2, sa-proj/proj-azure and toninoes/devopsunirp2 source code examples are useful. See the Terraform Example section for further details.
For Azure Resource Manager, the LRuttenCN/cloud-custodian, LRuttenCN/cloud-custodian and LRuttenCN/cloud-custodian source code examples are useful. See the Azure Resource Manager Example section for further details.