Skip to content

Commit 67d5450

Browse files
author
Jeff Carter
committed
add more ec2 resources
1 parent 1c99896 commit 67d5450

File tree

9 files changed

+324
-13
lines changed

9 files changed

+324
-13
lines changed

lister/ec2_customergateway.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package lister
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/aws/aws-sdk-go-v2/service/ec2"
7+
"github.com/trek10inc/awsets/option"
8+
"github.com/trek10inc/awsets/resource"
9+
)
10+
11+
type AWSEc2CustomerGateway struct {
12+
}
13+
14+
func init() {
15+
i := AWSEc2CustomerGateway{}
16+
listers = append(listers, i)
17+
}
18+
19+
func (l AWSEc2CustomerGateway) Types() []resource.ResourceType {
20+
return []resource.ResourceType{resource.Ec2CustomerGateway}
21+
}
22+
23+
func (l AWSEc2CustomerGateway) List(cfg option.AWSetsConfig) (*resource.Group, error) {
24+
svc := ec2.NewFromConfig(cfg.AWSCfg)
25+
26+
rg := resource.NewGroup()
27+
res, err := svc.DescribeCustomerGateways(cfg.Context, &ec2.DescribeCustomerGatewaysInput{})
28+
if err != nil {
29+
return nil, fmt.Errorf("failed to get customer gateways: %w", err)
30+
}
31+
for _, v := range res.CustomerGateways {
32+
r := resource.New(cfg, resource.Ec2CustomerGateway, v.CustomerGatewayId, v.CustomerGatewayId, v)
33+
rg.AddResource(r)
34+
}
35+
return rg, err
36+
}

lister/ec2_dhcpoption.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package lister
2+
3+
import (
4+
"github.com/aws/aws-sdk-go-v2/aws"
5+
"github.com/aws/aws-sdk-go-v2/service/ec2"
6+
"github.com/trek10inc/awsets/option"
7+
"github.com/trek10inc/awsets/resource"
8+
)
9+
10+
type AWSEc2DHCPOption struct {
11+
}
12+
13+
func init() {
14+
i := AWSEc2DHCPOption{}
15+
listers = append(listers, i)
16+
}
17+
18+
func (l AWSEc2DHCPOption) Types() []resource.ResourceType {
19+
return []resource.ResourceType{
20+
resource.Ec2DHCPOption,
21+
}
22+
}
23+
24+
func (l AWSEc2DHCPOption) List(cfg option.AWSetsConfig) (*resource.Group, error) {
25+
svc := ec2.NewFromConfig(cfg.AWSCfg)
26+
rg := resource.NewGroup()
27+
err := Paginator(func(nt *string) (*string, error) {
28+
res, err := svc.DescribeDhcpOptions(cfg.Context, &ec2.DescribeDhcpOptionsInput{
29+
MaxResults: aws.Int32(100),
30+
NextToken: nt,
31+
})
32+
if err != nil {
33+
return nil, err
34+
}
35+
for _, v := range res.DhcpOptions {
36+
r := resource.New(cfg, resource.Ec2DHCPOption, v.DhcpOptionsId, v.DhcpOptionsId, v)
37+
rg.AddResource(r)
38+
}
39+
return res.NextToken, nil
40+
})
41+
return rg, err
42+
}

lister/ec2_transitgateway.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ func (l AWSEc2TransitGateway) List(cfg option.AWSetsConfig) (*resource.Group, er
4040
for _, v := range res.TransitGateways {
4141
r := resource.New(cfg, resource.Ec2TransitGateway, v.TransitGatewayId, v.TransitGatewayId, v)
4242
// TODO lots of additional info to query here
43+
4344
rg.AddResource(r)
4445
}
4546
return res.NextToken, nil

lister/ec2_vpc.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
package lister
22

33
import (
4-
"github.com/trek10inc/awsets/option"
5-
"github.com/trek10inc/awsets/resource"
6-
74
"github.com/aws/aws-sdk-go-v2/aws"
85
"github.com/aws/aws-sdk-go-v2/service/ec2"
6+
"github.com/trek10inc/awsets/option"
7+
"github.com/trek10inc/awsets/resource"
98
)
109

1110
type AWSEc2Vpc struct {
@@ -34,6 +33,7 @@ func (l AWSEc2Vpc) List(cfg option.AWSetsConfig) (*resource.Group, error) {
3433
}
3534
for _, v := range res.Vpcs {
3635
r := resource.New(cfg, resource.Ec2Vpc, v.VpcId, v.VpcId, v)
36+
r.AddRelation(resource.Ec2DHCPOption, v.DhcpOptionsId, "")
3737
rg.AddResource(r)
3838
}
3939
return res.NextToken, nil

lister/ec2_vpcendpoint.go

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
package lister
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/aws/aws-sdk-go-v2/aws"
7+
"github.com/aws/aws-sdk-go-v2/service/ec2"
8+
"github.com/aws/aws-sdk-go-v2/service/ec2/types"
9+
"github.com/trek10inc/awsets/option"
10+
"github.com/trek10inc/awsets/resource"
11+
)
12+
13+
type AWSEc2VpcEndpoint struct {
14+
}
15+
16+
func init() {
17+
i := AWSEc2VpcEndpoint{}
18+
listers = append(listers, i)
19+
}
20+
21+
func (l AWSEc2VpcEndpoint) Types() []resource.ResourceType {
22+
return []resource.ResourceType{
23+
resource.Ec2VpcEndpoint,
24+
resource.Ec2VpcEndpointConnectionNotification,
25+
}
26+
}
27+
28+
func (l AWSEc2VpcEndpoint) List(cfg option.AWSetsConfig) (*resource.Group, error) {
29+
svc := ec2.NewFromConfig(cfg.AWSCfg)
30+
31+
rg := resource.NewGroup()
32+
err := Paginator(func(nt *string) (*string, error) {
33+
res, err := svc.DescribeVpcEndpoints(cfg.Context, &ec2.DescribeVpcEndpointsInput{
34+
MaxResults: aws.Int32(100),
35+
NextToken: nt,
36+
})
37+
if err != nil {
38+
return nil, err
39+
}
40+
for _, v := range res.VpcEndpoints {
41+
r := resource.New(cfg, resource.Ec2VpcEndpoint, v.VpcEndpointId, v.VpcEndpointId, v)
42+
r.AddRelation(resource.Ec2Vpc, v.VpcId, "")
43+
for _, dns := range v.DnsEntries {
44+
r.AddRelation(resource.Route53HostedZone, dns.HostedZoneId, "")
45+
}
46+
for _, rt := range v.RouteTableIds {
47+
r.AddRelation(resource.Ec2RouteTable, rt, "")
48+
}
49+
for _, eni := range v.NetworkInterfaceIds {
50+
r.AddRelation(resource.Ec2NetworkInterface, eni, "")
51+
}
52+
for _, sg := range v.Groups {
53+
r.AddRelation(resource.Ec2SecurityGroup, sg.GroupId, "")
54+
}
55+
for _, sn := range v.SubnetIds {
56+
r.AddRelation(resource.Ec2Subnet, sn, "")
57+
}
58+
59+
err = Paginator(func(nt2 *string) (*string, error) {
60+
ecns, err := svc.DescribeVpcEndpointConnectionNotifications(cfg.Context, &ec2.DescribeVpcEndpointConnectionNotificationsInput{
61+
ConnectionNotificationId: nil,
62+
DryRun: nil,
63+
Filters: []*types.Filter{{
64+
Name: aws.String("vpc-endpoint-id"),
65+
Values: []*string{v.VpcEndpointId},
66+
}},
67+
MaxResults: aws.Int32(100),
68+
NextToken: nt2,
69+
})
70+
if err != nil {
71+
return nil, fmt.Errorf("failed to get vpc endpoint connection notifications for %s: %w", *v.VpcEndpointId, err)
72+
}
73+
74+
for _, ecn := range ecns.ConnectionNotificationSet {
75+
cnR := resource.New(cfg, resource.Ec2VpcEndpointConnectionNotification, ecn.ConnectionNotificationId, ecn.ConnectionNotificationId, ecn)
76+
cnR.AddRelation(resource.Ec2VpcEndpoint, ecn.VpcEndpointId, "")
77+
cnR.AddRelation(resource.Ec2VpcEndpointService, ecn.ServiceId, "")
78+
rg.AddResource(cnR)
79+
}
80+
81+
return ecns.NextToken, nil
82+
})
83+
if err != nil {
84+
return nil, err
85+
}
86+
87+
rg.AddResource(r)
88+
}
89+
return res.NextToken, nil
90+
})
91+
return rg, err
92+
}

lister/ec2_vpcendpointservice.go

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
package lister
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/aws/aws-sdk-go-v2/service/ec2/types"
7+
8+
"github.com/aws/aws-sdk-go-v2/aws"
9+
"github.com/aws/aws-sdk-go-v2/service/ec2"
10+
"github.com/trek10inc/awsets/option"
11+
"github.com/trek10inc/awsets/resource"
12+
)
13+
14+
type AWSEc2VpcEndpointService struct {
15+
}
16+
17+
func init() {
18+
i := AWSEc2VpcEndpointService{}
19+
listers = append(listers, i)
20+
}
21+
22+
func (l AWSEc2VpcEndpointService) Types() []resource.ResourceType {
23+
return []resource.ResourceType{
24+
resource.Ec2VpcEndpointService,
25+
}
26+
}
27+
28+
func (l AWSEc2VpcEndpointService) List(cfg option.AWSetsConfig) (*resource.Group, error) {
29+
svc := ec2.NewFromConfig(cfg.AWSCfg)
30+
31+
rg := resource.NewGroup()
32+
err := Paginator(func(nt *string) (*string, error) {
33+
res, err := svc.DescribeVpcEndpointServices(cfg.Context, &ec2.DescribeVpcEndpointServicesInput{
34+
MaxResults: aws.Int32(100),
35+
NextToken: nt,
36+
})
37+
if err != nil {
38+
return nil, err
39+
}
40+
for _, v := range res.ServiceDetails {
41+
r := resource.New(cfg, resource.Ec2VpcEndpointService, v.ServiceId, v.ServiceName, v)
42+
43+
configs := make([]*types.ServiceConfiguration, 0)
44+
err = Paginator(func(nt2 *string) (*string, error) {
45+
scs, err := svc.DescribeVpcEndpointServiceConfigurations(cfg.Context, &ec2.DescribeVpcEndpointServiceConfigurationsInput{
46+
MaxResults: aws.Int32(100),
47+
NextToken: nt2,
48+
ServiceIds: []*string{v.ServiceId},
49+
})
50+
if err != nil {
51+
return nil, fmt.Errorf("failed to get vpc endpoint service configs for %s: %w", *v.ServiceId, err)
52+
}
53+
configs = append(configs, scs.ServiceConfigurations...)
54+
55+
return scs.NextToken, nil
56+
})
57+
if err != nil {
58+
return nil, err
59+
}
60+
if len(configs) > 0 {
61+
r.AddAttribute("Configurations", configs)
62+
}
63+
64+
principals := make([]*types.AllowedPrincipal, 0)
65+
err = Paginator(func(nt2 *string) (*string, error) {
66+
perms, err := svc.DescribeVpcEndpointServicePermissions(cfg.Context, &ec2.DescribeVpcEndpointServicePermissionsInput{
67+
MaxResults: aws.Int32(100),
68+
NextToken: nt2,
69+
ServiceId: v.ServiceId,
70+
})
71+
if err != nil {
72+
return nil, fmt.Errorf("failed to get vpc endpoint service permissions for %s: %w", *v.ServiceId, err)
73+
}
74+
principals = append(principals, perms.AllowedPrincipals...)
75+
76+
return perms.NextToken, nil
77+
})
78+
if err != nil {
79+
return nil, err
80+
}
81+
if len(principals) > 0 {
82+
r.AddAttribute("Permissions", principals)
83+
}
84+
85+
rg.AddResource(r)
86+
}
87+
return res.NextToken, nil
88+
})
89+
return rg, err
90+
}

lister/ec2_vpnconnection.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package lister
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/aws/aws-sdk-go-v2/service/ec2"
7+
"github.com/trek10inc/awsets/option"
8+
"github.com/trek10inc/awsets/resource"
9+
)
10+
11+
type AWSEc2VpnConnection struct {
12+
}
13+
14+
func init() {
15+
i := AWSEc2VpnConnection{}
16+
listers = append(listers, i)
17+
}
18+
19+
func (l AWSEc2VpnConnection) Types() []resource.ResourceType {
20+
return []resource.ResourceType{
21+
resource.Ec2VpnConnection,
22+
}
23+
}
24+
25+
func (l AWSEc2VpnConnection) List(cfg option.AWSetsConfig) (*resource.Group, error) {
26+
svc := ec2.NewFromConfig(cfg.AWSCfg)
27+
28+
rg := resource.NewGroup()
29+
res, err := svc.DescribeVpnConnections(cfg.Context, &ec2.DescribeVpnConnectionsInput{
30+
//VpnConnectionIds: nil,
31+
})
32+
if err != nil {
33+
return nil, fmt.Errorf("failed to get vpn connections: %w, err")
34+
}
35+
for _, v := range res.VpnConnections {
36+
r := resource.New(cfg, resource.Ec2VpnConnection, v.VpnConnectionId, v.VpnConnectionId, v)
37+
r.AddRelation(resource.Ec2CustomerGateway, v.CustomerGatewayId, "")
38+
r.AddRelation(resource.Ec2TransitGateway, v.TransitGatewayId, "")
39+
r.AddRelation(resource.Ec2VpnGateway, v.VpnGatewayId, "")
40+
rg.AddResource(r)
41+
}
42+
43+
return rg, err
44+
}

resource/cfn.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,8 @@ var mapping = map[string]ResourceType{
179179
"AWS::EC2::ClientVpnEndpoint": Unmapped,
180180
"AWS::EC2::ClientVpnRoute": Unmapped,
181181
"AWS::EC2::ClientVpnTargetNetworkAssociation": Unmapped,
182-
"AWS::EC2::CustomerGateway": Unmapped,
183-
"AWS::EC2::DHCPOptions": Unmapped,
182+
"AWS::EC2::CustomerGateway": Ec2CustomerGateway,
183+
"AWS::EC2::DHCPOptions": Ec2DHCPOption,
184184
"AWS::EC2::EC2Fleet": Unmapped,
185185
"AWS::EC2::EIP": Ec2Eip,
186186
"AWS::EC2::EIPAssociation": Ec2Eip,
@@ -222,16 +222,16 @@ var mapping = map[string]ResourceType{
222222
"AWS::EC2::TransitGatewayRouteTableAssociation": Unmapped,
223223
"AWS::EC2::TransitGatewayRouteTablePropagation": Unmapped,
224224
"AWS::EC2::VPC": Ec2Vpc,
225-
"AWS::EC2::VPCCidrBlock": Unmapped,
226-
"AWS::EC2::VPCDHCPOptionsAssociation": Unmapped,
227-
"AWS::EC2::VPCEndpoint": Unmapped,
228-
"AWS::EC2::VPCEndpointConnectionNotification": Unmapped,
229-
"AWS::EC2::VPCEndpointService": Unmapped,
230-
"AWS::EC2::VPCEndpointServicePermissions": Unmapped,
225+
"AWS::EC2::VPCCidrBlock": Ec2Vpc,
226+
"AWS::EC2::VPCDHCPOptionsAssociation": Ec2Vpc,
227+
"AWS::EC2::VPCEndpoint": Ec2VpcEndpoint,
228+
"AWS::EC2::VPCEndpointConnectionNotification": Ec2VpcEndpointConnectionNotification,
229+
"AWS::EC2::VPCEndpointService": Ec2VpcEndpointService,
230+
"AWS::EC2::VPCEndpointServicePermissions": Ec2VpcEndpointService,
231231
"AWS::EC2::VPCGatewayAttachment": Ec2VpnGateway,
232232
"AWS::EC2::VPCPeeringConnection": Ec2VpcPeering,
233-
"AWS::EC2::VPNConnection": Unmapped,
234-
"AWS::EC2::VPNConnectionRoute": Unmapped,
233+
"AWS::EC2::VPNConnection": Ec2VpnConnection,
234+
"AWS::EC2::VPNConnectionRoute": Ec2VpnConnection,
235235
"AWS::EC2::VPNGateway": Ec2VpnGateway,
236236
"AWS::EC2::VPNGatewayRoutePropagation": Unmapped,
237237
"AWS::EC2::Volume": Ec2Volume,

resource/types.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ const (
111111
DynamoDbBackup ResourceType = "ddb/backup"
112112
DynamoDbTable ResourceType = "ddb/table"
113113
DynamoDbStreamStream ResourceType = "ddbstream/stream"
114+
Ec2CustomerGateway ResourceType = "ec2/customergateway"
115+
Ec2DHCPOption ResourceType = "ec2/dhcpoption"
114116
Ec2Eip ResourceType = "ec2/eip"
115117
Ec2FlowLog ResourceType = "ec2/flowlog"
116118
Ec2Image ResourceType = "ec2/image"
@@ -129,7 +131,11 @@ const (
129131
Ec2TransitGateway ResourceType = "ec2/transitgateway"
130132
Ec2Volume ResourceType = "ec2/volume"
131133
Ec2Vpc ResourceType = "ec2/vpc"
134+
Ec2VpcEndpoint ResourceType = "ec2/vpcendpoint"
135+
Ec2VpcEndpointService ResourceType = "ec2/vpcendpointservice"
136+
Ec2VpcEndpointConnectionNotification ResourceType = "ec2/vpcendpointconnectionnotification"
132137
Ec2VpcPeering ResourceType = "ec2/vpcpeering"
138+
Ec2VpnConnection ResourceType = "ec2/vpnconnection"
133139
Ec2VpnGateway ResourceType = "ec2/vpngateway"
134140
EcrRepository ResourceType = "ecr/repository"
135141
EcsCapacityProvider ResourceType = "ecs/capacityprovider"

0 commit comments

Comments
 (0)