diff --git a/aws/resource_aws_eip.go b/aws/resource_aws_eip.go index 3de6d5b2c08..c3f8a1d580c 100644 --- a/aws/resource_aws_eip.go +++ b/aws/resource_aws_eip.go @@ -106,7 +106,7 @@ func resourceAwsEipCreate(d *schema.ResourceData, meta interface{}) error { } if v, ok := d.GetOk("public_ipv4_pool"); ok { - allocOpts.PublicIpv4Pool = aws.String(d.Get("public_ipv4_pool").(string)) + allocOpts.PublicIpv4Pool = aws.String(v.(string)) } log.Printf("[DEBUG] EIP create configuration: %#v", allocOpts) diff --git a/aws/resource_aws_eip_test.go b/aws/resource_aws_eip_test.go index 963a3dd1d41..76c4229f263 100644 --- a/aws/resource_aws_eip_test.go +++ b/aws/resource_aws_eip_test.go @@ -306,25 +306,46 @@ func TestAccAWSEIP_tags(t *testing.T) { }) } -func TestAccAWSEIP_PublicIpv4Pool(t *testing.T) { +func TestAccAWSEIP_PublicIpv4Pool_default(t *testing.T) { var conf ec2.Address resourceName := "aws_eip.bar" - envPoolName := fmt.Sprintf("%s", os.Getenv("AWS_EC2_EIP_PUBLIC_IPV4_POOL")) - poolName := "" - if envPoolName == "" { - poolName = "amazon" - } else { - poolName = envPoolName + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + IDRefreshName: resourceName, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSEIPDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSEIPConfig_PublicIpv4Pool_default, + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSEIPExists(resourceName, &conf), + testAccCheckAWSEIPAttributes(&conf), + resource.TestCheckResourceAttr(resourceName, "public_ipv4_pool", "amazon"), + ), + }, + }, + }) +} + +func TestAccAWSEIP_PublicIpv4Pool_custom(t *testing.T) { + if os.Getenv("AWS_EC2_EIP_PUBLIC_IPV4_POOL") == "" { + t.Skip("Environment variable AWS_EC2_EIP_PUBLIC_IPV4_POOL is not set") } + var conf ec2.Address + resourceName := "aws_eip.bar" + + poolName := fmt.Sprintf("%s", os.Getenv("AWS_EC2_EIP_PUBLIC_IPV4_POOL")) + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, - IDRefreshName: "aws_eip.bar", + IDRefreshName: resourceName, Providers: testAccProviders, CheckDestroy: testAccCheckAWSEIPDestroy, Steps: []resource.TestStep{ { - Config: testAccAWSEIPConfig_PublicIpv4Pool(poolName), + Config: testAccAWSEIPConfig_PublicIpv4Pool_custom(poolName), Check: resource.ComposeTestCheckFunc( testAccCheckAWSEIPExists(resourceName, &conf), testAccCheckAWSEIPAttributes(&conf), @@ -483,7 +504,13 @@ resource "aws_eip" "bar" { `, rName, testName) } -func testAccAWSEIPConfig_PublicIpv4Pool(poolName string) string { +const testAccAWSEIPConfig_PublicIpv4Pool_default = ` +resource "aws_eip" "bar" { + vpc = true +} +` + +func testAccAWSEIPConfig_PublicIpv4Pool_custom(poolName string) string { return fmt.Sprintf(` resource "aws_eip" "bar" { vpc = true diff --git a/website/docs/r/eip.html.markdown b/website/docs/r/eip.html.markdown index d005dd6ac81..d15fc35557f 100644 --- a/website/docs/r/eip.html.markdown +++ b/website/docs/r/eip.html.markdown @@ -104,7 +104,7 @@ The following arguments are supported: 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. * `tags` - (Optional) A mapping of tags to assign to the resource. -* `public_ipv4_pool` - (Optional) IPv4 address pool +* `public_ipv4_pool` - (Optional) EC2 IPv4 address pool identifier or `amazon`. This option is only available for VPC EIPs. ~> **NOTE:** You can specify either the `instance` ID or the `network_interface` ID, but not both. Including both will **not** return an error from the AWS API, but will @@ -122,7 +122,7 @@ In addition to all arguments above, the following attributes are exported: * `public_ip` - Contains the public IP address. * `instance` - Contains the ID of the attached instance. * `network_interface` - Contains the ID of the attached network interface. -* `public_ipv4_pool` - IPv4 address pool. +* `public_ipv4_pool` - EC2 IPv4 address pool identifier (if in VPC). ## Timeouts `aws_eip` provides the following [Timeouts](/docs/configuration/resources.html#timeouts) configuration options: