diff --git a/.changelog/46918.txt b/.changelog/46918.txt new file mode 100644 index 000000000000..332242c22a65 --- /dev/null +++ b/.changelog/46918.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +Add support for `ipv6_cidr_block_associations` to the `aws_ec2_vpc` data source. +``` diff --git a/internal/service/ec2/vpc_data_source.go b/internal/service/ec2/vpc_data_source.go index fabe6bca01ae..3dd4ae4479d7 100644 --- a/internal/service/ec2/vpc_data_source.go +++ b/internal/service/ec2/vpc_data_source.go @@ -61,6 +61,18 @@ func dataSourceVPC() *schema.Resource { Type: schema.TypeString, Computed: true, }, + "network_border_group": { + Type: schema.TypeString, + Computed: true, + }, + "ipam_pool_id": { + Type: schema.TypeString, + Computed: true, + }, + names.AttrSource: { + Type: schema.TypeString, + Computed: true, + }, }, }, }, @@ -96,13 +108,47 @@ func dataSourceVPC() *schema.Resource { Type: schema.TypeString, Computed: true, }, - "ipv6_cidr_block": { - Type: schema.TypeString, + "ipv6_cidr_block_associations": { + Type: schema.TypeList, Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + names.AttrAssociationID: { + Type: schema.TypeString, + Computed: true, + }, + names.AttrCIDRBlock: { + Type: schema.TypeString, + Computed: true, + }, + names.AttrState: { + Type: schema.TypeString, + Computed: true, + }, + names.AttrSource: { + Type: schema.TypeString, + Computed: true, + }, + "network_border_group": { + Type: schema.TypeString, + Computed: true, + }, + "ipam_pool_id": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "ipv6_cidr_block": { + Type: schema.TypeString, + Deprecated: "ipv6_cidr_block is deprecated. It can be accessed in the first element of ipv6_cidr_block_associations instead.", + Computed: true, }, "ipv6_association_id": { - Type: schema.TypeString, - Computed: true, + Type: schema.TypeString, + Deprecated: "ipv6_association_id is deprecated. It can be accessed in the first element of ipv6_cidr_block_associations instead.", + Computed: true, }, "main_route_table_id": { Type: schema.TypeString, @@ -212,6 +258,22 @@ func dataSourceVPCRead(ctx context.Context, d *schema.ResourceData, meta any) di return sdkdiag.AppendErrorf(diags, "setting cidr_block_associations: %s", err) } + ipv6Associations := []any{} + for _, v := range vpc.Ipv6CidrBlockAssociationSet { + association := map[string]any{ + names.AttrAssociationID: aws.ToString(v.AssociationId), + names.AttrCIDRBlock: aws.ToString(v.Ipv6CidrBlock), + names.AttrState: aws.ToString(aws.String(string(v.Ipv6CidrBlockState.State))), + "network_border_group": aws.ToString(v.NetworkBorderGroup), + "ipam_pool_id": aws.ToString(v.Ipv6Pool), + names.AttrSource: aws.String(string(v.IpSource)), + } + ipv6Associations = append(ipv6Associations, association) + } + if err := d.Set("ipv6_cidr_block_associations", ipv6Associations); err != nil { + return sdkdiag.AppendErrorf(diags, "setting ipv6_cidr_block_associations: %s", err) + } + if len(vpc.Ipv6CidrBlockAssociationSet) > 0 { d.Set("ipv6_association_id", vpc.Ipv6CidrBlockAssociationSet[0].AssociationId) d.Set("ipv6_cidr_block", vpc.Ipv6CidrBlockAssociationSet[0].Ipv6CidrBlock) diff --git a/internal/service/ec2/vpc_data_source_test.go b/internal/service/ec2/vpc_data_source_test.go index 3f23729f8d7e..334257ea03e1 100644 --- a/internal/service/ec2/vpc_data_source_test.go +++ b/internal/service/ec2/vpc_data_source_test.go @@ -86,6 +86,27 @@ func TestAccVPCDataSource_CIDRBlockAssociations_multiple(t *testing.T) { }) } +func TestAccVPCDataSource_IPv6CIDRBlockAssociations_multiple(t *testing.T) { + ctx := acctest.Context(t) + dataSourceName := "data.aws_vpc.test" + rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) + + acctest.ParallelTest(ctx, t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.EC2ServiceID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckVPCDestroy(ctx, t), + Steps: []resource.TestStep{ + { + Config: testAccVPCDataSourceConfig_IPv6CIDRBlockAssociationsMultiple(rName), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(dataSourceName, "ipv6_cidr_block_associations.#", "2"), + ), + }, + }, + }) +} + func testAccVPCDataSourceConfig_basic(rName, cidr string) string { return fmt.Sprintf(` resource "aws_vpc" "test" { @@ -141,3 +162,29 @@ data "aws_vpc" "test" { } `, rName) } + +func testAccVPCDataSourceConfig_IPv6CIDRBlockAssociationsMultiple(rName string) string { + return fmt.Sprintf(` +resource "aws_vpc" "test" { + cidr_block = "10.0.0.0/16" + assign_generated_ipv6_cidr_block = true + + tags = { + Name = %[1]q + } +} + +resource "aws_vpc_ipv6_cidr_block_association" "test" { + vpc_id = aws_vpc.test.id + assign_generated_ipv6_cidr_block = true +} + + +data "aws_vpc" "test" { + depends_on = [ + aws_vpc_ipv6_cidr_block_association.test + ] + id = aws_vpc.test.id +} +`, rName) +}