Skip to content

Commit

Permalink
ec2-route-tables filter Main
Browse files Browse the repository at this point in the history
use `Filter` instead of custom method
  • Loading branch information
leighpascoe authored and bjoernhaeuser committed Aug 15, 2023
1 parent c51bb62 commit ae6bd3c
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions resources/ec2-route-tables.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package resources

import (
"fmt"

"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/rebuy-de/aws-nuke/v2/pkg/types"
log "github.com/sirupsen/logrus"
)

type EC2RouteTable struct {
Expand Down Expand Up @@ -32,14 +33,6 @@ func ListEC2RouteTables(sess *session.Session) ([]Resource, error) {

resources := make([]Resource, 0)
for _, out := range resp.RouteTables {

if IsMain(out) {
log.WithFields(log.Fields{
"routetable": *out.RouteTableId,
}).Debug("Main RouteTables cannot be deleted, skipping RouteTable: routetable")
continue
}

resources = append(resources, &EC2RouteTable{
svc: svc,
routeTable: out,
Expand All @@ -50,13 +43,14 @@ func ListEC2RouteTables(sess *session.Session) ([]Resource, error) {
return resources, nil
}

func IsMain(e *ec2.RouteTable) bool {
for _, association := range e.Associations {
func (i *EC2RouteTable) Filter() error {

for _, association := range i.routeTable.Associations {
if *association.Main {
return true
return fmt.Errorf("Main RouteTables cannot be deleted")
}
}
return false
return nil
}

func (e *EC2RouteTable) Remove() error {
Expand Down

0 comments on commit ae6bd3c

Please sign in to comment.