Resource: aws_eip#
Manages an Elastic IP. For more information about EIPs, see user documentation.
Example Usage#
Single EIP associated with an instance#
resource "aws_eip" "example" {
instance = "i-12345678"
vpc = true
}
Attaching an EIP to an instance with a pre-assigned private IP#
resource "aws_vpc" "default" {
cidr_block = "10.0.0.0/16"
}
resource "aws_subnet" "tf_test_subnet" {
vpc_id = aws_vpc.default.id
cidr_block = "10.0.0.0/24"
}
resource "aws_instance" "foo" {
ami = "cmi-12345678" # add image id, change instance type if needed
instance_type = "m1.micro"
private_ip = "10.0.0.12"
subnet_id = aws_subnet.tf_test_subnet.id
}
resource "aws_eip" "bar" {
vpc = true
associate_with_private_ip = "10.0.0.12"
}
Allocating EIP from the BYOIP pool#
resource "aws_eip" "byoip-ip" {
vpc = true
public_ipv4_pool = "ipv4pool-ec2-012345"
}
Argument Reference#
The following arguments are supported:
address- (Optional) IP address from an EC2 BYOIP pool. Constraints: This option is only available for VPC EIPsassociate_with_private_ip- (Optional) User-specified primary or secondary private IP address to associate with the elastic IP address.- Constraints: If no private IP address is specified, the elastic IP address is associated with the primary private IP address
instance- (Optional) The ID of the EC2 instance.network_interface- (Optional) The ID of the network interface to associate with.public_ipv4_pool- (Optional) The ID of the EC2 IPv4 address pool.- Constraints: This option is only available for VPC EIPs
tags- (Optional) Map of tags to assign to the EIP. If a providerdefault_tagsconfiguration block is used, tags with matching keys will overwrite those defined at the provider level.- Constraints: Tags can only be applied to EIPs in a VPC
vpc- (Optional) Boolean if the EIP is in a VPC or not.
~> Note You can specify either the ID of instance or the ID of network_interface, but not both.
~> Note If both public_ipv4_pool and address are specified, address will be used in the case both options are defined as API only requires one or the other.
Attribute Reference#
Supported attributes#
~> Note The data source computes the public_dns and private_dns attributes according to the AWS VPC DNS Guide as they are not available with the EC2 API.
In addition to all arguments above, the following attributes are exported:
allocation_id- The ID representing the allocation of the IP address.association_id- The ID representing the association of the allocation of the IP-address with an instance or a private IP address.domain- Indicates if this EIP is for use in VPC (vpc).id- The ID of the EIP allocation.private_ip- Contains the private IP address. Can be""ifassociate_with_private_ipis specified.public_ip- Contains the public IP address.tags_all- Map of tags assigned to the EIP, including those inherited from the providerdefault_tagsconfiguration block.
Unsupported attributes#
~> Note These attributes may be present in the terraform.tfstate file, but they have preset values and cannot be specified in configuration files.
The following attributes are not currently supported:
carrier_ip, customer_owned_ip, customer_owned_ipv4_pool, network_border_group, private_dns, public_dns.
Timeouts#
The timeouts block allows you to specify timeouts for certain actions:
read- (Default15 minutes) How long to wait querying for information about EIPs.update- (Default5 minutes) How long to wait for an EIP to be updated.delete- (Default3 minutes) How long to wait for an EIP to be deleted.
Import#
EIPs in a VPC can be imported using their allocation ID, e.g.,
$ terraform import aws_eip.bar eipalloc-1234567
EIPs can be imported using their public IP, e.g.,
$ terraform import aws_eip.bar 1.1.1.1