Resource: aws_eip#
Manages an Elastic IP (EIP). For more information about EIPs, see user documentation.
Example usage#
EIP associated with an instance#
resource "aws_vpc" "example" {
cidr_block = "10.0.0.0/16"
}
resource "aws_subnet" "example" {
vpc_id = aws_vpc.example.id
cidr_block = "10.0.0.0/24"
}
resource "aws_internet_gateway" "example" {
vpc_id = aws_vpc.example.id
}
resource "aws_route" "default_route" {
route_table_id = aws_vpc.example.main_route_table_id
destination_cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.example.id
}
resource "aws_instance" "example" {
ami = "cmi-12345678"
instance_type = "m1.micro"
subnet_id = aws_subnet.example.id
}
resource "aws_eip" "example" {
depends_on = [aws_internet_gateway.example]
instance = aws_instance.example.id
tags = {
Name = "tf-eip"
}
}
EIP associated with a network interface#
~> Note This example uses the same VPC, subnet and internet gateway as in the EIP associated with an instance example.
resource "aws_network_interface" "example" {
subnet_id = aws_subnet.example.id
}
resource "aws_eip" "example" {
depends_on = [aws_internet_gateway.example]
network_interface = aws_network_interface.example.id
tags = {
Name = "tf-eip"
}
}
Allocating an EIP from the BYOIP pool#
resource "aws_eip" "example" {
public_ipv4_pool = "ipv4pool-ec2-012345"
}
Argument reference#
The following arguments are optional:
address- (Optional, Forces new resource, String) The IP address from an EC2 BYOIP pool.instance- (Optional, Editable, String) The ID of the EC2 instance. The EIP is associated with the primary network interface of the instance.- Constraints: Conflicts with the
network_interfaceargument
- Constraints: Conflicts with the
network_interface- (Optional, Editable, String) The ID of the network interface to associate with.- Constraints: Conflicts with the
instanceargument
- Constraints: Conflicts with the
public_ipv4_pool- (Optional, Forces new resource, String) The ID of the EC2 IPv4 address pool.tags- (Optional, Editable, Map of strings) Key-value pairs to assign to the EIP. If thedefault_tagsconfiguration block is used within a provider configuration, the tags with matching keys will overwrite those defined at the provider level.vpc- (Optional, Editable, Boolean, Deprecated) Indicates whether the EIP is for use in a VPC.
~> Note The vpc argument is deprecated.
Its value is ignored: all EIPs are for use in a VPC.
~> Note If both address and public_ipv4_pool 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#
In addition to all arguments above, the following attributes are exported:
allocation_id- (String) The ID of the allocation of the IP address.association_id- (String) The ID of the address association with an instance.- Constraints: Empty unless the EIP is attached to an instance or a network interface
domain- (String) The domain in which the EIP is used.- Valid values:
vpc
- Valid values:
id- (String) The ID of the EIP allocation.private_dns- (String) The private DNS name of the network interface this EIP is attached to.- Constraints: Empty unless the EIP is attached to an instance or a network interface
private_ip- (String) The private IP address.- Constraints: Empty unless the EIP is attached to an instance or a network interface
public_dns- (String) The public DNS name of the network interface this EIP is attached to.- Constraints: Empty unless the EIP is attached to an instance or a network interface
public_ip- (String) The EIP address.tags_all- (Map of strings) Key-value pairs assigned to the EIP, including any tags inherited from thedefault_tagsconfiguration block if used within a provider configuration.
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:
associate_with_private_ip, carrier_ip, customer_owned_ip, customer_owned_ipv4_pool, network_border_group.
Timeouts#
The timeouts block allows you to specify timeouts for certain actions:
read- (Default15 minutes) Used when waiting for a newly created EIP to become visible.update- (Default5 minutes) Used when associating the EIP with an instance or a network interface.delete- (Default3 minutes) Used when releasing the EIP.
Import#
The EIP can be imported using the allocation ID, for example:
$ terraform import aws_eip.example eipalloc-1234567
The EIP can also be imported using its IP address, for example:
$ terraform import aws_eip.example 1.1.1.1