From d895365fd5c4090d78d880e0b60a66b4b07e9540 Mon Sep 17 00:00:00 2001 From: Graham Davison Date: Thu, 8 Sep 2022 12:26:26 -0700 Subject: [PATCH 1/3] `make fmt` --- internal/service/acm/sweep.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/service/acm/sweep.go b/internal/service/acm/sweep.go index e12138944f6..9fe66134a6d 100644 --- a/internal/service/acm/sweep.go +++ b/internal/service/acm/sweep.go @@ -72,7 +72,7 @@ func sweepCertificates(region string) error { for _, iub := range output.Certificate.InUseBy { m[aws.StringValue(iub)[:77]] = "" } - for k, _ := range m { + for k := range m { log.Printf("[INFO] %s...", k) } continue From f337daa137f4bb01180cc2d98db4657ff18c698c Mon Sep 17 00:00:00 2001 From: Graham Davison Date: Thu, 8 Sep 2022 14:51:21 -0700 Subject: [PATCH 2/3] Uses default if `vpc` not set --- internal/service/ec2/ec2_eip.go | 8 +++---- internal/service/ec2/ec2_eip_test.go | 33 ++++++++++++++++++++++++++++ website/docs/r/eip.html.markdown | 8 ++++--- 3 files changed, 41 insertions(+), 8 deletions(-) diff --git a/internal/service/ec2/ec2_eip.go b/internal/service/ec2/ec2_eip.go index 93ae1384184..8068b16950f 100644 --- a/internal/service/ec2/ec2_eip.go +++ b/internal/service/ec2/ec2_eip.go @@ -131,12 +131,10 @@ func resourceEIPCreate(d *schema.ResourceData, meta interface{}) error { defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig tags := defaultTagsConfig.MergeTags(tftags.New(d.Get("tags").(map[string]interface{}))) - if _, ok := d.GetOk("vpc"); !ok { - return errors.New(`with the retirement of EC2-Classic no new non-VPC EC2 EIPs can be created`) - } + input := &ec2.AllocateAddressInput{} - input := &ec2.AllocateAddressInput{ - Domain: aws.String(ec2.DomainTypeVpc), + if v := d.Get("vpc"); v != nil && v.(bool) { + input.Domain = aws.String(ec2.DomainTypeVpc) } if v, ok := d.GetOk("address"); ok { diff --git a/internal/service/ec2/ec2_eip_test.go b/internal/service/ec2/ec2_eip_test.go index 44a51101f4c..a8f37757b09 100644 --- a/internal/service/ec2/ec2_eip_test.go +++ b/internal/service/ec2/ec2_eip_test.go @@ -68,6 +68,34 @@ func TestAccEC2EIP_disappears(t *testing.T) { }) } +func TestAccEC2EIP_noVPC(t *testing.T) { + var conf ec2.Address + resourceName := "aws_eip.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(t) }, + ErrorCheck: acctest.ErrorCheck(t, ec2.EndpointsID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckEIPDestroy, + Steps: []resource.TestStep{ + { + Config: testAccEIPConfig_noVPC, + Check: resource.ComposeTestCheckFunc( + testAccCheckEIPExists(resourceName, &conf), + resource.TestCheckResourceAttr(resourceName, "domain", "vpc"), + resource.TestCheckResourceAttrSet(resourceName, "public_ip"), + testAccCheckEIPPublicDNS(resourceName), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + func TestAccEC2EIP_tags(t *testing.T) { var conf ec2.Address resourceName := "aws_eip.test" @@ -745,6 +773,11 @@ resource "aws_eip" "test" { } ` +const testAccEIPConfig_noVPC = ` +resource "aws_eip" "test" { +} +` + func testAccEIPConfig_tags1(tagKey1, tagValue1 string) string { return fmt.Sprintf(` resource "aws_eip" "test" { diff --git a/website/docs/r/eip.html.markdown b/website/docs/r/eip.html.markdown index 3f88f9c32c5..2422c04ef14 100644 --- a/website/docs/r/eip.html.markdown +++ b/website/docs/r/eip.html.markdown @@ -103,9 +103,11 @@ The following arguments are supported: * `instance` - (Optional) EC2 instance ID. * `network_border_group` - (Optional) Location from which the IP address is advertised. Use this parameter to limit the address to this location. * `network_interface` - (Optional) Network interface ID to associate with. -* `public_ipv4_pool` - (Optional) EC2 IPv4 address pool identifier or `amazon`. This option is only available for VPC EIPs. +* `public_ipv4_pool` - (Optional) EC2 IPv4 address pool identifier or `amazon`. + This option is only available for VPC EIPs. * `tags` - (Optional) Map of tags to assign to the resource. Tags can only be applied to EIPs in a VPC. If configured with a provider [`default_tags` configuration block](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#default_tags-configuration-block) present, tags with matching keys will overwrite those defined at the provider-level. * `vpc` - (Optional) Boolean if the EIP is in a VPC or not. + Defaults to `true` unless the region supports EC2-Classic. ~> **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 have undefined behavior. See the relevant [AssociateAddress API Call][1] for more information. @@ -120,7 +122,7 @@ In addition to all arguments above, the following attributes are exported: * `association_id` - ID representing the association of the address with an instance in a VPC. * `carrier_ip` - Carrier IP address. * `customer_owned_ip` - Customer owned IP. -* `domain` - Indicates if this EIP is for use in VPC (`vpc`) or EC2 Classic (`standard`). +* `domain` - Indicates if this EIP is for use in VPC (`vpc`) or EC2-Classic (`standard`). * `id` - Contains the EIP allocation ID. * `private_dns` - The Private DNS associated with the Elastic IP address (if in VPC). * `private_ip` - Contains the private IP address (if in VPC). @@ -146,7 +148,7 @@ EIPs in a VPC can be imported using their Allocation ID, e.g., $ terraform import aws_eip.bar eipalloc-00a10e96 ``` -EIPs in EC2 Classic can be imported using their Public IP, e.g., +EIPs in EC2-Classic can be imported using their Public IP, e.g., ``` $ terraform import aws_eip.bar 52.0.0.0 From 633956600e2c95ee6d00974d4b028249fc206ff1 Mon Sep 17 00:00:00 2001 From: Graham Davison Date: Thu, 8 Sep 2022 14:56:28 -0700 Subject: [PATCH 3/3] Adds CHANGELOG entry --- .changelog/26716.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/26716.txt diff --git a/.changelog/26716.txt b/.changelog/26716.txt new file mode 100644 index 00000000000..c970dada9f4 --- /dev/null +++ b/.changelog/26716.txt @@ -0,0 +1,3 @@ +```release-note:bug +resource/aws_eip: Defaults to default regional `domain` when `vpc` not set +```