Skip to content
This repository has been archived by the owner on Aug 16, 2022. It is now read-only.

Commit

Permalink
feat: Adding ec2.vpn_gateways (#86)
Browse files Browse the repository at this point in the history
* Adding ec2_vpn_gateways
  • Loading branch information
saumilg66 authored Jun 3, 2021
1 parent ecb50fb commit a6e856b
Show file tree
Hide file tree
Showing 6 changed files with 151 additions and 0 deletions.
16 changes: 16 additions & 0 deletions client/mocks/builders_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,22 @@ func buildEc2VpcsPeeringConnections(t *testing.T, ctrl *gomock.Controller) clien
}
}

func buildEc2VpnGateways(t *testing.T, ctrl *gomock.Controller) client.Services {
m := mocks.NewMockEc2Client(ctrl)
l := ec2Types.VpnGateway{}
err := faker.FakeData(&l)
if err != nil {
t.Fatal(err)
}
m.EXPECT().DescribeVpnGateways(gomock.Any(), gomock.Any(), gomock.Any()).Return(
&ec2.DescribeVpnGatewaysOutput{
VpnGateways: []ec2Types.VpnGateway{l},
}, nil)
return client.Services{
EC2: m,
}
}

func buildEc2Instances(t *testing.T, ctrl *gomock.Controller) client.Services {
m := mocks.NewMockEc2Client(ctrl)
l := ec2Types.Reservation{}
Expand Down
5 changes: 5 additions & 0 deletions client/mocks/mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,11 @@ func TestResources(t *testing.T) {
mockBuilder: buildEc2VpcsPeeringConnections,
mainTable: resources.Ec2VpcPeeringConnections(),
},
{
resource: "ec2.vpn_gateways",
mockBuilder: buildEc2VpnGateways,
mainTable: resources.Ec2VpnGateways(),
},
{
resource: "ecr.repositories",
mockBuilder: buildEcrRepositoriesMock,
Expand Down
20 changes: 20 additions & 0 deletions client/mocks/services.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions client/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ type Ec2Client interface {
DescribeVolumes(ctx context.Context, params *ec2.DescribeVolumesInput, optFns ...func(*ec2.Options)) (*ec2.DescribeVolumesOutput, error)
DescribeVpcs(ctx context.Context, params *ec2.DescribeVpcsInput, optFns ...func(*ec2.Options)) (*ec2.DescribeVpcsOutput, error)
DescribeVpcEndpoints(ctx context.Context, params *ec2.DescribeVpcEndpointsInput, optFns ...func(*ec2.Options)) (*ec2.DescribeVpcEndpointsOutput, error)
DescribeVpnGateways(ctx context.Context, params *ec2.DescribeVpnGatewaysInput, optFns ...func(*ec2.Options)) (*ec2.DescribeVpnGatewaysOutput, error)
GetEbsEncryptionByDefault(ctx context.Context, params *ec2.GetEbsEncryptionByDefaultInput, optFns ...func(*ec2.Options)) (*ec2.GetEbsEncryptionByDefaultOutput, error)
GetEbsDefaultKmsKeyId(ctx context.Context, params *ec2.GetEbsDefaultKmsKeyIdInput, optFns ...func(*ec2.Options)) (*ec2.GetEbsDefaultKmsKeyIdOutput, error)
}
Expand Down
108 changes: 108 additions & 0 deletions resources/ec2_vpn_gateways.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package resources

import (
"context"

"github.com/aws/aws-sdk-go-v2/service/ec2"
"github.com/aws/aws-sdk-go-v2/service/ec2/types"
"github.com/cloudquery/cq-provider-aws/client"
"github.com/cloudquery/cq-provider-sdk/provider/schema"
)

func Ec2VpnGateways() *schema.Table {
return &schema.Table{
Name: "aws_ec2_vpn_gateways",
Resolver: fetchEc2VpnGateways,
Multiplex: client.AccountRegionMultiplex,
IgnoreError: client.IgnoreAccessDeniedServiceDisabled,
DeleteFilter: client.DeleteAccountRegionFilter,
Columns: []schema.Column{
{
Name: "account_id",
Type: schema.TypeString,
Resolver: client.ResolveAWSAccount,
},
{
Name: "region",
Type: schema.TypeString,
Resolver: client.ResolveAWSRegion,
},
{
Name: "amazon_side_asn",
Type: schema.TypeBigInt,
},
{
Name: "availability_zone",
Type: schema.TypeString,
},
{
Name: "state",
Type: schema.TypeString,
},
{
Name: "tags",
Type: schema.TypeJSON,
Resolver: resolveEc2VpnGatewayTags,
},
{
Name: "type",
Type: schema.TypeString,
},
{
Name: "vpn_gateway_id",
Type: schema.TypeString,
},
},
Relations: []*schema.Table{
{
Name: "aws_ec2_vpc_attachment",
Resolver: fetchEc2VpcAttachments,
Columns: []schema.Column{
{
Name: "vpn_gateway_id",
Type: schema.TypeUUID,
Resolver: schema.ParentIdResolver,
},
{
Name: "state",
Type: schema.TypeString,
},
{
Name: "vpc_id",
Type: schema.TypeString,
},
},
},
},
}
}

// ====================================================================================================================
// Table Resolver Functions
// ====================================================================================================================
func fetchEc2VpnGateways(ctx context.Context, meta schema.ClientMeta, parent *schema.Resource, res chan interface{}) error {
var config ec2.DescribeVpnGatewaysInput
c := meta.(*client.Client)
svc := c.Services().EC2
output, err := svc.DescribeVpnGateways(ctx, &config, func(options *ec2.Options) {
options.Region = c.Region
})
if err != nil {
return err
}
res <- output.VpnGateways
return nil
}
func fetchEc2VpcAttachments(ctx context.Context, meta schema.ClientMeta, parent *schema.Resource, res chan interface{}) error {
r := parent.Item.(types.VpnGateway)
res <- r.VpcAttachments
return nil
}
func resolveEc2VpnGatewayTags(ctx context.Context, meta schema.ClientMeta, resource *schema.Resource, c schema.Column) error {
r := resource.Item.(types.VpnGateway)
tags := map[string]*string{}
for _, t := range r.Tags {
tags[*t.Key] = t.Value
}
return resource.Set("tags", tags)
}
1 change: 1 addition & 0 deletions resources/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func Provider() *provider.Provider {
"ec2.vpc_peering_connections": Ec2VpcPeeringConnections(),
"ec2.vpc_endpoints": Ec2VpcEndpoints(),
"ec2.vpcs": Ec2Vpcs(),
"ec2.vpn_gateways": Ec2VpnGateways(),
"ec2.instances": Ec2Instances(),
"ec2.security_groups": Ec2SecurityGroups(),
"ec2.ebs_volumes": Ec2EbsVolumes(),
Expand Down

0 comments on commit a6e856b

Please sign in to comment.