Skip to content

azurermNetworkInterfaceSecurityGroupAssociation

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

Example Usage

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as azurerm from "./.gen/providers/azurerm";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: azurerm.
For a more precise conversion please use the --provider flag in convert.*/
const azurermResourceGroupExample = new azurerm.resourceGroup.ResourceGroup(
  this,
  "example",
  {
    location: "West Europe",
    name: "example-resources",
  }
);
const azurermVirtualNetworkExample = new azurerm.virtualNetwork.VirtualNetwork(
  this,
  "example_1",
  {
    address_space: ["10.0.0.0/16"],
    location: azurermResourceGroupExample.location,
    name: "example-network",
    resource_group_name: azurermResourceGroupExample.name,
  }
);
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
azurermVirtualNetworkExample.overrideLogicalId("example");
const azurermNetworkSecurityGroupExample =
  new azurerm.networkSecurityGroup.NetworkSecurityGroup(this, "example_2", {
    location: azurermResourceGroupExample.location,
    name: "example-nsg",
    resource_group_name: azurermResourceGroupExample.name,
  });
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
azurermNetworkSecurityGroupExample.overrideLogicalId("example");
const azurermSubnetExample = new azurerm.subnet.Subnet(this, "example_3", {
  address_prefixes: ["10.0.2.0/24"],
  name: "internal",
  resource_group_name: azurermResourceGroupExample.name,
  virtual_network_name: azurermVirtualNetworkExample.name,
});
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
azurermSubnetExample.overrideLogicalId("example");
const azurermNetworkInterfaceExample =
  new azurerm.networkInterface.NetworkInterface(this, "example_4", {
    ip_configuration: [
      {
        name: "testconfiguration1",
        private_ip_address_allocation: "Dynamic",
        subnet_id: azurermSubnetExample.id,
      },
    ],
    location: azurermResourceGroupExample.location,
    name: "example-nic",
    resource_group_name: azurermResourceGroupExample.name,
  });
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
azurermNetworkInterfaceExample.overrideLogicalId("example");
const azurermNetworkInterfaceSecurityGroupAssociationExample =
  new azurerm.networkInterfaceSecurityGroupAssociation.NetworkInterfaceSecurityGroupAssociation(
    this,
    "example_5",
    {
      network_interface_id: azurermNetworkInterfaceExample.id,
      network_security_group_id: azurermNetworkSecurityGroupExample.id,
    }
  );
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
azurermNetworkInterfaceSecurityGroupAssociationExample.overrideLogicalId(
  "example"
);

Argument Reference

The following arguments are supported:

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

  • networkSecurityGroupId - (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 resourceId, 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"

-> NOTE: This ID is specific to Terraform - and is of the format {networkInterfaceId}|{networkSecurityGroupId}.