forked from rebuy-de/aws-nuke
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ec2-eip.go
43 lines (35 loc) · 766 Bytes
/
ec2-eip.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package resources
import "github.com/aws/aws-sdk-go/service/ec2"
type EC2Address struct {
svc *ec2.EC2
id string
ip string
}
func (n *EC2Nuke) ListAddresses() ([]Resource, error) {
params := &ec2.DescribeAddressesInput{}
resp, err := n.Service.DescribeAddresses(params)
if err != nil {
return nil, err
}
resources := make([]Resource, 0)
for _, out := range resp.Addresses {
resources = append(resources, &EC2Address{
svc: n.Service,
id: *out.AllocationId,
ip: *out.PublicIp,
})
}
return resources, nil
}
func (e *EC2Address) Remove() error {
_, err := e.svc.ReleaseAddress(&ec2.ReleaseAddressInput{
AllocationId: &e.id,
})
if err != nil {
return err
}
return nil
}
func (e *EC2Address) String() string {
return e.ip
}