Skip to content

Commit

Permalink
resource/aws_eip: Add network_border_group attribute (#14028)
Browse files Browse the repository at this point in the history
* feat: support NetworkBorderGroup parameter for aws_eip resource

* test: add cover test

* docs: update resource documentation

* fixup! test: add cover test

* fixup! feat: support NetworkBorderGroup parameter for aws_eip resource

* Update aws/resource_aws_eip_test.go

Co-authored-by: Brian Flad <bflad417@gmail.com>
  • Loading branch information
drexler and bflad authored Nov 5, 2020
1 parent faa34d7 commit bdfcdf6
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
12 changes: 12 additions & 0 deletions aws/resource_aws_eip.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@ func resourceAwsEip() *schema.Resource {
Computed: true,
},

"network_border_group": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
},

"tags": tagsSchema(),
},
}
Expand All @@ -134,6 +141,10 @@ func resourceAwsEipCreate(d *schema.ResourceData, meta interface{}) error {
allocOpts.CustomerOwnedIpv4Pool = aws.String(v.(string))
}

if v, ok := d.GetOk("network_border_group"); ok {
allocOpts.NetworkBorderGroup = aws.String(v.(string))
}

log.Printf("[DEBUG] EIP create configuration: %#v", allocOpts)
allocResp, err := ec2conn.AllocateAddress(allocOpts)
if err != nil {
Expand Down Expand Up @@ -277,6 +288,7 @@ func resourceAwsEipRead(d *schema.ResourceData, meta interface{}) error {
d.Set("public_ipv4_pool", address.PublicIpv4Pool)
d.Set("customer_owned_ipv4_pool", address.CustomerOwnedIpv4Pool)
d.Set("customer_owned_ip", address.CustomerOwnedIp)
d.Set("network_border_group", address.NetworkBorderGroup)

// On import (domain never set, which it must've been if we created),
// set the 'vpc' attribute depending on if we're in a VPC.
Expand Down
37 changes: 37 additions & 0 deletions aws/resource_aws_eip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,34 @@ func TestAccAWSEIP_PublicIpv4Pool_default(t *testing.T) {
})
}

func TestAccAWSEIP_NetworkBorderGroup(t *testing.T) {
var conf ec2.Address
resourceName := "aws_eip.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
IDRefreshName: resourceName,
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSEIPDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSEIPConfigNetworkBorderGroup,
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSEIPExists(resourceName, &conf),
testAccCheckAWSEIPAttributes(&conf),
resource.TestCheckResourceAttr(resourceName, "public_ipv4_pool", "amazon"),
resource.TestCheckResourceAttr(resourceName, "network_border_group", testAccGetRegion()),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

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")
Expand Down Expand Up @@ -1095,3 +1123,12 @@ resource "aws_eip" "test" {
}
`
}

const testAccAWSEIPConfigNetworkBorderGroup = `
data "aws_region" current {}
resource "aws_eip" "test" {
vpc = true
network_border_group = data.aws_region.current.name
}
`
1 change: 1 addition & 0 deletions website/docs/r/eip.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ The following arguments are supported:
* `tags` - (Optional) A map of tags to assign to the resource. Tags can only be applied to EIPs in a VPC.
* `public_ipv4_pool` - (Optional) EC2 IPv4 address pool identifier or `amazon`. This option is only available for VPC EIPs.
* `customer_owned_ipv4_pool` - The ID of a customer-owned address pool. For more on customer owned IP addressed check out [Customer-owned IP addresses guide](https://docs.aws.amazon.com/outposts/latest/userguide/outposts-networking-components.html#ip-addressing)
* `network_border_group` - The location from which the IP address is advertised. Use this parameter to limit the address to this location.

~> **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
Expand Down

0 comments on commit bdfcdf6

Please sign in to comment.