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

aws_eip: Add 'carrier_ip' attribute #16724

Merged
merged 2 commits into from
Dec 15, 2020
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
5 changes: 5 additions & 0 deletions aws/data_source_aws_eip.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ func dataSourceAwsEip() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"carrier_ip": {
Type: schema.TypeString,
Computed: true,
},
"customer_owned_ipv4_pool": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -158,6 +162,7 @@ func dataSourceAwsEipRead(d *schema.ResourceData, meta interface{}) error {
}
}
d.Set("public_ipv4_pool", eip.PublicIpv4Pool)
d.Set("carrier_ip", eip.CarrierIp)
d.Set("customer_owned_ipv4_pool", eip.CustomerOwnedIpv4Pool)
d.Set("customer_owned_ip", eip.CustomerOwnedIp)

Expand Down
43 changes: 43 additions & 0 deletions aws/data_source_aws_eip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,26 @@ func TestAccDataSourceAwsEip_Instance(t *testing.T) {
})
}

func TestAccDataSourceAWSEIP_CarrierIP(t *testing.T) {
ewbankkit marked this conversation as resolved.
Show resolved Hide resolved
dataSourceName := "data.aws_eip.test"
resourceName := "aws_eip.test"
rName := acctest.RandomWithPrefix("tf-acc-test")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSWavelengthZoneAvailable(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccDataSourceAWSEIPConfigCarrierIP(rName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrPair(dataSourceName, "carrier_ip", resourceName, "carrier_ip"),
resource.TestCheckResourceAttrPair(dataSourceName, "public_ip", resourceName, "public_ip"),
),
},
},
})
}

func TestAccDataSourceAWSEIP_CustomerOwnedIpv4Pool(t *testing.T) {
dataSourceName := "data.aws_eip.test"
resourceName := "aws_eip.test"
Expand Down Expand Up @@ -328,3 +348,26 @@ data "aws_eip" "test" {
}
}
`

func testAccDataSourceAWSEIPConfigCarrierIP(rName string) string {
return composeConfig(
testAccAvailableAZsWavelengthZonesDefaultExcludeConfig(),
fmt.Sprintf(`
data "aws_availability_zone" "available" {
name = data.aws_availability_zones.available.names[0]
}

resource "aws_eip" "test" {
vpc = true
network_border_group = data.aws_availability_zone.available.network_border_group

tags = {
Name = %[1]q
}
}

data "aws_eip" "test" {
id = aws_eip.test.id
}
`, rName))
}
9 changes: 8 additions & 1 deletion aws/resource_aws_eip.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ func resourceAwsEip() *schema.Resource {
Optional: true,
},

"carrier_ip": {
Type: schema.TypeString,
Computed: true,
},

"customer_owned_ipv4_pool": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -293,6 +298,7 @@ func resourceAwsEipRead(d *schema.ResourceData, meta interface{}) error {
}
}
d.Set("public_ipv4_pool", address.PublicIpv4Pool)
d.Set("carrier_ip", address.CarrierIp)
d.Set("customer_owned_ipv4_pool", address.CustomerOwnedIpv4Pool)
d.Set("customer_owned_ip", address.CustomerOwnedIp)
d.Set("network_border_group", address.NetworkBorderGroup)
Expand Down Expand Up @@ -441,7 +447,8 @@ func resourceAwsEipDelete(d *schema.ResourceData, meta interface{}) error {
case ec2.DomainTypeVpc:
log.Printf("[DEBUG] EIP release (destroy) address allocation: %v", d.Id())
input = &ec2.ReleaseAddressInput{
AllocationId: aws.String(d.Id()),
AllocationId: aws.String(d.Id()),
NetworkBorderGroup: aws.String(d.Get("network_border_group").(string)),
ewbankkit marked this conversation as resolved.
Show resolved Hide resolved
}
case ec2.DomainTypeStandard:
log.Printf("[DEBUG] EIP release (destroy) address: %v", d.Id())
Expand Down
48 changes: 48 additions & 0 deletions aws/resource_aws_eip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,35 @@ func TestAccAWSEIP_NetworkBorderGroup(t *testing.T) {
})
}

func TestAccAWSEIP_CarrierIP(t *testing.T) {
var conf ec2.Address
rName := acctest.RandomWithPrefix("tf-acc-test")
resourceName := "aws_eip.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSWavelengthZoneAvailable(t) },
IDRefreshName: resourceName,
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSEIPDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSEIPConfigCarrierIP(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSEIPExists(resourceName, &conf),
resource.TestCheckResourceAttrSet(resourceName, "carrier_ip"),
resource.TestCheckResourceAttrSet(resourceName, "network_border_group"),
ewbankkit marked this conversation as resolved.
Show resolved Hide resolved
resource.TestCheckResourceAttr(resourceName, "public_ip", ""),
),
},
{
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 @@ -1176,3 +1205,22 @@ resource "aws_eip" "test" {
network_border_group = data.aws_region.current.name
}
`

func testAccAWSEIPConfigCarrierIP(rName string) string {
return composeConfig(
testAccAvailableAZsWavelengthZonesDefaultExcludeConfig(),
fmt.Sprintf(`
data "aws_availability_zone" "available" {
name = data.aws_availability_zones.available.names[0]
}

resource "aws_eip" "test" {
vpc = true
network_border_group = data.aws_availability_zone.available.network_border_group

tags = {
Name = %[1]q
}
}
`, rName))
}
24 changes: 24 additions & 0 deletions aws/resource_aws_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3307,6 +3307,30 @@ data "aws_availability_zones" "available" {
`
}

func testAccAvailableAZsWavelengthZonesExcludeConfig(excludeZoneIds ...string) string {
return fmt.Sprintf(`
data "aws_availability_zones" "available" {
exclude_zone_ids = ["%[1]s"]
state = "available"

filter {
name = "zone-type"
values = ["wavelength-zone"]
}

filter {
name = "opt-in-status"
values = ["opted-in"]
}
}
`, strings.Join(excludeZoneIds, "\", \""))
}

func testAccAvailableAZsWavelengthZonesDefaultExcludeConfig() string {
// Exclude usw2-wl1-den-wlz1 as there may be problems allocating carrier IP addresses.
return testAccAvailableAZsWavelengthZonesExcludeConfig("usw2-wl1-den-wlz1")
}

func testAccInstanceConfigInDefaultVpcBySgName(rName string) string {
return testAccAvailableAZsNoOptInDefaultExcludeConfig() +
testAccLatestAmazonLinuxHvmEbsAmiConfig() +
Expand Down
1 change: 1 addition & 0 deletions website/docs/d/eip.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ In addition to all arguments above, the following attributes are exported:
* `public_ip` - Public IP address of Elastic IP.
* `public_dns` - Public DNS associated with the Elastic IP address.
* `public_ipv4_pool` - The ID of an address pool.
* `carrier_ip` - The carrier IP address.
* `customer_owned_ipv4_pool` - The ID of a Customer Owned IP 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)
* `customer_owned_ip` - Customer Owned IP.
* `tags` - Key-value map of tags associated with Elastic IP.
Expand Down
1 change: 1 addition & 0 deletions website/docs/r/eip.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ In addition to all arguments above, the following attributes are exported:
* `instance` - Contains the ID of the attached instance.
* `network_interface` - Contains the ID of the attached network interface.
* `public_ipv4_pool` - EC2 IPv4 address pool identifier (if in VPC).
* `carrier_ip` - The carrier IP address.
* `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)
* `customer_owned_ip` - Customer owned IP.
* `domain` - Indicates if this EIP is for use in VPC (`vpc`) or EC2 Classic (`standard`).
Expand Down