-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvpcp.go
77 lines (59 loc) · 2.05 KB
/
vpcp.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
67
68
69
70
71
72
73
74
75
76
77
package window
import (
"time"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ec2"
)
type (
VPCPeeringConnection struct {
// The information of the peer VPC.
AccepterVpcInfo *ec2.VpcPeeringConnectionVpcInfo
// The time that an unaccepted VPC peering connection will expire.
ExpirationTime time.Time
// The information of the requester VPC.
RequesterVpcInfo *ec2.VpcPeeringConnectionVpcInfo
// The status of the VPC peering connection.
Status *ec2.VpcPeeringConnectionStateReason
// Any tags assigned to the resource.
Tags []*ec2.Tag
// The ID of the VPC peering connection.
VpcPeeringConnectionId string
Name string
Id string
State string
RequesterVPC *VPC
AccepterVPC *VPC
Subnets []*Subnet
}
VPCPeeringConnectionByNameAsc []*VPCPeeringConnection
)
func (a VPCPeeringConnectionByNameAsc) Len() int { return len(a) }
func (a VPCPeeringConnectionByNameAsc) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a VPCPeeringConnectionByNameAsc) Less(i, j int) bool {
return string_less_than(a[i].Name, a[j].Name)
}
func LoadVPCPeeringConnections(input *ec2.DescribeVpcPeeringConnectionsInput) (map[string]*VPCPeeringConnection, error) {
resp, err := EC2Client.DescribeVpcPeeringConnections(input)
if err != nil {
return nil, err
}
vpcps := make(map[string]*VPCPeeringConnection, len(resp.VpcPeeringConnections))
for _, vpcp := range resp.VpcPeeringConnections {
v := &VPCPeeringConnection{
AccepterVpcInfo: vpcp.AccepterVpcInfo,
ExpirationTime: aws.TimeValue(vpcp.ExpirationTime),
RequesterVpcInfo: vpcp.RequesterVpcInfo,
Status: vpcp.Status,
Tags: vpcp.Tags,
VpcPeeringConnectionId: aws.StringValue(vpcp.VpcPeeringConnectionId),
}
v.Name = TagOrDefault(v.Tags, "Name", v.VpcPeeringConnectionId)
v.Id = "vpcp:" + v.VpcPeeringConnectionId
v.State = aws.StringValue(v.Status.Code)
vpcps[v.VpcPeeringConnectionId] = v
}
return vpcps, nil
}
func (vpcp *VPCPeeringConnection) Inactive() bool {
return len(vpcp.Subnets) == 0
}