Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resource/aws_eip: Default to default domain when vpc not set #26716

Merged
merged 3 commits into from
Sep 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/26716.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_eip: Defaults to default regional `domain` when `vpc` not set
ewbankkit marked this conversation as resolved.
Show resolved Hide resolved
```
2 changes: 1 addition & 1 deletion internal/service/acm/sweep.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 3 additions & 5 deletions internal/service/ec2/ec2_eip.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
33 changes: 33 additions & 0 deletions internal/service/ec2/ec2_eip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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" {
Expand Down
8 changes: 5 additions & 3 deletions website/docs/r/eip.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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).
Expand All @@ -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
Expand Down