Resource: awsEip
Provides an Elastic IP resource.
\~> Note: EIP may require IGW to exist prior to association. Use dependsOn
to set an explicit dependency on the IGW.
\~> Note: Do not use networkInterface
to associate the EIP to awsLb
or awsNatGateway
resources. Instead use the allocationId
available in those resources to allow AWS to manage the association, otherwise you will see authFailure
errors.
Example Usage
Single EIP associated with an instance
/*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.eip.Eip(this, "lb", {
instance: "${aws_instance.web.id}",
vpc: true,
});
Multiple EIPs associated with a single network interface
/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as aws from "./.gen/providers/aws";
const awsNetworkInterfaceMultiIp = new aws.networkInterface.NetworkInterface(
this,
"multi-ip",
{
privateIps: ["10.0.0.10", "10.0.0.11"],
subnetId: "${aws_subnet.main.id}",
}
);
new aws.eip.Eip(this, "one", {
associateWithPrivateIp: "10.0.0.10",
networkInterface: awsNetworkInterfaceMultiIp.id,
vpc: true,
});
new aws.eip.Eip(this, "two", {
associateWithPrivateIp: "10.0.0.11",
networkInterface: awsNetworkInterfaceMultiIp.id,
vpc: true,
});
Attaching an EIP to an Instance with a pre-assigned private ip (VPC Only)
/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as aws from "./.gen/providers/aws";
const awsVpcDefault = new aws.vpc.Vpc(this, "default", {
cidrBlock: "10.0.0.0/16",
enableDnsHostnames: true,
});
const awsInternetGatewayGw = new aws.internetGateway.InternetGateway(
this,
"gw",
{
vpcId: awsVpcDefault.id,
}
);
const awsSubnetTfTestSubnet = new aws.subnet.Subnet(this, "tf_test_subnet", {
cidrBlock: "10.0.0.0/24",
depends_on: [`\${${awsInternetGatewayGw.fqn}}`],
mapPublicIpOnLaunch: true,
vpcId: awsVpcDefault.id,
});
const awsInstanceFoo = new aws.instance.Instance(this, "foo", {
ami: "ami-5189a661",
instanceType: "t2.micro",
privateIp: "10.0.0.12",
subnetId: awsSubnetTfTestSubnet.id,
});
new aws.eip.Eip(this, "bar", {
associateWithPrivateIp: "10.0.0.12",
depends_on: [`\${${awsInternetGatewayGw.fqn}}`],
instance: awsInstanceFoo.id,
vpc: true,
});
Allocating EIP from the BYOIP pool
/*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.eip.Eip(this, "byoip-ip", {
publicIpv4Pool: "ipv4pool-ec2-012345",
vpc: true,
});
Argument Reference
The following arguments are supported:
address
- (Optional) IP address from an EC2 BYOIP pool. This option is only available for VPC EIPs.associateWithPrivateIp
- (Optional) User-specified primary or secondary private IP address to associate with the Elastic IP address. If no private IP address is specified, the Elastic IP address is associated with the primary private IP address.customerOwnedIpv4Pool
- (Optional) ID of a customer-owned address pool. For more on customer owned IP addressed check out Customer-owned IP addresses guide.instance
- (Optional) EC2 instance ID.networkBorderGroup
- (Optional) Location from which the IP address is advertised. Use this parameter to limit the address to this location.networkInterface
- (Optional) Network interface ID to associate with.publicIpv4Pool
- (Optional) EC2 IPv4 address pool identifier oramazon
. This option is only available for VPC EIPs.tags
- (Optional) Map of tags to assign to the resource. Tags can only be applied to EIPs in a VPC. If configured with a providerdefaultTags
configuration block present, tags with matching keys will overwrite those defined at the provider-level.vpc
- (Optional) Boolean if the EIP is in a VPC or not. Defaults totrue
unless the region supports EC2-Classic.
\~> NOTE: You can specify either the instance
ID or the networkInterface
ID, but not both. Including both will not return an error from the AWS API, but will have undefined behavior. See the relevant AssociateAddress API Call for more information.
\~> NOTE: Specifying both publicIpv4Pool
and address
won't cause an error but address
will be used in the case both options are defined as the api only requires one or the other.
Attributes Reference
In addition to all arguments above, the following attributes are exported:
allocationId
- ID that AWS assigns to represent the allocation of the Elastic IP address for use with instances in a VPC.associationId
- ID representing the association of the address with an instance in a VPC.carrierIp
- Carrier IP address.customerOwnedIp
- Customer owned IP.domain
- Indicates if this EIP is for use in VPC (vpc
) or EC2-Classic (standard
).id
- Contains the EIP allocation ID.privateDns
- The Private DNS associated with the Elastic IP address (if in VPC).privateIp
- Contains the private IP address (if in VPC).publicDns
- Public DNS associated with the Elastic IP address.publicIp
- Contains the public IP address.tagsAll
- A map of tags assigned to the resource, including those inherited from the providerdefaultTags
configuration block.
\~> Note: The resource computes the publicDns
and privateDns
attributes according to the VPC DNS Guide as they are not available with the EC2 API.
Timeouts
read
- (Default15M
)update
- (Default5M
)delete
- (Default3M
)
Import
EIPs in a VPC can be imported using their Allocation ID, e.g.,
EIPs in EC2-Classic can be imported using their Public IP, e.g.,