provider/aws: Fix issue changing EIP Association (#6521)
provider/aws: Update EIP to use new associate_with_private_ip instead of private_ip
This commit is contained in:
parent
f0cf6564ad
commit
99e0aec769
|
@ -61,9 +61,13 @@ func resourceAwsEip() *schema.Resource {
|
||||||
|
|
||||||
"private_ip": &schema.Schema{
|
"private_ip": &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Optional: true,
|
|
||||||
Computed: true,
|
Computed: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
"associate_with_private_ip": &schema.Schema{
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Optional: true,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -190,7 +194,7 @@ func resourceAwsEipUpdate(d *schema.ResourceData, meta interface{}) error {
|
||||||
// more unique ID conditionals
|
// more unique ID conditionals
|
||||||
if domain == "vpc" {
|
if domain == "vpc" {
|
||||||
var privateIpAddress *string
|
var privateIpAddress *string
|
||||||
if v := d.Get("private_ip").(string); v != "" {
|
if v := d.Get("associate_with_private_ip").(string); v != "" {
|
||||||
privateIpAddress = aws.String(v)
|
privateIpAddress = aws.String(v)
|
||||||
}
|
}
|
||||||
assocOpts = &ec2.AssociateAddressInput{
|
assocOpts = &ec2.AssociateAddressInput{
|
||||||
|
|
|
@ -105,6 +105,38 @@ func TestAccAWSEIP_twoEIPsOneNetworkInterface(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This test is an expansion of TestAccAWSEIP_instance, by testing the
|
||||||
|
// associated Private EIPs of two instances
|
||||||
|
func TestAccAWSEIP_associated_user_private_ip(t *testing.T) {
|
||||||
|
var one ec2.Address
|
||||||
|
|
||||||
|
resource.Test(t, resource.TestCase{
|
||||||
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
IDRefreshName: "aws_eip.bar",
|
||||||
|
Providers: testAccProviders,
|
||||||
|
CheckDestroy: testAccCheckAWSEIPDestroy,
|
||||||
|
Steps: []resource.TestStep{
|
||||||
|
resource.TestStep{
|
||||||
|
Config: testAccAWSEIPInstanceConfig_associated,
|
||||||
|
Check: resource.ComposeTestCheckFunc(
|
||||||
|
testAccCheckAWSEIPExists("aws_eip.bar", &one),
|
||||||
|
testAccCheckAWSEIPAttributes(&one),
|
||||||
|
testAccCheckAWSEIPAssociated(&one),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
|
||||||
|
resource.TestStep{
|
||||||
|
Config: testAccAWSEIPInstanceConfig_associated_switch,
|
||||||
|
Check: resource.ComposeTestCheckFunc(
|
||||||
|
testAccCheckAWSEIPExists("aws_eip.bar", &one),
|
||||||
|
testAccCheckAWSEIPAttributes(&one),
|
||||||
|
testAccCheckAWSEIPAssociated(&one),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func testAccCheckAWSEIPDestroy(s *terraform.State) error {
|
func testAccCheckAWSEIPDestroy(s *terraform.State) error {
|
||||||
conn := testAccProvider.Meta().(*AWSClient).ec2conn
|
conn := testAccProvider.Meta().(*AWSClient).ec2conn
|
||||||
|
|
||||||
|
@ -248,6 +280,149 @@ resource "aws_eip" "bar" {
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
|
const testAccAWSEIPInstanceConfig_associated = `
|
||||||
|
resource "aws_vpc" "default" {
|
||||||
|
cidr_block = "10.0.0.0/16"
|
||||||
|
enable_dns_hostnames = true
|
||||||
|
|
||||||
|
tags {
|
||||||
|
Name = "default"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "aws_internet_gateway" "gw" {
|
||||||
|
vpc_id = "${aws_vpc.default.id}"
|
||||||
|
|
||||||
|
tags {
|
||||||
|
Name = "main"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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"]
|
||||||
|
|
||||||
|
tags {
|
||||||
|
Name = "tf_test_subnet"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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}"
|
||||||
|
|
||||||
|
tags {
|
||||||
|
Name = "foo instance"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "aws_instance" "bar" {
|
||||||
|
# us-west-2
|
||||||
|
|
||||||
|
ami = "ami-5189a661"
|
||||||
|
|
||||||
|
instance_type = "t2.micro"
|
||||||
|
|
||||||
|
private_ip = "10.0.0.19"
|
||||||
|
subnet_id = "${aws_subnet.tf_test_subnet.id}"
|
||||||
|
|
||||||
|
tags {
|
||||||
|
Name = "bar instance"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "aws_eip" "bar" {
|
||||||
|
vpc = true
|
||||||
|
|
||||||
|
instance = "${aws_instance.bar.id}"
|
||||||
|
associate_with_private_ip = "10.0.0.19"
|
||||||
|
}
|
||||||
|
`
|
||||||
|
const testAccAWSEIPInstanceConfig_associated_switch = `
|
||||||
|
resource "aws_vpc" "default" {
|
||||||
|
cidr_block = "10.0.0.0/16"
|
||||||
|
enable_dns_hostnames = true
|
||||||
|
|
||||||
|
tags {
|
||||||
|
Name = "default"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "aws_internet_gateway" "gw" {
|
||||||
|
vpc_id = "${aws_vpc.default.id}"
|
||||||
|
|
||||||
|
tags {
|
||||||
|
Name = "main"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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"]
|
||||||
|
|
||||||
|
tags {
|
||||||
|
Name = "tf_test_subnet"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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}"
|
||||||
|
|
||||||
|
tags {
|
||||||
|
Name = "foo instance"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "aws_instance" "bar" {
|
||||||
|
# us-west-2
|
||||||
|
|
||||||
|
ami = "ami-5189a661"
|
||||||
|
|
||||||
|
instance_type = "t2.micro"
|
||||||
|
|
||||||
|
private_ip = "10.0.0.19"
|
||||||
|
subnet_id = "${aws_subnet.tf_test_subnet.id}"
|
||||||
|
|
||||||
|
tags {
|
||||||
|
Name = "bar instance"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "aws_eip" "bar" {
|
||||||
|
vpc = true
|
||||||
|
|
||||||
|
instance = "${aws_instance.foo.id}"
|
||||||
|
associate_with_private_ip = "10.0.0.12"
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|
||||||
|
const testAccAWSEIPInstanceConfig_associated_update = `
|
||||||
|
resource "aws_instance" "bar" {
|
||||||
|
# us-west-2
|
||||||
|
ami = "ami-4fccb37f"
|
||||||
|
instance_type = "m1.small"
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "aws_eip" "bar" {
|
||||||
|
instance = "${aws_instance.bar.id}"
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|
||||||
const testAccAWSEIPNetworkInterfaceConfig = `
|
const testAccAWSEIPNetworkInterfaceConfig = `
|
||||||
resource "aws_vpc" "bar" {
|
resource "aws_vpc" "bar" {
|
||||||
cidr_block = "10.0.0.0/24"
|
cidr_block = "10.0.0.0/24"
|
||||||
|
@ -275,27 +450,32 @@ const testAccAWSEIPMultiNetworkInterfaceConfig = `
|
||||||
resource "aws_vpc" "bar" {
|
resource "aws_vpc" "bar" {
|
||||||
cidr_block = "10.0.0.0/24"
|
cidr_block = "10.0.0.0/24"
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "aws_internet_gateway" "bar" {
|
resource "aws_internet_gateway" "bar" {
|
||||||
vpc_id = "${aws_vpc.bar.id}"
|
vpc_id = "${aws_vpc.bar.id}"
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "aws_subnet" "bar" {
|
resource "aws_subnet" "bar" {
|
||||||
vpc_id = "${aws_vpc.bar.id}"
|
vpc_id = "${aws_vpc.bar.id}"
|
||||||
availability_zone = "us-west-2a"
|
availability_zone = "us-west-2a"
|
||||||
cidr_block = "10.0.0.0/24"
|
cidr_block = "10.0.0.0/24"
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "aws_network_interface" "bar" {
|
resource "aws_network_interface" "bar" {
|
||||||
subnet_id = "${aws_subnet.bar.id}"
|
subnet_id = "${aws_subnet.bar.id}"
|
||||||
private_ips = ["10.0.0.10", "10.0.0.11"]
|
private_ips = ["10.0.0.10", "10.0.0.11"]
|
||||||
security_groups = [ "${aws_vpc.bar.default_security_group_id}" ]
|
security_groups = ["${aws_vpc.bar.default_security_group_id}"]
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "aws_eip" "one" {
|
resource "aws_eip" "one" {
|
||||||
vpc = "true"
|
vpc = "true"
|
||||||
network_interface = "${aws_network_interface.bar.id}"
|
network_interface = "${aws_network_interface.bar.id}"
|
||||||
private_ip = "10.0.0.10"
|
associate_with_private_ip = "10.0.0.10"
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "aws_eip" "two" {
|
resource "aws_eip" "two" {
|
||||||
vpc = "true"
|
vpc = "true"
|
||||||
network_interface = "${aws_network_interface.bar.id}"
|
network_interface = "${aws_network_interface.bar.id}"
|
||||||
private_ip = "10.0.0.11"
|
associate_with_private_ip = "10.0.0.11"
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
|
@ -28,15 +28,54 @@ resource "aws_network_interface" "multi-ip" {
|
||||||
subnet_id = "${aws_subnet.main.id}"
|
subnet_id = "${aws_subnet.main.id}"
|
||||||
private_ips = ["10.0.0.10", "10.0.0.11"]
|
private_ips = ["10.0.0.10", "10.0.0.11"]
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "aws_eip" "one" {
|
resource "aws_eip" "one" {
|
||||||
vpc = true
|
vpc = true
|
||||||
network_interface = "${aws_network_interface.multi-ip.id}"
|
network_interface = "${aws_network_interface.multi-ip.id}"
|
||||||
private_ip = "10.0.0.10"
|
associate_with_private_ip = "10.0.0.10"
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "aws_eip" "two" {
|
resource "aws_eip" "two" {
|
||||||
vpc = true
|
vpc = true
|
||||||
network_interface = "${aws_network_interface.multi-ip.id}"
|
network_interface = "${aws_network_interface.multi-ip.id}"
|
||||||
private_ip = "10.0.0.11"
|
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"
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -47,7 +86,7 @@ The following arguments are supported:
|
||||||
* `vpc` - (Optional) Boolean if the EIP is in a VPC or not.
|
* `vpc` - (Optional) Boolean if the EIP is in a VPC or not.
|
||||||
* `instance` - (Optional) EC2 instance ID.
|
* `instance` - (Optional) EC2 instance ID.
|
||||||
* `network_interface` - (Optional) Network interface ID to associate with.
|
* `network_interface` - (Optional) Network interface ID to associate with.
|
||||||
* `private_ip` - (Optional) The primary or secondary private IP address to
|
* `associate_with_private_ip` - (Optional) A user specified primary or secondary private IP address to
|
||||||
associate with the Elastic IP address. If no private IP address is specified,
|
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.
|
the Elastic IP address is associated with the primary private IP address.
|
||||||
|
|
||||||
|
@ -62,6 +101,8 @@ The following attributes are exported:
|
||||||
|
|
||||||
* `id` - Contains the EIP allocation ID.
|
* `id` - Contains the EIP allocation ID.
|
||||||
* `private_ip` - Contains the private IP address (if in VPC).
|
* `private_ip` - Contains the private IP address (if in VPC).
|
||||||
|
* `associate_with_private_ip` - Contains the user specified private IP address
|
||||||
|
(if in VPC).
|
||||||
* `public_ip` - Contains the public IP address.
|
* `public_ip` - Contains the public IP address.
|
||||||
* `instance` - Contains the ID of the attached instance.
|
* `instance` - Contains the ID of the attached instance.
|
||||||
* `network_interface` - Contains the ID of the attached network interface.
|
* `network_interface` - Contains the ID of the attached network interface.
|
||||||
|
|
Loading…
Reference in New Issue