-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathig.go
66 lines (51 loc) · 1.47 KB
/
ig.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package window
import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ec2"
)
type (
InternetGateway struct {
Attachments []*ec2.InternetGatewayAttachment
// The ID of the Internet gateway.
InternetGatewayId string
// Any tags assigned to the Internet gateway.
Tags []*ec2.Tag
Name string
Id string
State string
VPCs []*VPC
}
InternetGatewayByNameAsc []*InternetGateway
)
func (a InternetGatewayByNameAsc) Len() int { return len(a) }
func (a InternetGatewayByNameAsc) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a InternetGatewayByNameAsc) Less(i, j int) bool {
return string_less_than(a[i].Name, a[j].Name)
}
func (igw *InternetGateway) String() string {
if igw != nil {
return igw.Name
}
return ""
}
func LoadInternetGateways(input *ec2.DescribeInternetGatewaysInput) (map[string]*InternetGateway, error) {
resp, err := EC2Client.DescribeInternetGateways(input)
if err != nil {
return nil, err
}
igs := make(map[string]*InternetGateway, len(resp.InternetGateways))
for _, ec2ig := range resp.InternetGateways {
ig := &InternetGateway{
Attachments: ec2ig.Attachments,
InternetGatewayId: aws.StringValue(ec2ig.InternetGatewayId),
Tags: ec2ig.Tags,
}
ig.Name = TagOrDefault(ig.Tags, "Name", ig.InternetGatewayId)
ig.Id = "igw:" + ig.InternetGatewayId
igs[ig.InternetGatewayId] = ig
}
return igs, nil
}
func (ig *InternetGateway) Inactive() bool {
return len(ig.Attachments) == 0
}