From e5ae663ba03eba7bb1c5c96f2388c2c6c37b4553 Mon Sep 17 00:00:00 2001 From: Scott Reu Date: Wed, 7 Dec 2022 15:14:34 -0800 Subject: [PATCH 01/20] Initial work on public_ipv4_pools data source --- internal/service/ec2/find.go | 47 +++++++ .../ec2/public_ipv4_pool_data_source.go | 117 ++++++++++++++++++ .../ec2/public_ipv4_pools_data_source.go | 79 ++++++++++++ .../ec2/public_ipv4_pools_data_source_test.go | 79 ++++++++++++ website/docs/d/public_ipv4_pool.html.markdown | 58 +++++++++ .../docs/d/public_ipv4_pools.html.markdown | 55 ++++++++ 6 files changed, 435 insertions(+) create mode 100644 internal/service/ec2/public_ipv4_pool_data_source.go create mode 100644 internal/service/ec2/public_ipv4_pools_data_source.go create mode 100644 internal/service/ec2/public_ipv4_pools_data_source_test.go create mode 100644 website/docs/d/public_ipv4_pool.html.markdown create mode 100644 website/docs/d/public_ipv4_pools.html.markdown diff --git a/internal/service/ec2/find.go b/internal/service/ec2/find.go index c9ea17048d8..213b501183c 100644 --- a/internal/service/ec2/find.go +++ b/internal/service/ec2/find.go @@ -1212,6 +1212,53 @@ func FindInstanceTypeOfferings(conn *ec2.EC2, input *ec2.DescribeInstanceTypeOff return output, nil } +func FindPublicIpv4Pool(ctx context.Context, conn *ec2.EC2, input *ec2.DescribePublicIpv4PoolsInput) ([]*ec2.PublicIpv4Pool, error) { + var output *ec2.DescribePublicIpv4PoolsOutput + var result []*ec2.PublicIpv4Pool + + output, err := conn.DescribePublicIpv4Pools(input) + if err != nil { + return nil, err + } + + result = output.PublicIpv4Pools + + return result, nil +} + +func FindPublicIpv4Pools(ctx context.Context, conn *ec2.EC2, input *ec2.DescribePublicIpv4PoolsInput) ([]*ec2.PublicIpv4Pool, error) { + var output []*ec2.PublicIpv4Pool + + err := conn.DescribePublicIpv4PoolsPages(input, func(page *ec2.DescribePublicIpv4PoolsOutput, lastPage bool) bool { + if page == nil { + return !lastPage + } + + for _, v := range page.PublicIpv4Pools { + if v == nil { + continue + } + + output = append(output, v) + } + + return !lastPage + }) + + if tfawserr.ErrCodeEquals(err, errCodeInvalidPoolIDNotFound) { + return nil, &resource.NotFoundError{ + LastError: err, + LastRequest: input, + } + } + + if err != nil { + return nil, err + } + + return output, nil +} + func FindLocalGatewayRouteTables(conn *ec2.EC2, input *ec2.DescribeLocalGatewayRouteTablesInput) ([]*ec2.LocalGatewayRouteTable, error) { var output []*ec2.LocalGatewayRouteTable diff --git a/internal/service/ec2/public_ipv4_pool_data_source.go b/internal/service/ec2/public_ipv4_pool_data_source.go new file mode 100644 index 00000000000..e3553eb1f87 --- /dev/null +++ b/internal/service/ec2/public_ipv4_pool_data_source.go @@ -0,0 +1,117 @@ +package ec2 + +import ( + "context" + + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/service/ec2" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-provider-aws/internal/conns" + "github.com/hashicorp/terraform-provider-aws/internal/create" + tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" + "github.com/hashicorp/terraform-provider-aws/names" +) + +func DataSourcePublicIpv4Pool() *schema.Resource { + return &schema.Resource{ + ReadWithoutTimeout: dataSourcePublicIpv4PoolRead, + Schema: map[string]*schema.Schema{ + "filter": DataSourceFiltersSchema(), + "pool_id": { + Type: schema.TypeString, + Required: true, + }, + "pool": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "tags": tftags.TagsSchemaComputed(), + }, + } +} + +const ( + DSNamePublicIpv4Pool = "Public IPv4 Pool Data Source" +) + +func dataSourcePublicIpv4PoolRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + conn := meta.(*conns.AWSClient).EC2Conn + input := &ec2.DescribePublicIpv4PoolsInput{} + + if v, ok := d.GetOk("pool_id"); ok { + input.PoolIds = aws.StringSlice([]string{v.(string)}) + } + + input.Filters = append(input.Filters, BuildTagFilterList( + Tags(tftags.New(d.Get("tags").(map[string]interface{}))), + )...) + + input.Filters = append(input.Filters, BuildFiltersDataSource( + d.Get("filter").(*schema.Set), + )...) + + if len(input.Filters) == 0 { + input.Filters = nil + } + + output, err := FindPublicIpv4Pool(ctx, conn, input) + if err != nil { + create.DiagError(names.EC2, create.ErrActionSetting, DSNamePublicIpv4Pool, d.Id(), err) + } + + pool := flattenPublicIpv4Pool(output[0]) + + d.SetId(meta.(*conns.AWSClient).Region) + d.Set("pool", pool) + + return nil +} + +func flattenPublicIpv4Pool(pool *ec2.PublicIpv4Pool) map[string]interface{} { + if pool == nil { + return map[string]interface{}{} + } + + m := map[string]interface{}{ + "description": aws.StringValue(pool.Description), + "network_border_group": aws.StringValue(pool.NetworkBorderGroup), + "pool_address_ranges": flattenPublicIpv4PoolRanges(pool.PoolAddressRanges), + "pool_id": aws.StringValue(pool.PoolId), + "tags": flattenTags(pool.Tags), + "total_address_count": aws.Int64Value(pool.TotalAddressCount), + "total_available_address_count": aws.Int64Value(pool.TotalAvailableAddressCount), + } + + return m +} + +func flattenPublicIpv4PoolRanges(pool_ranges []*ec2.PublicIpv4PoolRange) []interface{} { + result := []interface{}{} + + if pool_ranges == nil { + return result + } + + for _, v := range pool_ranges { + range_map := map[string]interface{}{ + "address_count": aws.Int64Value(v.AddressCount), + "available_address_count": aws.Int64Value(v.AvailableAddressCount), + "first_address": aws.StringValue(v.FirstAddress), + "last_address": aws.StringValue(v.LastAddress), + } + result = append(result, range_map) + } + + return result +} + +func flattenTags(tags []*ec2.Tag) map[string]string { + result := make(map[string]string) + for _, t := range tags { + result[aws.StringValue(t.Key)] = aws.StringValue(t.Value) + } + + return result +} diff --git a/internal/service/ec2/public_ipv4_pools_data_source.go b/internal/service/ec2/public_ipv4_pools_data_source.go new file mode 100644 index 00000000000..16c5fd8bf15 --- /dev/null +++ b/internal/service/ec2/public_ipv4_pools_data_source.go @@ -0,0 +1,79 @@ +package ec2 + +import ( + "context" + + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/service/ec2" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-provider-aws/internal/conns" + "github.com/hashicorp/terraform-provider-aws/internal/create" + tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" + "github.com/hashicorp/terraform-provider-aws/names" +) + +func DataSourcePublicIpv4Pools() *schema.Resource { + return &schema.Resource{ + ReadWithoutTimeout: dataSourcePublicIpv4PoolsRead, + Schema: map[string]*schema.Schema{ + "filter": DataSourceFiltersSchema(), + "pool_ids": { + Type: schema.TypeList, + Optional: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "pools": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeMap, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + }, + "tags": tftags.TagsSchemaComputed(), + }, + } +} + +const ( + DSNamePublicIpv4Pools = "Public IPv4 Pools Data Source" +) + +func dataSourcePublicIpv4PoolsRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + conn := meta.(*conns.AWSClient).EC2Conn + input := &ec2.DescribePublicIpv4PoolsInput{} + + if v, ok := d.GetOk("pool_ids"); ok { + input.PoolIds = aws.StringSlice([]string{v.(string)}) + } + + input.Filters = append(input.Filters, BuildTagFilterList( + Tags(tftags.New(d.Get("tags").(map[string]interface{}))), + )...) + + input.Filters = append(input.Filters, BuildFiltersDataSource( + d.Get("filter").(*schema.Set), + )...) + + if len(input.Filters) == 0 { + input.Filters = nil + } + + publicIpv4Pools := []map[string]interface{}{} + + output, err := FindPublicIpv4Pools(ctx, conn, input) + if err != nil { + create.DiagError(names.EC2, create.ErrActionSetting, DSNamePublicIpv4Pools, d.Id(), err) + } + + for _, v := range output { + pool := flattenPublicIpv4Pool(v) + publicIpv4Pools = append(publicIpv4Pools, pool) + } + + d.SetId(meta.(*conns.AWSClient).Region) + d.Set("pools", publicIpv4Pools) + + return nil +} diff --git a/internal/service/ec2/public_ipv4_pools_data_source_test.go b/internal/service/ec2/public_ipv4_pools_data_source_test.go new file mode 100644 index 00000000000..16c5fd8bf15 --- /dev/null +++ b/internal/service/ec2/public_ipv4_pools_data_source_test.go @@ -0,0 +1,79 @@ +package ec2 + +import ( + "context" + + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/service/ec2" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-provider-aws/internal/conns" + "github.com/hashicorp/terraform-provider-aws/internal/create" + tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" + "github.com/hashicorp/terraform-provider-aws/names" +) + +func DataSourcePublicIpv4Pools() *schema.Resource { + return &schema.Resource{ + ReadWithoutTimeout: dataSourcePublicIpv4PoolsRead, + Schema: map[string]*schema.Schema{ + "filter": DataSourceFiltersSchema(), + "pool_ids": { + Type: schema.TypeList, + Optional: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "pools": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeMap, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + }, + "tags": tftags.TagsSchemaComputed(), + }, + } +} + +const ( + DSNamePublicIpv4Pools = "Public IPv4 Pools Data Source" +) + +func dataSourcePublicIpv4PoolsRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + conn := meta.(*conns.AWSClient).EC2Conn + input := &ec2.DescribePublicIpv4PoolsInput{} + + if v, ok := d.GetOk("pool_ids"); ok { + input.PoolIds = aws.StringSlice([]string{v.(string)}) + } + + input.Filters = append(input.Filters, BuildTagFilterList( + Tags(tftags.New(d.Get("tags").(map[string]interface{}))), + )...) + + input.Filters = append(input.Filters, BuildFiltersDataSource( + d.Get("filter").(*schema.Set), + )...) + + if len(input.Filters) == 0 { + input.Filters = nil + } + + publicIpv4Pools := []map[string]interface{}{} + + output, err := FindPublicIpv4Pools(ctx, conn, input) + if err != nil { + create.DiagError(names.EC2, create.ErrActionSetting, DSNamePublicIpv4Pools, d.Id(), err) + } + + for _, v := range output { + pool := flattenPublicIpv4Pool(v) + publicIpv4Pools = append(publicIpv4Pools, pool) + } + + d.SetId(meta.(*conns.AWSClient).Region) + d.Set("pools", publicIpv4Pools) + + return nil +} diff --git a/website/docs/d/public_ipv4_pool.html.markdown b/website/docs/d/public_ipv4_pool.html.markdown new file mode 100644 index 00000000000..dcf853369e6 --- /dev/null +++ b/website/docs/d/public_ipv4_pool.html.markdown @@ -0,0 +1,58 @@ +--- +subcategory: "VPC (Virtual Private Cloud)" +layout: "aws" +page_title: "AWS: aws_vpc_public_ipv4_pools" +description: |- + Terraform data source for managing AWS VPC (Virtual Private Cloud) Public IPv4 Pools. +--- + +# Data Source: aws_ec2_public_ipv4_pools + +Terraform data source for managing an AWS VPC (Virtual Private Cloud) Public IPv4 Pool + +## Example Usage + +### Basic Usage + +```terraform +data "aws_vpc_public_ipv4_pool" "example" { + pool_ids = "ipv4pool-ec2-000df99cff0c1ec10" +} +``` + +### Usage with Filter +```terraform +data "aws_vpc_public_ipv4_pool" "example" { + filter { + name = "tag-key" + values = ["ExampleTagKey"] + } +} +``` + +## Argument Reference + +The following arguments are required: + +* `pool_id` - (Required) AWS resource IDs of a public IPv4 pool (as a string) for which this data source will fetch detailed information. + +The following arguments are optional: + +* `filter` - (Optional) One or more filters for results. Supported filters include `tag` and `tag-key`. +* `tags` - (Optional) One or more tags, which are used to filter results. + +## Attributes Reference + +In addition to all arguments above, the following attributes are exported: + +* `pool` - Record containing information about a Public IPv4 Pool. Contents: + - `description` - Description of the pool, if any. + - `network_border_group` - Name of the location from which the address pool is advertised. + - `pool_address_ranges` - List of Address Ranges in the Pool; each address range record contains: + - `address_count` - Number of addresses in the range. + - `available_address_count` - Number of available addresses in the range. + - `first_address` - First address in the range. + - `last_address` - Last address in the range. + - `tags` - Any tags for the address pool. + - `total_address_count` - Total number of addresses in the pool. + - `total_available_address_count` - Total number of available addresses in the pool. diff --git a/website/docs/d/public_ipv4_pools.html.markdown b/website/docs/d/public_ipv4_pools.html.markdown new file mode 100644 index 00000000000..790fa9314ec --- /dev/null +++ b/website/docs/d/public_ipv4_pools.html.markdown @@ -0,0 +1,55 @@ +--- +subcategory: "VPC (Virtual Private Cloud)" +layout: "aws" +page_title: "AWS: aws_vpc_public_ipv4_pools" +description: |- + Terraform data source for managing AWS VPC (Virtual Private Cloud) Public IPv4 Pools. +--- + +# Data Source: aws_ec2_public_ipv4_pools + +Terraform data source for managing AWS VPC (Virtual Private Cloud) Public IPv4 Pools + +## Example Usage + +### Basic Usage + +```terraform +data "aws_vpc_public_ipv4_pools" "example" { + pool_ids = ["ipv4pool-ec2-000df99cff0c1ec10", "ipv4pool-ec2-000fe121a300ffc94"] +} +``` + +### Usage with Filter +```terraform +data "aws_vpc_public_ipv4_pools" "example" { + filter { + name = "tag-key" + values = ["ExampleTagKey"] + } +} +``` + +## Argument Reference + +The following arguments are optional: + +* `pool_ids` - (Optional) List of AWS resource IDs of public IPv4 pools (as strings) for which this data source will fetch detailed information. If not specified, then this data source will return info about all pools in the configured region. +* `filter` - (Optional) One or more filters for results. Supported filters include `tag` and `tag-key`. +* `tags` - (Optional) One or more tags, which are used to filter results. + +## Attributes Reference + +In addition to all arguments above, the following attributes are exported: + +* `pools` - List of Public IPv4 Pool records. Each of these contains: + - `description` - Description of the pool, if any. + - `network_border_group` - Name of the location from which the address pool is advertised. + - `pool_address_ranges` - List of Address Ranges in the Pool; each address range record contains: + - `address_count` - Number of addresses in the range. + - `available_address_count` - Number of available addresses in the range. + - `first_address` - First address in the range. + - `last_address` - Last address in the range. + - `tags` - Any tags for the address pool. + - `total_address_count` - Total number of addresses in the pool. + - `total_available_address_count` - Total number of available addresses in the pool. From 044d2411feef039f4234dceb2d3ee0a67fbd7e98 Mon Sep 17 00:00:00 2001 From: Scott Reu Date: Wed, 7 Dec 2022 15:23:36 -0800 Subject: [PATCH 02/20] Remove test since we can't AccTest BYOIP-related resources --- .../ec2/public_ipv4_pools_data_source_test.go | 79 ------------------- 1 file changed, 79 deletions(-) delete mode 100644 internal/service/ec2/public_ipv4_pools_data_source_test.go diff --git a/internal/service/ec2/public_ipv4_pools_data_source_test.go b/internal/service/ec2/public_ipv4_pools_data_source_test.go deleted file mode 100644 index 16c5fd8bf15..00000000000 --- a/internal/service/ec2/public_ipv4_pools_data_source_test.go +++ /dev/null @@ -1,79 +0,0 @@ -package ec2 - -import ( - "context" - - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/ec2" - "github.com/hashicorp/terraform-plugin-sdk/v2/diag" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-provider-aws/internal/conns" - "github.com/hashicorp/terraform-provider-aws/internal/create" - tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" - "github.com/hashicorp/terraform-provider-aws/names" -) - -func DataSourcePublicIpv4Pools() *schema.Resource { - return &schema.Resource{ - ReadWithoutTimeout: dataSourcePublicIpv4PoolsRead, - Schema: map[string]*schema.Schema{ - "filter": DataSourceFiltersSchema(), - "pool_ids": { - Type: schema.TypeList, - Optional: true, - Elem: &schema.Schema{Type: schema.TypeString}, - }, - "pools": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeMap, - Elem: &schema.Schema{Type: schema.TypeString}, - }, - }, - "tags": tftags.TagsSchemaComputed(), - }, - } -} - -const ( - DSNamePublicIpv4Pools = "Public IPv4 Pools Data Source" -) - -func dataSourcePublicIpv4PoolsRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - conn := meta.(*conns.AWSClient).EC2Conn - input := &ec2.DescribePublicIpv4PoolsInput{} - - if v, ok := d.GetOk("pool_ids"); ok { - input.PoolIds = aws.StringSlice([]string{v.(string)}) - } - - input.Filters = append(input.Filters, BuildTagFilterList( - Tags(tftags.New(d.Get("tags").(map[string]interface{}))), - )...) - - input.Filters = append(input.Filters, BuildFiltersDataSource( - d.Get("filter").(*schema.Set), - )...) - - if len(input.Filters) == 0 { - input.Filters = nil - } - - publicIpv4Pools := []map[string]interface{}{} - - output, err := FindPublicIpv4Pools(ctx, conn, input) - if err != nil { - create.DiagError(names.EC2, create.ErrActionSetting, DSNamePublicIpv4Pools, d.Id(), err) - } - - for _, v := range output { - pool := flattenPublicIpv4Pool(v) - publicIpv4Pools = append(publicIpv4Pools, pool) - } - - d.SetId(meta.(*conns.AWSClient).Region) - d.Set("pools", publicIpv4Pools) - - return nil -} From 166bde7efc73a1cba68f5b658a7f7c93de19321b Mon Sep 17 00:00:00 2001 From: Scott Reu Date: Mon, 13 Mar 2023 12:55:45 -0700 Subject: [PATCH 03/20] Correct tftags.New calls to use new API requirement (ctx) --- internal/service/ec2/public_ipv4_pool_data_source.go | 2 +- internal/service/ec2/public_ipv4_pools_data_source.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/service/ec2/public_ipv4_pool_data_source.go b/internal/service/ec2/public_ipv4_pool_data_source.go index e3553eb1f87..d3d2660d075 100644 --- a/internal/service/ec2/public_ipv4_pool_data_source.go +++ b/internal/service/ec2/public_ipv4_pool_data_source.go @@ -45,7 +45,7 @@ func dataSourcePublicIpv4PoolRead(ctx context.Context, d *schema.ResourceData, m } input.Filters = append(input.Filters, BuildTagFilterList( - Tags(tftags.New(d.Get("tags").(map[string]interface{}))), + Tags(tftags.New(ctx, d.Get("tags").(map[string]interface{}))), )...) input.Filters = append(input.Filters, BuildFiltersDataSource( diff --git a/internal/service/ec2/public_ipv4_pools_data_source.go b/internal/service/ec2/public_ipv4_pools_data_source.go index 16c5fd8bf15..3fef8f72435 100644 --- a/internal/service/ec2/public_ipv4_pools_data_source.go +++ b/internal/service/ec2/public_ipv4_pools_data_source.go @@ -49,7 +49,7 @@ func dataSourcePublicIpv4PoolsRead(ctx context.Context, d *schema.ResourceData, } input.Filters = append(input.Filters, BuildTagFilterList( - Tags(tftags.New(d.Get("tags").(map[string]interface{}))), + Tags(tftags.New(ctx, d.Get("tags").(map[string]interface{}))), )...) input.Filters = append(input.Filters, BuildFiltersDataSource( From dfb9062c7d6182bf3dfbb1c0dcb2f3fcef47500e Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Mon, 13 Mar 2023 16:32:56 -0400 Subject: [PATCH 04/20] Add CHANGELOG entry. --- .changelog/28245.txt | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .changelog/28245.txt diff --git a/.changelog/28245.txt b/.changelog/28245.txt new file mode 100644 index 00000000000..3679718020e --- /dev/null +++ b/.changelog/28245.txt @@ -0,0 +1,7 @@ +```release-note:new-data-source +aws_vpc_public_ipv4_pools +``` + +```release-note:new-data-source +aws_vpc_public_ipv4_pool +``` \ No newline at end of file From 43ae24d66711117f7b0858330c24d24462308df8 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Mon, 13 Mar 2023 16:44:34 -0400 Subject: [PATCH 05/20] 'FindPublicIpv4Pool(s)' -> 'FindPublicIPv4Pool(s)'. --- internal/service/ec2/find.go | 4 ++-- internal/service/ec2/public_ipv4_pool_data_source.go | 3 ++- internal/service/ec2/public_ipv4_pools_data_source.go | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/internal/service/ec2/find.go b/internal/service/ec2/find.go index b4792587462..fde5f4b5065 100644 --- a/internal/service/ec2/find.go +++ b/internal/service/ec2/find.go @@ -1257,7 +1257,7 @@ func FindInstanceTypeOfferings(ctx context.Context, conn *ec2.EC2, input *ec2.De return output, nil } -func FindPublicIpv4Pool(ctx context.Context, conn *ec2.EC2, input *ec2.DescribePublicIpv4PoolsInput) ([]*ec2.PublicIpv4Pool, error) { +func FindPublicIPv4Pool(ctx context.Context, conn *ec2.EC2, input *ec2.DescribePublicIpv4PoolsInput) ([]*ec2.PublicIpv4Pool, error) { var output *ec2.DescribePublicIpv4PoolsOutput var result []*ec2.PublicIpv4Pool @@ -1271,7 +1271,7 @@ func FindPublicIpv4Pool(ctx context.Context, conn *ec2.EC2, input *ec2.DescribeP return result, nil } -func FindPublicIpv4Pools(ctx context.Context, conn *ec2.EC2, input *ec2.DescribePublicIpv4PoolsInput) ([]*ec2.PublicIpv4Pool, error) { +func FindPublicIPv4Pools(ctx context.Context, conn *ec2.EC2, input *ec2.DescribePublicIpv4PoolsInput) ([]*ec2.PublicIpv4Pool, error) { var output []*ec2.PublicIpv4Pool err := conn.DescribePublicIpv4PoolsPages(input, func(page *ec2.DescribePublicIpv4PoolsOutput, lastPage bool) bool { diff --git a/internal/service/ec2/public_ipv4_pool_data_source.go b/internal/service/ec2/public_ipv4_pool_data_source.go index d3d2660d075..5e4e768c111 100644 --- a/internal/service/ec2/public_ipv4_pool_data_source.go +++ b/internal/service/ec2/public_ipv4_pool_data_source.go @@ -16,6 +16,7 @@ import ( func DataSourcePublicIpv4Pool() *schema.Resource { return &schema.Resource{ ReadWithoutTimeout: dataSourcePublicIpv4PoolRead, + Schema: map[string]*schema.Schema{ "filter": DataSourceFiltersSchema(), "pool_id": { @@ -56,7 +57,7 @@ func dataSourcePublicIpv4PoolRead(ctx context.Context, d *schema.ResourceData, m input.Filters = nil } - output, err := FindPublicIpv4Pool(ctx, conn, input) + output, err := FindPublicIPv4Pool(ctx, conn, input) if err != nil { create.DiagError(names.EC2, create.ErrActionSetting, DSNamePublicIpv4Pool, d.Id(), err) } diff --git a/internal/service/ec2/public_ipv4_pools_data_source.go b/internal/service/ec2/public_ipv4_pools_data_source.go index 3fef8f72435..fd111cb5c03 100644 --- a/internal/service/ec2/public_ipv4_pools_data_source.go +++ b/internal/service/ec2/public_ipv4_pools_data_source.go @@ -62,7 +62,7 @@ func dataSourcePublicIpv4PoolsRead(ctx context.Context, d *schema.ResourceData, publicIpv4Pools := []map[string]interface{}{} - output, err := FindPublicIpv4Pools(ctx, conn, input) + output, err := FindPublicIPv4Pools(ctx, conn, input) if err != nil { create.DiagError(names.EC2, create.ErrActionSetting, DSNamePublicIpv4Pools, d.Id(), err) } From 1a93dcf1c721d1d419be57c8797e62acf999ad27 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Mon, 13 Mar 2023 16:48:12 -0400 Subject: [PATCH 06/20] Add and use 'errCodeInvalidPublicIpv4PoolIDNotFound'. --- internal/service/ec2/errors.go | 1 + internal/service/ec2/find.go | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/internal/service/ec2/errors.go b/internal/service/ec2/errors.go index e22f30beb17..6bc6924688f 100644 --- a/internal/service/ec2/errors.go +++ b/internal/service/ec2/errors.go @@ -68,6 +68,7 @@ const ( errCodeInvalidPoolIDNotFound = "InvalidPoolID.NotFound" errCodeInvalidPrefixListIDNotFound = "InvalidPrefixListID.NotFound" errCodeInvalidPrefixListIdNotFound = "InvalidPrefixListId.NotFound" + errCodeInvalidPublicIpv4PoolIDNotFound = "InvalidPublicIpv4PoolID.NotFound" errCodeInvalidRouteNotFound = "InvalidRoute.NotFound" errCodeInvalidRouteTableIDNotFound = "InvalidRouteTableID.NotFound" errCodeInvalidRouteTableIdNotFound = "InvalidRouteTableId.NotFound" diff --git a/internal/service/ec2/find.go b/internal/service/ec2/find.go index fde5f4b5065..c4134d98ced 100644 --- a/internal/service/ec2/find.go +++ b/internal/service/ec2/find.go @@ -1290,7 +1290,7 @@ func FindPublicIPv4Pools(ctx context.Context, conn *ec2.EC2, input *ec2.Describe return !lastPage }) - if tfawserr.ErrCodeEquals(err, errCodeInvalidPoolIDNotFound) { + if tfawserr.ErrCodeEquals(err, errCodeInvalidPublicIpv4PoolIDNotFound) { return nil, &resource.NotFoundError{ LastError: err, LastRequest: input, From 265fc088f5890eaecdd6142dbede49cdf2e8c66e Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Mon, 13 Mar 2023 16:51:28 -0400 Subject: [PATCH 07/20] Use 'FindPublicIPv4Pools' in 'FindPublicIPv4Pool'. --- internal/service/ec2/find.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/internal/service/ec2/find.go b/internal/service/ec2/find.go index c4134d98ced..b3aabbd0c3e 100644 --- a/internal/service/ec2/find.go +++ b/internal/service/ec2/find.go @@ -1257,18 +1257,22 @@ func FindInstanceTypeOfferings(ctx context.Context, conn *ec2.EC2, input *ec2.De return output, nil } -func FindPublicIPv4Pool(ctx context.Context, conn *ec2.EC2, input *ec2.DescribePublicIpv4PoolsInput) ([]*ec2.PublicIpv4Pool, error) { - var output *ec2.DescribePublicIpv4PoolsOutput - var result []*ec2.PublicIpv4Pool +func FindPublicIPv4Pool(ctx context.Context, conn *ec2.EC2, input *ec2.DescribePublicIpv4PoolsInput) (*ec2.PublicIpv4Pool, error) { + output, err := FindPublicIPv4Pools(ctx, conn, input) - output, err := conn.DescribePublicIpv4Pools(input) if err != nil { return nil, err } - result = output.PublicIpv4Pools + if len(output) == 0 || output[0] == nil { + return nil, tfresource.NewEmptyResultError(input) + } + + if count := len(output); count > 1 { + return nil, tfresource.NewTooManyResultsError(count, input) + } - return result, nil + return output[0], nil } func FindPublicIPv4Pools(ctx context.Context, conn *ec2.EC2, input *ec2.DescribePublicIpv4PoolsInput) ([]*ec2.PublicIpv4Pool, error) { From 632044751a01464fd7d72b0708928ee15ceeab80 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Mon, 13 Mar 2023 17:05:08 -0400 Subject: [PATCH 08/20] d/aws_vpc_public_ipv4_pools: Simplify attributes. --- .../ec2/public_ipv4_pools_data_source.go | 43 +++++++------------ internal/service/ec2/service_package_gen.go | 4 ++ .../docs/d/public_ipv4_pools.html.markdown | 34 ++++++--------- 3 files changed, 32 insertions(+), 49 deletions(-) diff --git a/internal/service/ec2/public_ipv4_pools_data_source.go b/internal/service/ec2/public_ipv4_pools_data_source.go index fd111cb5c03..ee4d0d09e58 100644 --- a/internal/service/ec2/public_ipv4_pools_data_source.go +++ b/internal/service/ec2/public_ipv4_pools_data_source.go @@ -8,45 +8,32 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-aws/internal/conns" - "github.com/hashicorp/terraform-provider-aws/internal/create" + "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" - "github.com/hashicorp/terraform-provider-aws/names" ) -func DataSourcePublicIpv4Pools() *schema.Resource { +// @SDKDataSource("aws_vpc_public_ipv4_pools") +func DataSourcePublicIPv4Pools() *schema.Resource { return &schema.Resource{ ReadWithoutTimeout: dataSourcePublicIpv4PoolsRead, + Schema: map[string]*schema.Schema{ "filter": DataSourceFiltersSchema(), "pool_ids": { - Type: schema.TypeList, - Optional: true, - Elem: &schema.Schema{Type: schema.TypeString}, - }, - "pools": { Type: schema.TypeList, Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeMap, - Elem: &schema.Schema{Type: schema.TypeString}, - }, + Elem: &schema.Schema{Type: schema.TypeString}, }, "tags": tftags.TagsSchemaComputed(), }, } } -const ( - DSNamePublicIpv4Pools = "Public IPv4 Pools Data Source" -) - func dataSourcePublicIpv4PoolsRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - conn := meta.(*conns.AWSClient).EC2Conn - input := &ec2.DescribePublicIpv4PoolsInput{} + var diags diag.Diagnostics + conn := meta.(*conns.AWSClient).EC2Conn() - if v, ok := d.GetOk("pool_ids"); ok { - input.PoolIds = aws.StringSlice([]string{v.(string)}) - } + input := &ec2.DescribePublicIpv4PoolsInput{} input.Filters = append(input.Filters, BuildTagFilterList( Tags(tftags.New(ctx, d.Get("tags").(map[string]interface{}))), @@ -60,20 +47,20 @@ func dataSourcePublicIpv4PoolsRead(ctx context.Context, d *schema.ResourceData, input.Filters = nil } - publicIpv4Pools := []map[string]interface{}{} - output, err := FindPublicIPv4Pools(ctx, conn, input) + if err != nil { - create.DiagError(names.EC2, create.ErrActionSetting, DSNamePublicIpv4Pools, d.Id(), err) + return sdkdiag.AppendErrorf(diags, "reading EC2 Public IPv4 Pools: %s", err) } + var poolIDs []string + for _, v := range output { - pool := flattenPublicIpv4Pool(v) - publicIpv4Pools = append(publicIpv4Pools, pool) + poolIDs = append(poolIDs, aws.StringValue(v.PoolId)) } d.SetId(meta.(*conns.AWSClient).Region) - d.Set("pools", publicIpv4Pools) + d.Set("pool_ids", poolIDs) - return nil + return diags } diff --git a/internal/service/ec2/service_package_gen.go b/internal/service/ec2/service_package_gen.go index ec2c9d41263..a12adf3a744 100644 --- a/internal/service/ec2/service_package_gen.go +++ b/internal/service/ec2/service_package_gen.go @@ -335,6 +335,10 @@ func (p *servicePackage) SDKDataSources(ctx context.Context) []*types.ServicePac Factory: DataSourceVPCPeeringConnections, TypeName: "aws_vpc_peering_connections", }, + { + Factory: DataSourcePublicIPv4Pools, + TypeName: "aws_vpc_public_ipv4_pools", + }, { Factory: DataSourceVPCs, TypeName: "aws_vpcs", diff --git a/website/docs/d/public_ipv4_pools.html.markdown b/website/docs/d/public_ipv4_pools.html.markdown index 790fa9314ec..149d986f4bd 100644 --- a/website/docs/d/public_ipv4_pools.html.markdown +++ b/website/docs/d/public_ipv4_pools.html.markdown @@ -3,21 +3,20 @@ subcategory: "VPC (Virtual Private Cloud)" layout: "aws" page_title: "AWS: aws_vpc_public_ipv4_pools" description: |- - Terraform data source for managing AWS VPC (Virtual Private Cloud) Public IPv4 Pools. + Terraform data source for getting information about AWS VPC (Virtual Private Cloud) Public IPv4 Pools. --- # Data Source: aws_ec2_public_ipv4_pools -Terraform data source for managing AWS VPC (Virtual Private Cloud) Public IPv4 Pools +Terraform data source for getting information about AWS VPC (Virtual Private Cloud) Public IPv4 Pools. ## Example Usage ### Basic Usage ```terraform -data "aws_vpc_public_ipv4_pools" "example" { - pool_ids = ["ipv4pool-ec2-000df99cff0c1ec10", "ipv4pool-ec2-000fe121a300ffc94"] -} +# Returns all public IPv4 pools. +data "aws_vpc_public_ipv4_pools" "example" {} ``` ### Usage with Filter @@ -34,22 +33,15 @@ data "aws_vpc_public_ipv4_pools" "example" { The following arguments are optional: -* `pool_ids` - (Optional) List of AWS resource IDs of public IPv4 pools (as strings) for which this data source will fetch detailed information. If not specified, then this data source will return info about all pools in the configured region. -* `filter` - (Optional) One or more filters for results. Supported filters include `tag` and `tag-key`. -* `tags` - (Optional) One or more tags, which are used to filter results. +* `filter` - (Optional) Custom filter block as described below. +* `tags` - (Optional) Map of tags, each pair of which must exactly match a pair on the desired pools. + +More complex filters can be expressed using one or more `filter` sub-blocks, +which take the following arguments: + +* `name` - (Required) Name of the field to filter by, as defined by [the underlying AWS API](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribePublicIpv4Pools.html). +* `values` - (Required) Set of values that are accepted for the given field. Pool IDs will be selected if any one of the given values match. ## Attributes Reference -In addition to all arguments above, the following attributes are exported: - -* `pools` - List of Public IPv4 Pool records. Each of these contains: - - `description` - Description of the pool, if any. - - `network_border_group` - Name of the location from which the address pool is advertised. - - `pool_address_ranges` - List of Address Ranges in the Pool; each address range record contains: - - `address_count` - Number of addresses in the range. - - `available_address_count` - Number of available addresses in the range. - - `first_address` - First address in the range. - - `last_address` - Last address in the range. - - `tags` - Any tags for the address pool. - - `total_address_count` - Total number of addresses in the pool. - - `total_available_address_count` - Total number of available addresses in the pool. +* `pool_ids` - List of all the pool IDs found. From ff2700842b390605fb67e0acf5269adaae296a56 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Mon, 13 Mar 2023 17:12:50 -0400 Subject: [PATCH 09/20] Add 'FindPublicIPv4PoolByID'. --- internal/service/ec2/find.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/internal/service/ec2/find.go b/internal/service/ec2/find.go index b3aabbd0c3e..1be25c959e7 100644 --- a/internal/service/ec2/find.go +++ b/internal/service/ec2/find.go @@ -1308,6 +1308,27 @@ func FindPublicIPv4Pools(ctx context.Context, conn *ec2.EC2, input *ec2.Describe return output, nil } +func FindPublicIPv4PoolByID(ctx context.Context, conn *ec2.EC2, id string) (*ec2.PublicIpv4Pool, error) { + input := &ec2.DescribePublicIpv4PoolsInput{ + PoolIds: aws.StringSlice([]string{id}), + } + + output, err := FindPublicIPv4Pool(ctx, conn, input) + + if err != nil { + return nil, err + } + + // Eventual consistency check. + if aws.StringValue(output.PoolId) != id { + return nil, &resource.NotFoundError{ + LastRequest: input, + } + } + + return output, nil +} + func FindLocalGatewayRouteTables(ctx context.Context, conn *ec2.EC2, input *ec2.DescribeLocalGatewayRouteTablesInput) ([]*ec2.LocalGatewayRouteTable, error) { var output []*ec2.LocalGatewayRouteTable From 9f563434cf70ffb1932f15df3a33d2c14a1ad19d Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Mon, 13 Mar 2023 17:27:01 -0400 Subject: [PATCH 10/20] d/aws_vpc_public_ipv4_pool: Simplify attributes. --- .../ec2/public_ipv4_pool_data_source.go | 155 ++++++++++-------- internal/service/ec2/service_package_gen.go | 4 + website/docs/d/public_ipv4_pool.html.markdown | 46 ++---- 3 files changed, 107 insertions(+), 98 deletions(-) diff --git a/internal/service/ec2/public_ipv4_pool_data_source.go b/internal/service/ec2/public_ipv4_pool_data_source.go index 5e4e768c111..f8e2afb6bcb 100644 --- a/internal/service/ec2/public_ipv4_pool_data_source.go +++ b/internal/service/ec2/public_ipv4_pool_data_source.go @@ -8,111 +8,132 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-aws/internal/conns" - "github.com/hashicorp/terraform-provider-aws/internal/create" + "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" - "github.com/hashicorp/terraform-provider-aws/names" ) -func DataSourcePublicIpv4Pool() *schema.Resource { +// @SDKDataSource("aws_vpc_public_ipv4_pool") +func DataSourcePublicIPv4Pool() *schema.Resource { return &schema.Resource{ ReadWithoutTimeout: dataSourcePublicIpv4PoolRead, Schema: map[string]*schema.Schema{ - "filter": DataSourceFiltersSchema(), + "description": { + Type: schema.TypeString, + Computed: true, + }, + "network_border_group": { + Type: schema.TypeString, + Computed: true, + }, + "pool_address_ranges": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "address_count": { + Type: schema.TypeInt, + Computed: true, + }, + "available_address_count": { + Type: schema.TypeInt, + Computed: true, + }, + "first_address": { + Type: schema.TypeString, + Computed: true, + }, + "last_address": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, "pool_id": { Type: schema.TypeString, Required: true, }, - "pool": { - Type: schema.TypeMap, + "tags": tftags.TagsSchemaComputed(), + "total_address_count": { + Type: schema.TypeInt, + Computed: true, + }, + "total_available_address_count": { + Type: schema.TypeInt, Computed: true, - Elem: &schema.Schema{Type: schema.TypeString}, }, - "tags": tftags.TagsSchemaComputed(), }, } } -const ( - DSNamePublicIpv4Pool = "Public IPv4 Pool Data Source" -) - func dataSourcePublicIpv4PoolRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - conn := meta.(*conns.AWSClient).EC2Conn - input := &ec2.DescribePublicIpv4PoolsInput{} - - if v, ok := d.GetOk("pool_id"); ok { - input.PoolIds = aws.StringSlice([]string{v.(string)}) - } + var diags diag.Diagnostics + conn := meta.(*conns.AWSClient).EC2Conn() + ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig - input.Filters = append(input.Filters, BuildTagFilterList( - Tags(tftags.New(ctx, d.Get("tags").(map[string]interface{}))), - )...) + poolID := d.Get("pool_id").(string) + pool, err := FindPublicIPv4PoolByID(ctx, conn, poolID) - input.Filters = append(input.Filters, BuildFiltersDataSource( - d.Get("filter").(*schema.Set), - )...) - - if len(input.Filters) == 0 { - input.Filters = nil - } - - output, err := FindPublicIPv4Pool(ctx, conn, input) if err != nil { - create.DiagError(names.EC2, create.ErrActionSetting, DSNamePublicIpv4Pool, d.Id(), err) + return sdkdiag.AppendErrorf(diags, "reading EC2 Public IPv4 Pool (%s): %s", poolID, err) } - pool := flattenPublicIpv4Pool(output[0]) - - d.SetId(meta.(*conns.AWSClient).Region) - d.Set("pool", pool) + d.SetId(poolID) + d.Set("description", pool.Description) + d.Set("network_border_group", pool.NetworkBorderGroup) + if err := d.Set("pool_address_ranges", flattenPublicIpv4PoolRanges(pool.PoolAddressRanges)); err != nil { + return sdkdiag.AppendErrorf(diags, "setting pool_address_ranges: %s", err) + } + if err := d.Set("tags", KeyValueTags(ctx, pool.Tags).IgnoreAWS().IgnoreConfig(ignoreTagsConfig).Map()); err != nil { + return sdkdiag.AppendErrorf(diags, "setting tags: %s", err) + } + d.Set("total_address_count", pool.TotalAddressCount) + d.Set("total_available_address_count", pool.TotalAvailableAddressCount) return nil } -func flattenPublicIpv4Pool(pool *ec2.PublicIpv4Pool) map[string]interface{} { - if pool == nil { - return map[string]interface{}{} +func flattenPublicIpv4PoolRange(apiObject *ec2.PublicIpv4PoolRange) map[string]interface{} { + if apiObject == nil { + return nil } - m := map[string]interface{}{ - "description": aws.StringValue(pool.Description), - "network_border_group": aws.StringValue(pool.NetworkBorderGroup), - "pool_address_ranges": flattenPublicIpv4PoolRanges(pool.PoolAddressRanges), - "pool_id": aws.StringValue(pool.PoolId), - "tags": flattenTags(pool.Tags), - "total_address_count": aws.Int64Value(pool.TotalAddressCount), - "total_available_address_count": aws.Int64Value(pool.TotalAvailableAddressCount), - } + tfMap := map[string]interface{}{} - return m -} + if v := apiObject.AddressCount; v != nil { + tfMap["address_count"] = aws.Int64Value(v) + } -func flattenPublicIpv4PoolRanges(pool_ranges []*ec2.PublicIpv4PoolRange) []interface{} { - result := []interface{}{} + if v := apiObject.AvailableAddressCount; v != nil { + tfMap["available_address_count"] = aws.Int64Value(v) + } - if pool_ranges == nil { - return result + if v := apiObject.FirstAddress; v != nil { + tfMap["first_address"] = aws.StringValue(v) } - for _, v := range pool_ranges { - range_map := map[string]interface{}{ - "address_count": aws.Int64Value(v.AddressCount), - "available_address_count": aws.Int64Value(v.AvailableAddressCount), - "first_address": aws.StringValue(v.FirstAddress), - "last_address": aws.StringValue(v.LastAddress), - } - result = append(result, range_map) + if v := apiObject.LastAddress; v != nil { + tfMap["last_address"] = aws.StringValue(v) } - return result + return tfMap } -func flattenTags(tags []*ec2.Tag) map[string]string { - result := make(map[string]string) - for _, t := range tags { - result[aws.StringValue(t.Key)] = aws.StringValue(t.Value) +func flattenPublicIpv4PoolRanges(apiObjects []*ec2.PublicIpv4PoolRange) []interface{} { + if len(apiObjects) == 0 { + return nil + } + + var tfList []interface{} + + for _, apiObject := range apiObjects { + if apiObject == nil { + continue + } + + tfList = append(tfList, flattenPublicIpv4PoolRange(apiObject)) } - return result + return tfList } diff --git a/internal/service/ec2/service_package_gen.go b/internal/service/ec2/service_package_gen.go index a12adf3a744..0e41645e9b4 100644 --- a/internal/service/ec2/service_package_gen.go +++ b/internal/service/ec2/service_package_gen.go @@ -335,6 +335,10 @@ func (p *servicePackage) SDKDataSources(ctx context.Context) []*types.ServicePac Factory: DataSourceVPCPeeringConnections, TypeName: "aws_vpc_peering_connections", }, + { + Factory: DataSourcePublicIPv4Pool, + TypeName: "aws_vpc_public_ipv4_pool", + }, { Factory: DataSourcePublicIPv4Pools, TypeName: "aws_vpc_public_ipv4_pools", diff --git a/website/docs/d/public_ipv4_pool.html.markdown b/website/docs/d/public_ipv4_pool.html.markdown index dcf853369e6..8674dca7cef 100644 --- a/website/docs/d/public_ipv4_pool.html.markdown +++ b/website/docs/d/public_ipv4_pool.html.markdown @@ -1,14 +1,14 @@ --- subcategory: "VPC (Virtual Private Cloud)" layout: "aws" -page_title: "AWS: aws_vpc_public_ipv4_pools" +page_title: "AWS: aws_vpc_public_ipv4_pool" description: |- - Terraform data source for managing AWS VPC (Virtual Private Cloud) Public IPv4 Pools. + Provides details about a specific AWS VPC (Virtual Private Cloud) Public IPv4 Pool. --- -# Data Source: aws_ec2_public_ipv4_pools +# Data Source: aws_ec2_public_ipv4_pool -Terraform data source for managing an AWS VPC (Virtual Private Cloud) Public IPv4 Pool +Provides details about a specific AWS VPC (Virtual Private Cloud) Public IPv4 Pool. ## Example Usage @@ -16,17 +16,7 @@ Terraform data source for managing an AWS VPC (Virtual Private Cloud) Public IPv ```terraform data "aws_vpc_public_ipv4_pool" "example" { - pool_ids = "ipv4pool-ec2-000df99cff0c1ec10" -} -``` - -### Usage with Filter -```terraform -data "aws_vpc_public_ipv4_pool" "example" { - filter { - name = "tag-key" - values = ["ExampleTagKey"] - } + pool_id = "ipv4pool-ec2-000df99cff0c1ec10" } ``` @@ -36,23 +26,17 @@ The following arguments are required: * `pool_id` - (Required) AWS resource IDs of a public IPv4 pool (as a string) for which this data source will fetch detailed information. -The following arguments are optional: - -* `filter` - (Optional) One or more filters for results. Supported filters include `tag` and `tag-key`. -* `tags` - (Optional) One or more tags, which are used to filter results. - ## Attributes Reference In addition to all arguments above, the following attributes are exported: -* `pool` - Record containing information about a Public IPv4 Pool. Contents: - - `description` - Description of the pool, if any. - - `network_border_group` - Name of the location from which the address pool is advertised. - - `pool_address_ranges` - List of Address Ranges in the Pool; each address range record contains: - - `address_count` - Number of addresses in the range. - - `available_address_count` - Number of available addresses in the range. - - `first_address` - First address in the range. - - `last_address` - Last address in the range. - - `tags` - Any tags for the address pool. - - `total_address_count` - Total number of addresses in the pool. - - `total_available_address_count` - Total number of available addresses in the pool. +* `description` - Description of the pool, if any. +* `network_border_group` - Name of the location from which the address pool is advertised. +* pool_address_ranges` - List of Address Ranges in the Pool; each address range record contains: + * `address_count` - Number of addresses in the range. + * `available_address_count` - Number of available addresses in the range. + * `first_address` - First address in the range. + * `last_address` - Last address in the range. +* `tags` - Any tags for the address pool. +* `total_address_count` - Total number of addresses in the pool. +* `total_available_address_count` - Total number of available addresses in the pool. From a5681aa55b2973ae63521de1fbec6ca2ea93faf5 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 14 Mar 2023 08:13:15 -0400 Subject: [PATCH 11/20] d/aws_vpc_public_ipv4_pools: Add acceptance tests. Acceptance test output: % make testacc TESTARGS='-run=TestAccEC2PublicIPv4PoolsDataSource_' PKG=ec2 ACCTEST_PARALLELISM=3 ==> Checking that code complies with gofmt requirements... TF_ACC=1 go test ./internal/service/ec2/... -v -count 1 -parallel 3 -run=TestAccEC2PublicIPv4PoolsDataSource_ -timeout 180m === RUN TestAccEC2PublicIPv4PoolsDataSource_basic === PAUSE TestAccEC2PublicIPv4PoolsDataSource_basic === RUN TestAccEC2PublicIPv4PoolsDataSource_tags === PAUSE TestAccEC2PublicIPv4PoolsDataSource_tags === CONT TestAccEC2PublicIPv4PoolsDataSource_basic === CONT TestAccEC2PublicIPv4PoolsDataSource_tags --- PASS: TestAccEC2PublicIPv4PoolsDataSource_basic (13.84s) --- PASS: TestAccEC2PublicIPv4PoolsDataSource_tags (13.85s) PASS ok github.com/hashicorp/terraform-provider-aws/internal/service/ec2 19.297s --- .../ec2/public_ipv4_pools_data_source_test.go | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 internal/service/ec2/public_ipv4_pools_data_source_test.go diff --git a/internal/service/ec2/public_ipv4_pools_data_source_test.go b/internal/service/ec2/public_ipv4_pools_data_source_test.go new file mode 100644 index 00000000000..8f2f8de124e --- /dev/null +++ b/internal/service/ec2/public_ipv4_pools_data_source_test.go @@ -0,0 +1,64 @@ +package ec2_test + +import ( + "fmt" + "testing" + + "github.com/aws/aws-sdk-go/service/ec2" + sdkacctest "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-provider-aws/internal/acctest" +) + +func TestAccEC2PublicIPv4PoolsDataSource_basic(t *testing.T) { + ctx := acctest.Context(t) + dataSourceName := "data.aws_vpc_public_ipv4_pools.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, ec2.EndpointsID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testPublicIPv4PoolsDataSourceConfig_basic, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet(dataSourceName, "pool_ids.#"), + ), + }, + }, + }) +} + +func TestAccEC2PublicIPv4PoolsDataSource_tags(t *testing.T) { + ctx := acctest.Context(t) + dataSourceName := "data.aws_vpc_public_ipv4_pools.test" + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, ec2.EndpointsID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testPublicIPv4PoolsDataSourceConfig_tags(rName), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(dataSourceName, "pool_ids.#", "0"), + ), + }, + }, + }) +} + +const testPublicIPv4PoolsDataSourceConfig_basic = ` +data "aws_vpc_public_ipv4_pools" "test" {} +` + +func testPublicIPv4PoolsDataSourceConfig_tags(rName string) string { + return fmt.Sprintf(` +data "aws_vpc_public_ipv4_pools" "test" { + tags = { + Name = %[1]q + } +} +`, rName) +} From 70094b3fe9ab3aab64eb8f16ed3ee5e23e30af9c Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 14 Mar 2023 08:31:11 -0400 Subject: [PATCH 12/20] d/aws_vpc_public_ipv4_pool: Add acceptance tests. Acceptance test output: % make testacc TESTARGS='-run=TestAccEC2PublicIPv4PoolDataSource_' PKG=ec2 ACCTEST_PARALLELISM=3 ==> Checking that code complies with gofmt requirements... TF_ACC=1 go test ./internal/service/ec2/... -v -count 1 -parallel 3 -run=TestAccEC2PublicIPv4PoolDataSource_ -timeout 180m === RUN TestAccEC2PublicIPv4PoolDataSource_basic === PAUSE TestAccEC2PublicIPv4PoolDataSource_basic === CONT TestAccEC2PublicIPv4PoolDataSource_basic public_ipv4_pool_data_source_test.go:49: skipping since no EC2 Public IPv4 Pools found --- SKIP: TestAccEC2PublicIPv4PoolDataSource_basic (0.88s) PASS ok github.com/hashicorp/terraform-provider-aws/internal/service/ec2 7.321s --- .../ec2/public_ipv4_pool_data_source_test.go | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 internal/service/ec2/public_ipv4_pool_data_source_test.go diff --git a/internal/service/ec2/public_ipv4_pool_data_source_test.go b/internal/service/ec2/public_ipv4_pool_data_source_test.go new file mode 100644 index 00000000000..18815263d35 --- /dev/null +++ b/internal/service/ec2/public_ipv4_pool_data_source_test.go @@ -0,0 +1,59 @@ +package ec2_test + +import ( + "context" + "testing" + + "github.com/aws/aws-sdk-go/service/ec2" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-provider-aws/internal/acctest" + "github.com/hashicorp/terraform-provider-aws/internal/conns" + tfec2 "github.com/hashicorp/terraform-provider-aws/internal/service/ec2" +) + +func TestAccEC2PublicIPv4PoolDataSource_basic(t *testing.T) { + ctx := acctest.Context(t) + dataSourceName := "data.aws_vpc_public_ipv4_pool.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheckPublicIPv4Pools(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, ec2.EndpointsID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testPublicIPv4PoolDataSourceConfig_basic, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet(dataSourceName, "total_address_count"), + resource.TestCheckResourceAttrSet(dataSourceName, "total_available_address_count"), + ), + }, + }, + }) +} + +func testAccPreCheckPublicIPv4Pools(ctx context.Context, t *testing.T) { + conn := acctest.Provider.Meta().(*conns.AWSClient).EC2Conn() + + output, err := tfec2.FindPublicIPv4Pools(ctx, conn, &ec2.DescribePublicIpv4PoolsInput{}) + + if acctest.PreCheckSkipError(err) { + t.Skipf("skipping acceptance testing: %s", err) + } + + if err != nil { + t.Fatalf("unexpected PreCheck error: %s", err) + } + + // Ensure there is at least one pool. + if len(output) == 0 { + t.Skip("skipping since no EC2 Public IPv4 Pools found") + } +} + +const testPublicIPv4PoolDataSourceConfig_basic = ` +data "aws_vpc_public_ipv4_pools" "test" {} + +data "aws_vpc_public_ipv4_pool" "test" { + pool_id = data.aws_vpc_public_ipv4_pools.test.pool_ids[0] +} +` From f7d36e91e7892fb58440461eef617e565b8e67ec Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 14 Mar 2023 08:40:01 -0400 Subject: [PATCH 13/20] 'aws_vpc_public_ipv4_pools' -> 'aws_ec2_public_ipv4_pools'. --- .changelog/28245.txt | 2 +- ...ource.go => ec2_public_ipv4_pools_data_source.go} | 2 +- ....go => ec2_public_ipv4_pools_data_source_test.go} | 8 ++++---- .../service/ec2/public_ipv4_pool_data_source_test.go | 4 ++-- internal/service/ec2/service_package_gen.go | 8 ++++---- ....markdown => ec2_public_ipv4_pools.html.markdown} | 12 ++++++------ 6 files changed, 18 insertions(+), 18 deletions(-) rename internal/service/ec2/{public_ipv4_pools_data_source.go => ec2_public_ipv4_pools_data_source.go} (97%) rename internal/service/ec2/{public_ipv4_pools_data_source_test.go => ec2_public_ipv4_pools_data_source_test.go} (89%) rename website/docs/d/{public_ipv4_pools.html.markdown => ec2_public_ipv4_pools.html.markdown} (72%) diff --git a/.changelog/28245.txt b/.changelog/28245.txt index 3679718020e..f8c3c012148 100644 --- a/.changelog/28245.txt +++ b/.changelog/28245.txt @@ -1,5 +1,5 @@ ```release-note:new-data-source -aws_vpc_public_ipv4_pools +aws_ec2_public_ipv4_pools ``` ```release-note:new-data-source diff --git a/internal/service/ec2/public_ipv4_pools_data_source.go b/internal/service/ec2/ec2_public_ipv4_pools_data_source.go similarity index 97% rename from internal/service/ec2/public_ipv4_pools_data_source.go rename to internal/service/ec2/ec2_public_ipv4_pools_data_source.go index ee4d0d09e58..f5cf7cb8f65 100644 --- a/internal/service/ec2/public_ipv4_pools_data_source.go +++ b/internal/service/ec2/ec2_public_ipv4_pools_data_source.go @@ -12,7 +12,7 @@ import ( tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" ) -// @SDKDataSource("aws_vpc_public_ipv4_pools") +// @SDKDataSource("aws_ec2_public_ipv4_pools") func DataSourcePublicIPv4Pools() *schema.Resource { return &schema.Resource{ ReadWithoutTimeout: dataSourcePublicIpv4PoolsRead, diff --git a/internal/service/ec2/public_ipv4_pools_data_source_test.go b/internal/service/ec2/ec2_public_ipv4_pools_data_source_test.go similarity index 89% rename from internal/service/ec2/public_ipv4_pools_data_source_test.go rename to internal/service/ec2/ec2_public_ipv4_pools_data_source_test.go index 8f2f8de124e..8ae2ee7c74e 100644 --- a/internal/service/ec2/public_ipv4_pools_data_source_test.go +++ b/internal/service/ec2/ec2_public_ipv4_pools_data_source_test.go @@ -12,7 +12,7 @@ import ( func TestAccEC2PublicIPv4PoolsDataSource_basic(t *testing.T) { ctx := acctest.Context(t) - dataSourceName := "data.aws_vpc_public_ipv4_pools.test" + dataSourceName := "data.aws_ec2_public_ipv4_pools.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) }, @@ -31,7 +31,7 @@ func TestAccEC2PublicIPv4PoolsDataSource_basic(t *testing.T) { func TestAccEC2PublicIPv4PoolsDataSource_tags(t *testing.T) { ctx := acctest.Context(t) - dataSourceName := "data.aws_vpc_public_ipv4_pools.test" + dataSourceName := "data.aws_ec2_public_ipv4_pools.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resource.ParallelTest(t, resource.TestCase{ @@ -50,12 +50,12 @@ func TestAccEC2PublicIPv4PoolsDataSource_tags(t *testing.T) { } const testPublicIPv4PoolsDataSourceConfig_basic = ` -data "aws_vpc_public_ipv4_pools" "test" {} +data "aws_ec2_public_ipv4_pools" "test" {} ` func testPublicIPv4PoolsDataSourceConfig_tags(rName string) string { return fmt.Sprintf(` -data "aws_vpc_public_ipv4_pools" "test" { +data "aws_ec2_public_ipv4_pools" "test" { tags = { Name = %[1]q } diff --git a/internal/service/ec2/public_ipv4_pool_data_source_test.go b/internal/service/ec2/public_ipv4_pool_data_source_test.go index 18815263d35..aa89e8f0d94 100644 --- a/internal/service/ec2/public_ipv4_pool_data_source_test.go +++ b/internal/service/ec2/public_ipv4_pool_data_source_test.go @@ -51,9 +51,9 @@ func testAccPreCheckPublicIPv4Pools(ctx context.Context, t *testing.T) { } const testPublicIPv4PoolDataSourceConfig_basic = ` -data "aws_vpc_public_ipv4_pools" "test" {} +data "aws_ec2_public_ipv4_pools" "test" {} data "aws_vpc_public_ipv4_pool" "test" { - pool_id = data.aws_vpc_public_ipv4_pools.test.pool_ids[0] + pool_id = data.aws_ec2_public_ipv4_pools.test.pool_ids[0] } ` diff --git a/internal/service/ec2/service_package_gen.go b/internal/service/ec2/service_package_gen.go index 0e41645e9b4..9f1a9519352 100644 --- a/internal/service/ec2/service_package_gen.go +++ b/internal/service/ec2/service_package_gen.go @@ -155,6 +155,10 @@ func (p *servicePackage) SDKDataSources(ctx context.Context) []*types.ServicePac Factory: DataSourceNetworkInsightsPath, TypeName: "aws_ec2_network_insights_path", }, + { + Factory: DataSourcePublicIPv4Pools, + TypeName: "aws_ec2_public_ipv4_pools", + }, { Factory: DataSourceSerialConsoleAccess, TypeName: "aws_ec2_serial_console_access", @@ -339,10 +343,6 @@ func (p *servicePackage) SDKDataSources(ctx context.Context) []*types.ServicePac Factory: DataSourcePublicIPv4Pool, TypeName: "aws_vpc_public_ipv4_pool", }, - { - Factory: DataSourcePublicIPv4Pools, - TypeName: "aws_vpc_public_ipv4_pools", - }, { Factory: DataSourceVPCs, TypeName: "aws_vpcs", diff --git a/website/docs/d/public_ipv4_pools.html.markdown b/website/docs/d/ec2_public_ipv4_pools.html.markdown similarity index 72% rename from website/docs/d/public_ipv4_pools.html.markdown rename to website/docs/d/ec2_public_ipv4_pools.html.markdown index 149d986f4bd..1ba41450122 100644 --- a/website/docs/d/public_ipv4_pools.html.markdown +++ b/website/docs/d/ec2_public_ipv4_pools.html.markdown @@ -1,14 +1,14 @@ --- -subcategory: "VPC (Virtual Private Cloud)" +subcategory: "EC2 (Elastic Compute Cloud)" layout: "aws" -page_title: "AWS: aws_vpc_public_ipv4_pools" +page_title: "AWS: aws_ec2_public_ipv4_pools" description: |- - Terraform data source for getting information about AWS VPC (Virtual Private Cloud) Public IPv4 Pools. + Terraform data source for getting information about AWS EC2 Public IPv4 Pools. --- # Data Source: aws_ec2_public_ipv4_pools -Terraform data source for getting information about AWS VPC (Virtual Private Cloud) Public IPv4 Pools. +Terraform data source for getting information about AWS EC2 Public IPv4 Pools. ## Example Usage @@ -16,12 +16,12 @@ Terraform data source for getting information about AWS VPC (Virtual Private Clo ```terraform # Returns all public IPv4 pools. -data "aws_vpc_public_ipv4_pools" "example" {} +data "aws_ec2_public_ipv4_pools" "example" {} ``` ### Usage with Filter ```terraform -data "aws_vpc_public_ipv4_pools" "example" { +data "aws_ec2_public_ipv4_pools" "example" { filter { name = "tag-key" values = ["ExampleTagKey"] From 55775308cae5297e7c847ec96c0f6d088962c0f9 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 14 Mar 2023 08:43:59 -0400 Subject: [PATCH 14/20] 'aws_vpc_public_ipv4_pool' -> 'aws_ec2_public_ipv4_pool'. --- .changelog/28245.txt | 2 +- ...a_source.go => ec2_public_ipv4_pool_data_source.go} | 2 +- ...est.go => ec2_public_ipv4_pool_data_source_test.go} | 4 ++-- internal/service/ec2/service_package_gen.go | 8 ++++---- ...tml.markdown => ec2_public_ipv4_pool.html.markdown} | 10 +++++----- 5 files changed, 13 insertions(+), 13 deletions(-) rename internal/service/ec2/{public_ipv4_pool_data_source.go => ec2_public_ipv4_pool_data_source.go} (98%) rename internal/service/ec2/{public_ipv4_pool_data_source_test.go => ec2_public_ipv4_pool_data_source_test.go} (94%) rename website/docs/d/{public_ipv4_pool.html.markdown => ec2_public_ipv4_pool.html.markdown} (79%) diff --git a/.changelog/28245.txt b/.changelog/28245.txt index f8c3c012148..58dc5465387 100644 --- a/.changelog/28245.txt +++ b/.changelog/28245.txt @@ -3,5 +3,5 @@ aws_ec2_public_ipv4_pools ``` ```release-note:new-data-source -aws_vpc_public_ipv4_pool +aws_ec2_public_ipv4_pool ``` \ No newline at end of file diff --git a/internal/service/ec2/public_ipv4_pool_data_source.go b/internal/service/ec2/ec2_public_ipv4_pool_data_source.go similarity index 98% rename from internal/service/ec2/public_ipv4_pool_data_source.go rename to internal/service/ec2/ec2_public_ipv4_pool_data_source.go index f8e2afb6bcb..b3a46bd2eae 100644 --- a/internal/service/ec2/public_ipv4_pool_data_source.go +++ b/internal/service/ec2/ec2_public_ipv4_pool_data_source.go @@ -12,7 +12,7 @@ import ( tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" ) -// @SDKDataSource("aws_vpc_public_ipv4_pool") +// @SDKDataSource("aws_ec2_public_ipv4_pool") func DataSourcePublicIPv4Pool() *schema.Resource { return &schema.Resource{ ReadWithoutTimeout: dataSourcePublicIpv4PoolRead, diff --git a/internal/service/ec2/public_ipv4_pool_data_source_test.go b/internal/service/ec2/ec2_public_ipv4_pool_data_source_test.go similarity index 94% rename from internal/service/ec2/public_ipv4_pool_data_source_test.go rename to internal/service/ec2/ec2_public_ipv4_pool_data_source_test.go index aa89e8f0d94..95039a4c65a 100644 --- a/internal/service/ec2/public_ipv4_pool_data_source_test.go +++ b/internal/service/ec2/ec2_public_ipv4_pool_data_source_test.go @@ -13,7 +13,7 @@ import ( func TestAccEC2PublicIPv4PoolDataSource_basic(t *testing.T) { ctx := acctest.Context(t) - dataSourceName := "data.aws_vpc_public_ipv4_pool.test" + dataSourceName := "data.aws_ec2_public_ipv4_pool.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheckPublicIPv4Pools(ctx, t) }, @@ -53,7 +53,7 @@ func testAccPreCheckPublicIPv4Pools(ctx context.Context, t *testing.T) { const testPublicIPv4PoolDataSourceConfig_basic = ` data "aws_ec2_public_ipv4_pools" "test" {} -data "aws_vpc_public_ipv4_pool" "test" { +data "aws_ec2_public_ipv4_pool" "test" { pool_id = data.aws_ec2_public_ipv4_pools.test.pool_ids[0] } ` diff --git a/internal/service/ec2/service_package_gen.go b/internal/service/ec2/service_package_gen.go index 9f1a9519352..835f6a571d6 100644 --- a/internal/service/ec2/service_package_gen.go +++ b/internal/service/ec2/service_package_gen.go @@ -155,6 +155,10 @@ func (p *servicePackage) SDKDataSources(ctx context.Context) []*types.ServicePac Factory: DataSourceNetworkInsightsPath, TypeName: "aws_ec2_network_insights_path", }, + { + Factory: DataSourcePublicIPv4Pool, + TypeName: "aws_ec2_public_ipv4_pool", + }, { Factory: DataSourcePublicIPv4Pools, TypeName: "aws_ec2_public_ipv4_pools", @@ -339,10 +343,6 @@ func (p *servicePackage) SDKDataSources(ctx context.Context) []*types.ServicePac Factory: DataSourceVPCPeeringConnections, TypeName: "aws_vpc_peering_connections", }, - { - Factory: DataSourcePublicIPv4Pool, - TypeName: "aws_vpc_public_ipv4_pool", - }, { Factory: DataSourceVPCs, TypeName: "aws_vpcs", diff --git a/website/docs/d/public_ipv4_pool.html.markdown b/website/docs/d/ec2_public_ipv4_pool.html.markdown similarity index 79% rename from website/docs/d/public_ipv4_pool.html.markdown rename to website/docs/d/ec2_public_ipv4_pool.html.markdown index 8674dca7cef..09805cf1b5c 100644 --- a/website/docs/d/public_ipv4_pool.html.markdown +++ b/website/docs/d/ec2_public_ipv4_pool.html.markdown @@ -1,21 +1,21 @@ --- -subcategory: "VPC (Virtual Private Cloud)" +subcategory: "EC2 (Elastic Compute Cloud)" layout: "aws" -page_title: "AWS: aws_vpc_public_ipv4_pool" +page_title: "AWS: aws_ec2_public_ipv4_pool" description: |- - Provides details about a specific AWS VPC (Virtual Private Cloud) Public IPv4 Pool. + Provides details about a specific AWS EC2 Public IPv4 Pool. --- # Data Source: aws_ec2_public_ipv4_pool -Provides details about a specific AWS VPC (Virtual Private Cloud) Public IPv4 Pool. +Provides details about a specific AWS EC2 Public IPv4 Pool. ## Example Usage ### Basic Usage ```terraform -data "aws_vpc_public_ipv4_pool" "example" { +data "aws_ec2_public_ipv4_pool" "example" { pool_id = "ipv4pool-ec2-000df99cff0c1ec10" } ``` From a27be32bebc9d1e6aace31ce1ba53a378bc0fcda Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 14 Mar 2023 08:51:48 -0400 Subject: [PATCH 15/20] Fix semgrep 'ci.semgrep.migrate.aws-api-context'. --- internal/service/ec2/find.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/service/ec2/find.go b/internal/service/ec2/find.go index 1be25c959e7..2373b2a325b 100644 --- a/internal/service/ec2/find.go +++ b/internal/service/ec2/find.go @@ -1278,7 +1278,7 @@ func FindPublicIPv4Pool(ctx context.Context, conn *ec2.EC2, input *ec2.DescribeP func FindPublicIPv4Pools(ctx context.Context, conn *ec2.EC2, input *ec2.DescribePublicIpv4PoolsInput) ([]*ec2.PublicIpv4Pool, error) { var output []*ec2.PublicIpv4Pool - err := conn.DescribePublicIpv4PoolsPages(input, func(page *ec2.DescribePublicIpv4PoolsOutput, lastPage bool) bool { + err := conn.DescribePublicIpv4PoolsPagesWithContext(ctx, input, func(page *ec2.DescribePublicIpv4PoolsOutput, lastPage bool) bool { if page == nil { return !lastPage } From a907712b0a6035e6790af2da4b6734cf0b6e7393 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 14 Mar 2023 08:53:56 -0400 Subject: [PATCH 16/20] Fix semgrep 'ci.caps5-in-func-name'. --- .../service/ec2/ec2_public_ipv4_pool_data_source.go | 12 ++++++------ .../service/ec2/ec2_public_ipv4_pools_data_source.go | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/internal/service/ec2/ec2_public_ipv4_pool_data_source.go b/internal/service/ec2/ec2_public_ipv4_pool_data_source.go index b3a46bd2eae..4099b783dd8 100644 --- a/internal/service/ec2/ec2_public_ipv4_pool_data_source.go +++ b/internal/service/ec2/ec2_public_ipv4_pool_data_source.go @@ -15,7 +15,7 @@ import ( // @SDKDataSource("aws_ec2_public_ipv4_pool") func DataSourcePublicIPv4Pool() *schema.Resource { return &schema.Resource{ - ReadWithoutTimeout: dataSourcePublicIpv4PoolRead, + ReadWithoutTimeout: dataSourcePublicIPv4PoolRead, Schema: map[string]*schema.Schema{ "description": { @@ -67,7 +67,7 @@ func DataSourcePublicIPv4Pool() *schema.Resource { } } -func dataSourcePublicIpv4PoolRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func dataSourcePublicIPv4PoolRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics conn := meta.(*conns.AWSClient).EC2Conn() ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig @@ -82,7 +82,7 @@ func dataSourcePublicIpv4PoolRead(ctx context.Context, d *schema.ResourceData, m d.SetId(poolID) d.Set("description", pool.Description) d.Set("network_border_group", pool.NetworkBorderGroup) - if err := d.Set("pool_address_ranges", flattenPublicIpv4PoolRanges(pool.PoolAddressRanges)); err != nil { + if err := d.Set("pool_address_ranges", flattenPublicIPv4PoolRanges(pool.PoolAddressRanges)); err != nil { return sdkdiag.AppendErrorf(diags, "setting pool_address_ranges: %s", err) } if err := d.Set("tags", KeyValueTags(ctx, pool.Tags).IgnoreAWS().IgnoreConfig(ignoreTagsConfig).Map()); err != nil { @@ -94,7 +94,7 @@ func dataSourcePublicIpv4PoolRead(ctx context.Context, d *schema.ResourceData, m return nil } -func flattenPublicIpv4PoolRange(apiObject *ec2.PublicIpv4PoolRange) map[string]interface{} { +func flattenPublicIPv4PoolRange(apiObject *ec2.PublicIpv4PoolRange) map[string]interface{} { if apiObject == nil { return nil } @@ -120,7 +120,7 @@ func flattenPublicIpv4PoolRange(apiObject *ec2.PublicIpv4PoolRange) map[string]i return tfMap } -func flattenPublicIpv4PoolRanges(apiObjects []*ec2.PublicIpv4PoolRange) []interface{} { +func flattenPublicIPv4PoolRanges(apiObjects []*ec2.PublicIpv4PoolRange) []interface{} { if len(apiObjects) == 0 { return nil } @@ -132,7 +132,7 @@ func flattenPublicIpv4PoolRanges(apiObjects []*ec2.PublicIpv4PoolRange) []interf continue } - tfList = append(tfList, flattenPublicIpv4PoolRange(apiObject)) + tfList = append(tfList, flattenPublicIPv4PoolRange(apiObject)) } return tfList diff --git a/internal/service/ec2/ec2_public_ipv4_pools_data_source.go b/internal/service/ec2/ec2_public_ipv4_pools_data_source.go index f5cf7cb8f65..712f6adb2d3 100644 --- a/internal/service/ec2/ec2_public_ipv4_pools_data_source.go +++ b/internal/service/ec2/ec2_public_ipv4_pools_data_source.go @@ -15,7 +15,7 @@ import ( // @SDKDataSource("aws_ec2_public_ipv4_pools") func DataSourcePublicIPv4Pools() *schema.Resource { return &schema.Resource{ - ReadWithoutTimeout: dataSourcePublicIpv4PoolsRead, + ReadWithoutTimeout: dataSourcePublicIPv4PoolsRead, Schema: map[string]*schema.Schema{ "filter": DataSourceFiltersSchema(), @@ -29,7 +29,7 @@ func DataSourcePublicIPv4Pools() *schema.Resource { } } -func dataSourcePublicIpv4PoolsRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func dataSourcePublicIPv4PoolsRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics conn := meta.(*conns.AWSClient).EC2Conn() From 5f8e886ebc0ccbb5cfcdd042ee5f3cb646223cd4 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 14 Mar 2023 08:55:21 -0400 Subject: [PATCH 17/20] Fix markdown-lint 'MD007/ul-indent Unordered list indentation [Expected: 4; Actual: 2]'. --- website/docs/d/ec2_public_ipv4_pool.html.markdown | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/website/docs/d/ec2_public_ipv4_pool.html.markdown b/website/docs/d/ec2_public_ipv4_pool.html.markdown index 09805cf1b5c..f62cf07d828 100644 --- a/website/docs/d/ec2_public_ipv4_pool.html.markdown +++ b/website/docs/d/ec2_public_ipv4_pool.html.markdown @@ -33,10 +33,10 @@ In addition to all arguments above, the following attributes are exported: * `description` - Description of the pool, if any. * `network_border_group` - Name of the location from which the address pool is advertised. * pool_address_ranges` - List of Address Ranges in the Pool; each address range record contains: - * `address_count` - Number of addresses in the range. - * `available_address_count` - Number of available addresses in the range. - * `first_address` - First address in the range. - * `last_address` - Last address in the range. + * `address_count` - Number of addresses in the range. + * `available_address_count` - Number of available addresses in the range. + * `first_address` - First address in the range. + * `last_address` - Last address in the range. * `tags` - Any tags for the address pool. * `total_address_count` - Total number of addresses in the pool. * `total_available_address_count` - Total number of available addresses in the pool. From ece0ecf56213468cdb6fcefac2cc42b93b86f569 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 14 Mar 2023 08:56:20 -0400 Subject: [PATCH 18/20] Fix markdown-lint 'MD031/blanks-around-fences Fenced code blocks should be surrounded by blank lines'. --- website/docs/d/ec2_public_ipv4_pools.html.markdown | 1 + 1 file changed, 1 insertion(+) diff --git a/website/docs/d/ec2_public_ipv4_pools.html.markdown b/website/docs/d/ec2_public_ipv4_pools.html.markdown index 1ba41450122..409453dffce 100644 --- a/website/docs/d/ec2_public_ipv4_pools.html.markdown +++ b/website/docs/d/ec2_public_ipv4_pools.html.markdown @@ -20,6 +20,7 @@ data "aws_ec2_public_ipv4_pools" "example" {} ``` ### Usage with Filter + ```terraform data "aws_ec2_public_ipv4_pools" "example" { filter { From 2635c246e0d37ac1bf882ab6a33b8893cf7b3a2d Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 14 Mar 2023 09:23:44 -0400 Subject: [PATCH 19/20] Fix semgrep 'ci.caps5-in-const-name' and 'ci.caps5-in-var-name'. --- internal/service/ec2/errors.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/service/ec2/errors.go b/internal/service/ec2/errors.go index 6bc6924688f..ef94bfc8167 100644 --- a/internal/service/ec2/errors.go +++ b/internal/service/ec2/errors.go @@ -68,7 +68,7 @@ const ( errCodeInvalidPoolIDNotFound = "InvalidPoolID.NotFound" errCodeInvalidPrefixListIDNotFound = "InvalidPrefixListID.NotFound" errCodeInvalidPrefixListIdNotFound = "InvalidPrefixListId.NotFound" - errCodeInvalidPublicIpv4PoolIDNotFound = "InvalidPublicIpv4PoolID.NotFound" + errCodeInvalidPublicIpv4PoolIDNotFound = "InvalidPublicIpv4PoolID.NotFound" // nosemgrep:ci.caps5-in-const-name,ci.caps5-in-var-name errCodeInvalidRouteNotFound = "InvalidRoute.NotFound" errCodeInvalidRouteTableIDNotFound = "InvalidRouteTableID.NotFound" errCodeInvalidRouteTableIdNotFound = "InvalidRouteTableId.NotFound" From 9d7a4532c955232c918ab96d52d29f9546ba32fd Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 14 Mar 2023 09:41:35 -0400 Subject: [PATCH 20/20] Add prefix for EC2 Public IPv4 Pools. --- .github/labeler-issue-triage.yml | 2 +- .github/labeler-pr-triage.yml | 1 + names/names_data.csv | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/labeler-issue-triage.yml b/.github/labeler-issue-triage.yml index 30c412c73bb..5d9d2cfaa5e 100644 --- a/.github/labeler-issue-triage.yml +++ b/.github/labeler-issue-triage.yml @@ -206,7 +206,7 @@ service/dynamodbstreams: service/ebs: - '((\*|-)\s*`?|(data|resource)\s+"?)aws_ebs_' service/ec2: - - '((\*|-)\s*`?|(data|resource)\s+"?)aws_(ami|availability_zone|ec2_(availability|capacity|fleet|host|instance|serial|spot|tag)|eip|instance|key_pair|launch_template|placement_group|spot)' + - '((\*|-)\s*`?|(data|resource)\s+"?)aws_(ami|availability_zone|ec2_(availability|capacity|fleet|host|instance|public_ipv4_pool|serial|spot|tag)|eip|instance|key_pair|launch_template|placement_group|spot)' service/ec2ebs: - '((\*|-)\s*`?|(data|resource)\s+"?)aws_(ebs_|volume_attach|snapshot_create)' service/ec2instanceconnect: diff --git a/.github/labeler-pr-triage.yml b/.github/labeler-pr-triage.yml index 3f64aaf3729..9d842fb7884 100644 --- a/.github/labeler-pr-triage.yml +++ b/.github/labeler-pr-triage.yml @@ -346,6 +346,7 @@ service/ec2: - 'website/**/ec2_fleet*' - 'website/**/ec2_host*' - 'website/**/ec2_instance_*' + - 'website/**/ec2_public_ipv4_pool*' - 'website/**/ec2_serial_*' - 'website/**/ec2_spot_*' - 'website/**/ec2_tag*' diff --git a/names/names_data.csv b/names/names_data.csv index 8da7cbcbb07..ef2b193f3d9 100644 --- a/names/names_data.csv +++ b/names/names_data.csv @@ -117,7 +117,7 @@ dax,dax,dax,dax,,dax,,,DAX,DAX,,1,,,aws_dax_,,dax_,DynamoDB Accelerator (DAX),Am dynamodbstreams,dynamodbstreams,dynamodbstreams,dynamodbstreams,,dynamodbstreams,,,DynamoDBStreams,DynamoDBStreams,,1,,,aws_dynamodbstreams_,,dynamodbstreams_,DynamoDB Streams,Amazon,,,,, ,,,,,ec2ebs,ec2,,EC2EBS,,,,,aws_(ebs_|volume_attach|snapshot_create),aws_ec2ebs_,ebs_,ebs_;volume_attachment;snapshot_,EBS (EC2),Amazon,x,x,,,Part of EC2 ebs,ebs,ebs,ebs,,ebs,,,EBS,EBS,,1,,,aws_ebs_,,changewhenimplemented,EBS (Elastic Block Store),Amazon,,,,, -ec2,ec2,ec2,ec2,,ec2,ec2,,EC2,EC2,,1,2,aws_(ami|availability_zone|ec2_(availability|capacity|fleet|host|instance|serial|spot|tag)|eip|instance|key_pair|launch_template|placement_group|spot),aws_ec2_,ec2_,ami;availability_zone;ec2_availability_;ec2_capacity_;ec2_fleet;ec2_host;ec2_instance_;ec2_serial_;ec2_spot_;ec2_tag;eip;instance;key_pair;launch_template;placement_group;spot_,EC2 (Elastic Compute Cloud),Amazon,,,,, +ec2,ec2,ec2,ec2,,ec2,ec2,,EC2,EC2,,1,2,aws_(ami|availability_zone|ec2_(availability|capacity|fleet|host|instance|public_ipv4_pool|serial|spot|tag)|eip|instance|key_pair|launch_template|placement_group|spot),aws_ec2_,ec2_,ami;availability_zone;ec2_availability_;ec2_capacity_;ec2_fleet;ec2_host;ec2_instance_;ec2_public_ipv4_pool;ec2_serial_;ec2_spot_;ec2_tag;eip;instance;key_pair;launch_template;placement_group;spot_,EC2 (Elastic Compute Cloud),Amazon,,,,, imagebuilder,imagebuilder,imagebuilder,imagebuilder,,imagebuilder,,,ImageBuilder,Imagebuilder,,1,,,aws_imagebuilder_,,imagebuilder_,EC2 Image Builder,Amazon,,,,, ec2-instance-connect,ec2instanceconnect,ec2instanceconnect,ec2instanceconnect,,ec2instanceconnect,,,EC2InstanceConnect,EC2InstanceConnect,,1,,,aws_ec2instanceconnect_,,ec2instanceconnect_,EC2 Instance Connect,AWS,,,,, ecr,ecr,ecr,ecr,,ecr,,,ECR,ECR,,1,,,aws_ecr_,,ecr_,ECR (Elastic Container Registry),Amazon,,,,,