2014-07-23 22:08:07 +02:00
|
|
|
---
|
|
|
|
layout: "aws"
|
|
|
|
page_title: "AWS: aws_eip"
|
|
|
|
sidebar_current: "docs-aws-resource-eip"
|
2014-10-22 05:21:56 +02:00
|
|
|
description: |-
|
|
|
|
Provides an Elastic IP resource.
|
2014-07-23 22:08:07 +02:00
|
|
|
---
|
|
|
|
|
|
|
|
# aws\_eip
|
|
|
|
|
|
|
|
Provides an Elastic IP resource.
|
|
|
|
|
|
|
|
## Example Usage
|
|
|
|
|
2016-04-07 19:15:00 +02:00
|
|
|
Single EIP associated with an instance:
|
|
|
|
|
2014-07-23 22:08:07 +02:00
|
|
|
```
|
|
|
|
resource "aws_eip" "lb" {
|
2016-04-07 19:15:00 +02:00
|
|
|
instance = "${aws_instance.web.id}"
|
|
|
|
vpc = true
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2016-09-12 08:04:04 +02:00
|
|
|
Multiple EIPs associated with a single network interface:
|
2016-04-07 19:15:00 +02:00
|
|
|
|
|
|
|
```
|
|
|
|
resource "aws_network_interface" "multi-ip" {
|
2016-05-06 22:38:39 +02:00
|
|
|
subnet_id = "${aws_subnet.main.id}"
|
|
|
|
private_ips = ["10.0.0.10", "10.0.0.11"]
|
2016-04-07 19:15:00 +02:00
|
|
|
}
|
2016-05-06 22:38:39 +02:00
|
|
|
|
2016-04-07 19:15:00 +02:00
|
|
|
resource "aws_eip" "one" {
|
2016-05-06 22:38:39 +02:00
|
|
|
vpc = true
|
|
|
|
network_interface = "${aws_network_interface.multi-ip.id}"
|
|
|
|
associate_with_private_ip = "10.0.0.10"
|
2016-04-07 19:15:00 +02:00
|
|
|
}
|
2016-05-06 22:38:39 +02:00
|
|
|
|
2016-04-07 19:15:00 +02:00
|
|
|
resource "aws_eip" "two" {
|
2016-05-06 22:38:39 +02:00
|
|
|
vpc = true
|
|
|
|
network_interface = "${aws_network_interface.multi-ip.id}"
|
|
|
|
associate_with_private_ip = "10.0.0.11"
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
Attaching an EIP to an Instance with a pre-assigned private ip (VPC Only):
|
|
|
|
|
|
|
|
```
|
|
|
|
resource "aws_vpc" "default" {
|
|
|
|
cidr_block = "10.0.0.0/16"
|
|
|
|
enable_dns_hostnames = true
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_internet_gateway" "gw" {
|
|
|
|
vpc_id = "${aws_vpc.default.id}"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_subnet" "tf_test_subnet" {
|
|
|
|
vpc_id = "${aws_vpc.default.id}"
|
|
|
|
cidr_block = "10.0.0.0/24"
|
|
|
|
map_public_ip_on_launch = true
|
|
|
|
|
|
|
|
depends_on = ["aws_internet_gateway.gw"]
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_instance" "foo" {
|
|
|
|
# us-west-2
|
|
|
|
ami = "ami-5189a661"
|
|
|
|
instance_type = "t2.micro"
|
|
|
|
|
|
|
|
private_ip = "10.0.0.12"
|
|
|
|
subnet_id = "${aws_subnet.tf_test_subnet.id}"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_eip" "bar" {
|
|
|
|
vpc = true
|
|
|
|
|
|
|
|
instance = "${aws_instance.foo.id}"
|
|
|
|
associate_with_private_ip = "10.0.0.12"
|
2014-07-23 22:08:07 +02:00
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
## Argument Reference
|
|
|
|
|
|
|
|
The following arguments are supported:
|
|
|
|
|
2014-07-30 00:12:00 +02:00
|
|
|
* `vpc` - (Optional) Boolean if the EIP is in a VPC or not.
|
2014-07-23 22:08:07 +02:00
|
|
|
* `instance` - (Optional) EC2 instance ID.
|
2015-05-05 22:25:45 +02:00
|
|
|
* `network_interface` - (Optional) Network interface ID to associate with.
|
2016-05-06 22:38:39 +02:00
|
|
|
* `associate_with_private_ip` - (Optional) A user specified primary or secondary private IP address to
|
2016-04-07 19:15:00 +02:00
|
|
|
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.
|
2014-07-23 22:08:07 +02:00
|
|
|
|
2016-01-14 21:55:39 +01:00
|
|
|
~> **NOTE:** You can specify either the `instance` ID or the `network_interface` ID,
|
2015-10-08 16:20:51 +02:00
|
|
|
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][1] for
|
|
|
|
more information.
|
|
|
|
|
2014-07-23 22:08:07 +02:00
|
|
|
## Attributes Reference
|
|
|
|
|
|
|
|
The following attributes are exported:
|
|
|
|
|
2015-12-30 18:50:22 +01:00
|
|
|
* `id` - Contains the EIP allocation ID.
|
2014-07-29 08:51:24 +02:00
|
|
|
* `private_ip` - Contains the private IP address (if in VPC).
|
2016-05-06 22:38:39 +02:00
|
|
|
* `associate_with_private_ip` - Contains the user specified private IP address
|
|
|
|
(if in VPC).
|
2014-07-23 22:08:07 +02:00
|
|
|
* `public_ip` - Contains the public IP address.
|
2014-07-29 08:51:24 +02:00
|
|
|
* `instance` - Contains the ID of the attached instance.
|
2015-05-05 22:25:45 +02:00
|
|
|
* `network_interface` - Contains the ID of the attached network interface.
|
2014-07-23 22:08:07 +02:00
|
|
|
|
2016-01-14 21:55:39 +01:00
|
|
|
[1]: https://docs.aws.amazon.com/fr_fr/AWSEC2/latest/APIReference/API_AssociateAddress.html
|