Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
olasaadi99 committed Nov 21, 2024
1 parent 4ddb680 commit 8473966
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
17 changes: 14 additions & 3 deletions pkg/vpcmodel/subnetsConnectivity.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,21 @@ func updateSubnetsConnectivityByTransitGateway(src, dst VPCResourceIntf,
c *VPCConfig) (
*netset.TransportSet, error) {
// assuming a single router representing the tgw for a "MultipleVPCsConfig"
if len(c.RoutingResources) != 2 { // expecting tgw and sgw (virtual gateway)
return nil, fmt.Errorf("unexpected number of RoutingResources for MultipleVPCsConfig, expecting only TGW")
resourceTypeTGW := "TGW"
var tgw RoutingResource
tgwRouterFound := false
for _, router := range c.RoutingResources {
if router.Kind() == resourceTypeTGW {
if tgwRouterFound {
return nil, fmt.Errorf("unexpected number of RoutingResources for MultipleVPCsConfig, expecting only one TGW")
}
tgw = router
tgwRouterFound = true
}
}
if !tgwRouterFound {
return nil, fmt.Errorf("unexpected number of RoutingResources for MultipleVPCsConfig, expecting TGW")
}
tgw := c.RoutingResources[0]
connections, err := tgw.AllowedConnectivity(src, dst)
if err != nil {
return nil, err
Expand Down
18 changes: 14 additions & 4 deletions pkg/vpcmodel/textOutput.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,21 @@ type TextOutputFormatter struct {
}

func multipleVPCsConfigHeader(c *VPCConfig) (string, error) {
if len(c.RoutingResources) != 2 { // expecting tgw and sgw (virtual gateway)
fmt.Printf("c.RoutingResources: %v\n", c.RoutingResources)
return "", errors.New("unexpected config of multiple VPCs connected by TGW, missing TGW resource")
resourceTypeTGW := "TGW"
var tgw RoutingResource
tgwRouterFound := false
for _, router := range c.RoutingResources {
if router.Kind() == resourceTypeTGW {
if tgwRouterFound {
return "", errors.New("unexpected number of RoutingResources for MultipleVPCsConfig, expecting only one TGW")
}
tgw = router
tgwRouterFound = true
}
}
if !tgwRouterFound {
return "", errors.New("unexpected number of RoutingResources for MultipleVPCsConfig, expecting TGW")
}
tgw := c.RoutingResources[0]
return fmt.Sprintf("Connectivity between VPCs connected by TGW %s (UID: %s)\n", tgw.NameForAnalyzerOut(c), tgw.UID()), nil
}

Expand Down

0 comments on commit 8473966

Please sign in to comment.