Skip to content

Commit e6a5d50

Browse files
ekristencorybekk
authored andcommitted
fix(ec2-ip): include network border group if set during remove
1 parent fad517c commit e6a5d50

File tree

1 file changed

+17
-22
lines changed

1 file changed

+17
-22
lines changed

resources/ec2-eip.go

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ package resources
33
import (
44
"context"
55

6-
"github.com/gotidy/ptr"
7-
86
"github.com/aws/aws-sdk-go/service/ec2"
97

108
"github.com/ekristen/libnuke/pkg/registry"
@@ -40,26 +38,28 @@ func (l *EC2AddressLister) List(_ context.Context, o interface{}) ([]resource.Re
4038
resources := make([]resource.Resource, 0)
4139
for _, out := range resp.Addresses {
4240
resources = append(resources, &EC2Address{
43-
svc: svc,
44-
eip: out,
45-
id: ptr.ToString(out.AllocationId),
46-
ip: ptr.ToString(out.PublicIp),
41+
svc: svc,
42+
AllocationID: out.AllocationId,
43+
PublicIP: out.PublicIp,
44+
Tags: out.Tags,
4745
})
4846
}
4947

5048
return resources, nil
5149
}
5250

5351
type EC2Address struct {
54-
svc *ec2.EC2
55-
eip *ec2.Address
56-
id string
57-
ip string
52+
svc *ec2.EC2
53+
AllocationID *string
54+
PublicIP *string
55+
NetworkBorderGroup *string
56+
Tags []*ec2.Tag
5857
}
5958

60-
func (e *EC2Address) Remove(_ context.Context) error {
61-
_, err := e.svc.ReleaseAddress(&ec2.ReleaseAddressInput{
62-
AllocationId: &e.id,
59+
func (r *EC2Address) Remove(_ context.Context) error {
60+
_, err := r.svc.ReleaseAddress(&ec2.ReleaseAddressInput{
61+
AllocationId: r.AllocationID,
62+
NetworkBorderGroup: r.NetworkBorderGroup,
6363
})
6464
if err != nil {
6565
return err
@@ -68,15 +68,10 @@ func (e *EC2Address) Remove(_ context.Context) error {
6868
return nil
6969
}
7070

71-
func (e *EC2Address) Properties() types.Properties {
72-
properties := types.NewProperties()
73-
for _, tagValue := range e.eip.Tags {
74-
properties.SetTag(tagValue.Key, tagValue.Value)
75-
}
76-
properties.Set("AllocationID", e.id)
77-
return properties
71+
func (r *EC2Address) Properties() types.Properties {
72+
return types.NewPropertiesFromStruct(r)
7873
}
7974

80-
func (e *EC2Address) String() string {
81-
return e.ip
75+
func (r *EC2Address) String() string {
76+
return *r.PublicIP
8277
}

0 commit comments

Comments
 (0)