Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/46918.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
Add support for `ipv6_cidr_block_associations` to the `aws_ec2_vpc` data source.
```
70 changes: 66 additions & 4 deletions internal/service/ec2/vpc_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
},
},
Expand Down Expand Up @@ -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{
Copy link
Contributor Author

@danquack danquack Mar 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's more fields, but I grabbed a copy of ipv4 associations to align. Notably missing:Attributes

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,
Expand Down Expand Up @@ -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)
Expand Down
47 changes: 47 additions & 0 deletions internal/service/ec2/vpc_data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down Expand Up @@ -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)
}
Loading