Skip to content

Commit

Permalink
feat(ec2-subnet): filter shared resources
Browse files Browse the repository at this point in the history
  • Loading branch information
ekristen committed Jan 31, 2025
1 parent 689f7ec commit f0dbc27
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions resources/ec2-subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package resources

import (
"context"
"errors"

"github.com/gotidy/ptr"

"github.com/aws/aws-sdk-go/service/ec2"

Expand All @@ -28,6 +31,7 @@ func init() {

type EC2Subnet struct {
svc *ec2.EC2
accountID *string
subnet *ec2.Subnet
defaultVPC bool
}
Expand All @@ -54,6 +58,7 @@ func (l *EC2SubnetLister) List(_ context.Context, o interface{}) ([]resource.Res
for _, out := range resp.Subnets {
resources = append(resources, &EC2Subnet{
svc: svc,
accountID: opts.AccountID,
subnet: out,
defaultVPC: defVpcID == *out.VpcId,
})
Expand All @@ -62,6 +67,14 @@ func (l *EC2SubnetLister) List(_ context.Context, o interface{}) ([]resource.Res
return resources, nil
}

func (r *EC2Subnet) Filter() error {
if ptr.ToString(r.subnet.OwnerId) != ptr.ToString(r.accountID) {
return errors.New("not owned by account, likely shared")
}

return nil
}

func (r *EC2Subnet) Remove(_ context.Context) error {
params := &ec2.DeleteSubnetInput{
SubnetId: r.subnet.SubnetId,
Expand Down

0 comments on commit f0dbc27

Please sign in to comment.