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

security.tf#L32
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

}

securitygroupassociation.tf#L1
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" {
security.tf#L29
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

}

security_group.tf#L201
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
network.tf#L222
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_group.tf#L72
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
}


security.tf#L24
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
security.tf#L26
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
security.tf#L26
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

}

security.tf#L26
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

Review your Terraform file for Azure best practices

Shisho Cloud, our free checker to make sure your Terraform configuration follows best practices, is available (beta).

Parameters

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.

risk-label

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.

risk-label

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.

risk-label

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.

Review your Azure Network settings

In addition to the above, there are other security points you should be aware of making sure that your .tf files are protected in Shisho Cloud.

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

NetworkSecurityGroupTest.test_open_ports.json#L41
                                "type": "Microsoft.Network/networkSecurityGroups",
                                "location": "eastus",
                                "properties": {
                                    "provisioningState": "Succeeded",
                                    "resourceGuid": "94a0c0a4-cdba-45b0-b2b1-b6f602d8981e",
                                    "securityRules": [
NetworkSecurityGroupTest.test_egress_policy_protocols.json#L41
                                "type": "Microsoft.Network/networkSecurityGroups",
                                "location": "eastus",
                                "properties": {
                                    "provisioningState": "Succeeded",
                                    "resourceGuid": "94a0c0a4-cdba-45b0-b2b1-b6f602d8981e",
                                    "securityRules": [
NetworkSecurityGroupTest.test_find_by_name.json#L41
                                "type": "Microsoft.Network/networkSecurityGroups",
                                "location": "eastus",
                                "properties": {
                                    "provisioningState": "Succeeded",
                                    "resourceGuid": "94a0c0a4-cdba-45b0-b2b1-b6f602d8981e",
                                    "securityRules": [
NetworkSecurityGroupTest.test_allow_ports_range_any.json#L41
                                "type": "Microsoft.Network/networkSecurityGroups",
                                "location": "eastus",
                                "properties": {
                                    "provisioningState": "Succeeded",
                                    "resourceGuid": "94a0c0a4-cdba-45b0-b2b1-b6f602d8981e",
                                    "securityRules": [
NetworkSecurityGroupTest.test_deny_port.json#L41
                                "type": "Microsoft.Network/networkSecurityGroups",
                                "location": "eastus",
                                "properties": {
                                    "provisioningState": "Succeeded",
                                    "resourceGuid": "94a0c0a4-cdba-45b0-b2b1-b6f602d8981e",
                                    "securityRules": [
NetworkSecurityGroupTest.test_allow_single_port.json#L41
                                "type": "Microsoft.Network/networkSecurityGroups",
                                "location": "eastus",
                                "properties": {
                                    "provisioningState": "Succeeded",
                                    "resourceGuid": "94a0c0a4-cdba-45b0-b2b1-b6f602d8981e",
                                    "securityRules": [
NetworkSecurityGroupTest.test_allow_multiple_ports.json#L41
                                "type": "Microsoft.Network/networkSecurityGroups",
                                "location": "eastus",
                                "properties": {
                                    "provisioningState": "Succeeded",
                                    "resourceGuid": "94a0c0a4-cdba-45b0-b2b1-b6f602d8981e",
                                    "securityRules": [
NetworkSecurityGroupTest.test_open_ports.json#L41
                                "type": "Microsoft.Network/networkSecurityGroups",
                                "location": "eastus",
                                "properties": {
                                    "provisioningState": "Succeeded",
                                    "resourceGuid": "94a0c0a4-cdba-45b0-b2b1-b6f602d8981e",
                                    "securityRules": [
network.template.json#L27
            "type": "Microsoft.Network/networkSecurityGroups",
            "apiVersion": "2020-11-01",
            "location": "[resourceGroup().location]",
            "properties": {
                "securityRules": [
                    {
NetworkSecurityGroupTest.test_egress_policy_protocols.json#L41
                                "type": "Microsoft.Network/networkSecurityGroups",
                                "location": "eastus",
                                "properties": {
                                    "provisioningState": "Succeeded",
                                    "resourceGuid": "94a0c0a4-cdba-45b0-b2b1-b6f602d8981e",
                                    "securityRules": [

Parameters

  • name required - string
  • type required - string
  • apiVersion required - string
  • location required - string

    Resource location.

  • tags optional - string

    Resource tags.

  • properties required
      • securityRules optional array
          • properties optional
              • description optional - string

                A description for this rule. Restricted to 140 chars.

              • protocol required - string

                Network protocol this rule applies to.

              • sourcePortRange optional - string

                The source port or range. Integer or range between 0 and 65535. Asterisk '*' can also be used to match all ports.

              • destinationPortRange optional - string

                The destination port or range. Integer or range between 0 and 65535. Asterisk '*' can also be used to match all ports.

              • sourceAddressPrefix optional - string

                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.

              • sourceAddressPrefixes optional - array

                The CIDR or source IP ranges.

              • sourceApplicationSecurityGroups optional array
                  • id required - string

                    Resource ID.

              • destinationAddressPrefix optional - string

                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.

              • destinationAddressPrefixes optional - array

                The destination address prefixes. CIDR or destination IP ranges.

              • destinationApplicationSecurityGroups optional array
                  • id required - string

                    Resource ID.

              • sourcePortRanges optional - array

                The source port ranges.

              • destinationPortRanges optional - array

                The destination port ranges.

              • access required - string

                The network traffic is allowed or denied.

              • priority required - integer

                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.

              • direction required - string

                The direction of the rule. The direction specifies if rule will be evaluated on incoming or outgoing traffic.

          • name optional - string

            The 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.