Skip to content

Commit

Permalink
fix(ec2-ip): include network border group if set during remove
Browse files Browse the repository at this point in the history
  • Loading branch information
ekristen committed Oct 10, 2024
1 parent a48555b commit f0e3e7d
Showing 1 changed file with 17 additions and 22 deletions.
39 changes: 17 additions & 22 deletions resources/ec2-eip.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package resources
import (
"context"

"github.com/gotidy/ptr"

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

"github.com/ekristen/libnuke/pkg/registry"
Expand Down Expand Up @@ -40,26 +38,28 @@ func (l *EC2AddressLister) List(_ context.Context, o interface{}) ([]resource.Re
resources := make([]resource.Resource, 0)
for _, out := range resp.Addresses {
resources = append(resources, &EC2Address{
svc: svc,
eip: out,
id: ptr.ToString(out.AllocationId),
ip: ptr.ToString(out.PublicIp),
svc: svc,
AllocationID: out.AllocationId,
PublicIP: out.PublicIp,
Tags: out.Tags,
})
}

return resources, nil
}

type EC2Address struct {
svc *ec2.EC2
eip *ec2.Address
id string
ip string
svc *ec2.EC2
AllocationID *string
PublicIP *string
NetworkBorderGroup *string
Tags []*ec2.Tag
}

func (e *EC2Address) Remove(_ context.Context) error {
_, err := e.svc.ReleaseAddress(&ec2.ReleaseAddressInput{
AllocationId: &e.id,
func (r *EC2Address) Remove(_ context.Context) error {
_, err := r.svc.ReleaseAddress(&ec2.ReleaseAddressInput{
AllocationId: r.AllocationID,
NetworkBorderGroup: r.NetworkBorderGroup,
})
if err != nil {
return err
Expand All @@ -68,15 +68,10 @@ func (e *EC2Address) Remove(_ context.Context) error {
return nil
}

func (e *EC2Address) Properties() types.Properties {
properties := types.NewProperties()
for _, tagValue := range e.eip.Tags {
properties.SetTag(tagValue.Key, tagValue.Value)
}
properties.Set("AllocationID", e.id)
return properties
func (r *EC2Address) Properties() types.Properties {
return types.NewPropertiesFromStruct(r)
}

func (e *EC2Address) String() string {
return e.ip
func (r *EC2Address) String() string {
return *r.PublicIP
}

0 comments on commit f0e3e7d

Please sign in to comment.