Skip to content

Commit 8473966

Browse files
committed
fix
1 parent 4ddb680 commit 8473966

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

pkg/vpcmodel/subnetsConnectivity.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,10 +241,21 @@ func updateSubnetsConnectivityByTransitGateway(src, dst VPCResourceIntf,
241241
c *VPCConfig) (
242242
*netset.TransportSet, error) {
243243
// assuming a single router representing the tgw for a "MultipleVPCsConfig"
244-
if len(c.RoutingResources) != 2 { // expecting tgw and sgw (virtual gateway)
245-
return nil, fmt.Errorf("unexpected number of RoutingResources for MultipleVPCsConfig, expecting only TGW")
244+
resourceTypeTGW := "TGW"
245+
var tgw RoutingResource
246+
tgwRouterFound := false
247+
for _, router := range c.RoutingResources {
248+
if router.Kind() == resourceTypeTGW {
249+
if tgwRouterFound {
250+
return nil, fmt.Errorf("unexpected number of RoutingResources for MultipleVPCsConfig, expecting only one TGW")
251+
}
252+
tgw = router
253+
tgwRouterFound = true
254+
}
255+
}
256+
if !tgwRouterFound {
257+
return nil, fmt.Errorf("unexpected number of RoutingResources for MultipleVPCsConfig, expecting TGW")
246258
}
247-
tgw := c.RoutingResources[0]
248259
connections, err := tgw.AllowedConnectivity(src, dst)
249260
if err != nil {
250261
return nil, err

pkg/vpcmodel/textOutput.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,21 @@ type TextOutputFormatter struct {
1515
}
1616

1717
func multipleVPCsConfigHeader(c *VPCConfig) (string, error) {
18-
if len(c.RoutingResources) != 2 { // expecting tgw and sgw (virtual gateway)
19-
fmt.Printf("c.RoutingResources: %v\n", c.RoutingResources)
20-
return "", errors.New("unexpected config of multiple VPCs connected by TGW, missing TGW resource")
18+
resourceTypeTGW := "TGW"
19+
var tgw RoutingResource
20+
tgwRouterFound := false
21+
for _, router := range c.RoutingResources {
22+
if router.Kind() == resourceTypeTGW {
23+
if tgwRouterFound {
24+
return "", errors.New("unexpected number of RoutingResources for MultipleVPCsConfig, expecting only one TGW")
25+
}
26+
tgw = router
27+
tgwRouterFound = true
28+
}
29+
}
30+
if !tgwRouterFound {
31+
return "", errors.New("unexpected number of RoutingResources for MultipleVPCsConfig, expecting TGW")
2132
}
22-
tgw := c.RoutingResources[0]
2333
return fmt.Sprintf("Connectivity between VPCs connected by TGW %s (UID: %s)\n", tgw.NameForAnalyzerOut(c), tgw.UID()), nil
2434
}
2535

0 commit comments

Comments
 (0)