Skip to content

Commit 616f77d

Browse files
feat: add the ability to filter pn per vpc_id (#2357)
1 parent c7d4c41 commit 616f77d

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

scaleway/data_source_vpc_private_network.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,19 @@ func dataSourceScalewayVPCPrivateNetwork() *schema.Resource {
1717
addOptionalFieldsToSchema(dsSchema, "name", "project_id")
1818

1919
dsSchema["name"].ConflictsWith = []string{"private_network_id"}
20+
dsSchema["vpc_id"] = &schema.Schema{
21+
Type: schema.TypeString,
22+
Optional: true,
23+
Description: "The ID of the vpc to which the private network belongs to",
24+
ValidateFunc: validationUUIDorUUIDWithLocality(),
25+
ConflictsWith: []string{"private_network_id"},
26+
}
2027
dsSchema["private_network_id"] = &schema.Schema{
2128
Type: schema.TypeString,
2229
Optional: true,
2330
Description: "The ID of the private network",
2431
ValidateFunc: validationUUIDorUUIDWithLocality(),
25-
ConflictsWith: []string{"name"},
32+
ConflictsWith: []string{"name", "vpc_id"},
2633
}
2734

2835
return &schema.Resource{
@@ -50,9 +57,11 @@ func dataSourceScalewayVPCPrivateNetworkRead(ctx context.Context, d *schema.Reso
5057
return diag.FromErr(err)
5158
}
5259

60+
vpcID, hasVpcIDFilter := d.GetOk("vpc_id")
61+
5362
foundPN, err := findExact(
5463
res.PrivateNetworks,
55-
func(s *vpc.PrivateNetwork) bool { return s.Name == pnName },
64+
func(s *vpc.PrivateNetwork) bool { return s.Name == pnName && (!hasVpcIDFilter || s.VpcID == vpcID) },
5665
pnName,
5766
)
5867
if err != nil {

0 commit comments

Comments
 (0)