github.com/vtorhonen/terraform@v0.9.0-beta2.0.20170307220345-5d894e4ffda7/website/source/docs/providers/aws/r/eip.html.markdown (about) 1 --- 2 layout: "aws" 3 page_title: "AWS: aws_eip" 4 sidebar_current: "docs-aws-resource-eip" 5 description: |- 6 Provides an Elastic IP resource. 7 --- 8 9 # aws\_eip 10 11 Provides an Elastic IP resource. 12 13 ## Example Usage 14 15 Single EIP associated with an instance: 16 17 ``` 18 resource "aws_eip" "lb" { 19 instance = "${aws_instance.web.id}" 20 vpc = true 21 } 22 ``` 23 24 Multiple EIPs associated with a single network interface: 25 26 ``` 27 resource "aws_network_interface" "multi-ip" { 28 subnet_id = "${aws_subnet.main.id}" 29 private_ips = ["10.0.0.10", "10.0.0.11"] 30 } 31 32 resource "aws_eip" "one" { 33 vpc = true 34 network_interface = "${aws_network_interface.multi-ip.id}" 35 associate_with_private_ip = "10.0.0.10" 36 } 37 38 resource "aws_eip" "two" { 39 vpc = true 40 network_interface = "${aws_network_interface.multi-ip.id}" 41 associate_with_private_ip = "10.0.0.11" 42 } 43 ``` 44 45 Attaching an EIP to an Instance with a pre-assigned private ip (VPC Only): 46 47 ``` 48 resource "aws_vpc" "default" { 49 cidr_block = "10.0.0.0/16" 50 enable_dns_hostnames = true 51 } 52 53 resource "aws_internet_gateway" "gw" { 54 vpc_id = "${aws_vpc.default.id}" 55 } 56 57 resource "aws_subnet" "tf_test_subnet" { 58 vpc_id = "${aws_vpc.default.id}" 59 cidr_block = "10.0.0.0/24" 60 map_public_ip_on_launch = true 61 62 depends_on = ["aws_internet_gateway.gw"] 63 } 64 65 resource "aws_instance" "foo" { 66 # us-west-2 67 ami = "ami-5189a661" 68 instance_type = "t2.micro" 69 70 private_ip = "10.0.0.12" 71 subnet_id = "${aws_subnet.tf_test_subnet.id}" 72 } 73 74 resource "aws_eip" "bar" { 75 vpc = true 76 77 instance = "${aws_instance.foo.id}" 78 associate_with_private_ip = "10.0.0.12" 79 } 80 ``` 81 82 ## Argument Reference 83 84 The following arguments are supported: 85 86 * `vpc` - (Optional) Boolean if the EIP is in a VPC or not. 87 * `instance` - (Optional) EC2 instance ID. 88 * `network_interface` - (Optional) Network interface ID to associate with. 89 * `associate_with_private_ip` - (Optional) A user specified primary or secondary private IP address to 90 associate with the Elastic IP address. If no private IP address is specified, 91 the Elastic IP address is associated with the primary private IP address. 92 93 ~> **NOTE:** You can specify either the `instance` ID or the `network_interface` ID, 94 but not both. Including both will **not** return an error from the AWS API, but will 95 have undefined behavior. See the relevant [AssociateAddress API Call][1] for 96 more information. 97 98 ## Attributes Reference 99 100 The following attributes are exported: 101 102 * `id` - Contains the EIP allocation ID. 103 * `private_ip` - Contains the private IP address (if in VPC). 104 * `associate_with_private_ip` - Contains the user specified private IP address 105 (if in VPC). 106 * `public_ip` - Contains the public IP address. 107 * `instance` - Contains the ID of the attached instance. 108 * `network_interface` - Contains the ID of the attached network interface. 109 110 111 ## Import 112 113 EIPs in a VPC can be imported using their Allocation ID, e.g. 114 115 ``` 116 $ terraform import aws_eip.bar eipalloc-00a10e96 117 ``` 118 119 EIPs in EC2 Classic can be imported using their Public IP, e.g. 120 121 ``` 122 $ terraform import aws_eip.bar 52.0.0.0 123 ``` 124 125 [1]: https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_AssociateAddress.html