» azurerm_network_interface_security_group_association

Manages the association between a Network Interface and a Network Security Group.

» Example Usage

resource "azurerm_resource_group" "example" {
  name     = "example-resources"
  location = "West Europe"
}

resource "azurerm_virtual_network" "example" {
  name                = "example-network"
  address_space       = ["10.0.0.0/16"]
  location            = azurerm_resource_group.example.location
  resource_group_name = azurerm_resource_group.example.name
}

resource "azurerm_subnet" "example" {
  name                 = "internal"
  resource_group_name  = azurerm_resource_group.example.name
  virtual_network_name = azurerm_virtual_network.example.name
  address_prefix       = "10.0.2.0/24"
}

resource "azurerm_network_security_group" "example" {
  name                = "example-nsg"
  location            = azurerm_resource_group.example.location
  resource_group_name = azurerm_resource_group.example.name
}

resource "azurerm_network_interface" "example" {
  name                = "example-nic"
  location            = azurerm_resource_group.example.location
  resource_group_name = azurerm_resource_group.example.name

  ip_configuration {
    name                          = "testconfiguration1"
    subnet_id                     = azurerm_subnet.example.id
    private_ip_address_allocation = "Dynamic"
  }
}

resource "azurerm_network_interface_security_group_association" "example" {
  network_interface_id      = azurerm_network_interface.example.id
  network_security_group_id = azurerm_network_security_group.example.id
}

» Argument Reference

The following arguments are supported:

  • network_interface_id - (Required) The ID of the Network Interface. Changing this forces a new resource to be created.

  • network_security_group_id - (Required) The ID of the Network Security Group which should be attached to the Network Interface. Changing this forces a new resource to be created.

» Attributes Reference

The following attributes are exported:

  • id - The (Terraform specific) ID of the Association between the Network Interface and the Network Interface.

» Timeouts

The timeouts block allows you to specify timeouts for certain actions:

  • create - (Defaults to 30 minutes) Used when creating the association between the Network Interface and the Network Security Group.
  • update - (Defaults to 30 minutes) Used when updating the association between the Network Interface and the Network Security Group.
  • read - (Defaults to 5 minutes) Used when retrieving the association between the Network Interface and the Network Security Group.
  • delete - (Defaults to 30 minutes) Used when deleting the association between the Network Interface and the Network Security Group.

» Import

Associations between Network Interfaces and Network Security Group can be imported using the resource id, e.g.

terraform import azurerm_network_interface_security_group_association.association1 "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mygroup1/providers/microsoft.network/networkInterfaces/example|/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.Network/networkSecurityGroups/group1"