Resource: awsNetworkInterface
Provides an Elastic network interface (ENI) resource.
Example Usage
/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as aws from "./.gen/providers/aws";
new aws.networkInterface.NetworkInterface(this, "test", {
attachment: [
{
deviceIndex: 1,
instance: "${aws_instance.test.id}",
},
],
privateIps: ["10.0.0.50"],
securityGroups: ["${aws_security_group.web.id}"],
subnetId: "${aws_subnet.public_a.id}",
});
Example of Managing Multiple IPs on a Network Interface
By default, private IPs are managed through the privateIps
and privateIpsCount
arguments which manage IPs as a set of IPs that are configured without regard to order. For a new network interface, the same primary IP address is consistently selected from a given set of addresses, regardless of the order provided. However, modifications of the set of addresses of an existing interface will not alter the current primary IP address unless it has been removed from the set.
In order to manage the private IPs as a sequentially ordered list, configure privateIpListEnabled
to true
and use privateIpList
to manage the IPs. This will disable the privateIps
and privateIpsCount
settings, which must be removed from the config file but are still exported. Note that changing the first address of privateIpList
, which is the primary, always requires a new interface.
If you are managing a specific set or list of IPs, instead of just using privateIpsCount
, this is a potential workflow for also leveraging privateIpsCount
to have AWS automatically assign additional IP addresses:
- Comment out
privateIps
,privateIpList
,privateIpListEnabled
in your configuration - Set the desired
privateIpsCount
(count of the number of secondaries, the primary is not included) - Apply to assign the extra IPs
- Remove
privateIpsCount
and restore your settings from the first step - Add the new IPs to your current settings
- Apply again to update the stored state
This process can also be used to remove IP addresses in addition to the option of manually removing them. Adding IP addresses in a manually is more difficult because it requires knowledge of which addresses are available.
Argument Reference
The following arguments are required:
subnetId
- (Required) Subnet ID to create the ENI in.
The following arguments are optional:
attachment
- (Optional) Configuration block to define the attachment of the ENI. See Attachment below for more details!description
- (Optional) Description for the network interface.interfaceType
- (Optional) Type of network interface to create. Set toefa
for Elastic Fabric Adapter. ChanginginterfaceType
will cause the resource to be destroyed and re-created.ipv4PrefixCount
- (Optional) Number of IPv4 prefixes that AWS automatically assigns to the network interface.ipv4Prefixes
- (Optional) One or more IPv4 prefixes assigned to the network interface.ipv6AddressCount
- (Optional) Number of IPv6 addresses to assign to a network interface. You can't use this option if specifying specificipv6Addresses
. If your subnet has the AssignIpv6AddressOnCreation attribute set totrue
, you can specify0
to override this setting.ipv6AddressListEnabled
- (Optional) Whetheripv6AddressList
is allowed and controls the IPs to assign to the ENI andipv6Addresses
andipv6AddressCount
become read-only. Default false.ipv6AddressList
- (Optional) List of private IPs to assign to the ENI in sequential order.ipv6Addresses
- (Optional) One or more specific IPv6 addresses from the IPv6 CIDR block range of your subnet. Addresses are assigned without regard to order. You can't use this option if you're specifyingipv6AddressCount
.ipv6PrefixCount
- (Optional) Number of IPv6 prefixes that AWS automatically assigns to the network interface.ipv6Prefixes
- (Optional) One or more IPv6 prefixes assigned to the network interface.privateIpList
- (Optional) List of private IPs to assign to the ENI in sequential order. Requires settingprivateIpListEnabled
totrue
.privateIpListEnabled
- (Optional) WhetherprivateIpList
is allowed and controls the IPs to assign to the ENI andprivateIps
andprivateIpsCount
become read-only. Default false.privateIps
- (Optional) List of private IPs to assign to the ENI without regard to order.privateIpsCount
- (Optional) Number of secondary private IPs to assign to the ENI. The total number of private IPs will be 1 +privateIpsCount
, as a primary private IP will be assiged to an ENI by default.securityGroups
- (Optional) List of security group IDs to assign to the ENI.sourceDestCheck
- (Optional) Whether to enable source destination checking for the ENI. Default true.tags
- (Optional) Map of tags to assign to the resource. If configured with a providerdefaultTags
configuration block present, tags with matching keys will overwrite those defined at the provider-level.
Attachment
The attachment
block supports the following:
instance
- (Required) ID of the instance to attach to.deviceIndex
- (Required) Integer to define the devices index.
Attributes Reference
In addition to all arguments above, the following attributes are exported:
arn
- ARN of the network interface.id
- ID of the network interface.macAddress
- MAC address of the network interface.ownerId
- AWS account ID of the owner of the network interface.privateDnsName
- Private DNS name of the network interface (IPv4).tagsAll
- Map of tags assigned to the resource, including those inherited from the providerdefaultTags
configuration block.
Import
Network Interfaces can be imported using the id
, e.g.,