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

Commit

Permalink
feat: directconnect virtual gateways (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
James Quigley authored May 3, 2021
1 parent a54a07f commit 82dc2fa
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 1 deletion.
2 changes: 1 addition & 1 deletion adding_a_new_resource.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ If the service to which the resource belongs has not been used before in cq-prov
1. In that file, create a function that returns a `*schema.Table`
1. In [resources/provider.go](./resources/provider.go), add a mapping between the function you just created and the name of the resource that will be used in the config yml file.
1. In [client/config.go](./client/config.go), add the key that you used in the map in the previous step to the config template
1. Add a test in [clients/mocks/mock_test.go](./clients/../client/mocks/mock_test.go) for the resource following the existing examples
1. Add a test in [clients/mocks/mock_test.go](./client/mocks/mock_test.go) and the corresponding test implementation in [clients/mocks/builders_test.go](./client/mocks/builders_test.go) for the resource following the existing examples.

### Implementation

Expand Down
1 change: 1 addition & 0 deletions client/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const DefaultConfigYaml = `
- name: cloudwatch.alarms
- name: cloudwatchlogs.filters
- name: directconnect.gateways
- name: directconnect.virtual_gateways
- name: directconnect.virtual_interfaces
- name: ec2.customer_gateways
- name: ec2.ebs_volumes
Expand Down
16 changes: 16 additions & 0 deletions client/mocks/builders_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,22 @@ func buildDirectconnectGatewaysMock(t *testing.T, ctrl *gomock.Controller) clien
}
}

func buildDirectconnectVirtualGatewaysMock(t *testing.T, ctrl *gomock.Controller) client.Services {
m := mocks.NewMockDirectconnectClient(ctrl)
l := directconnectTypes.VirtualGateway{}
err := faker.FakeData(&l)
if err != nil {
t.Fatal(err)
}
m.EXPECT().DescribeVirtualGateways(gomock.Any(), gomock.Any(), gomock.Any()).Return(
&directconnect.DescribeVirtualGatewaysOutput{
VirtualGateways: []directconnectTypes.VirtualGateway{l},
}, nil)
return client.Services{
Directconnect: m,
}
}

func buildDirectconnectVirtualInterfacesMock(t *testing.T, ctrl *gomock.Controller) client.Services {
m := mocks.NewMockDirectconnectClient(ctrl)
l := directconnectTypes.VirtualInterface{}
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 @@ -75,6 +75,11 @@ func TestResources(t *testing.T) {
mockBuilder: buildDirectconnectGatewaysMock,
mainTable: resources.DirectconnectGateways(),
},
{
resource: "directconnect.virtual_gateways",
mockBuilder: buildDirectconnectVirtualGatewaysMock,
mainTable: resources.DirectconnectVirtualGateways(),
},
{
resource: "directconnect.virtual_interfaces",
mockBuilder: buildDirectconnectVirtualInterfacesMock,
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 @@ -50,6 +50,7 @@ type CloudwatchLogsClient interface {

type DirectconnectClient interface {
DescribeDirectConnectGateways(ctx context.Context, params *directconnect.DescribeDirectConnectGatewaysInput, optFns ...func(*directconnect.Options)) (*directconnect.DescribeDirectConnectGatewaysOutput, error)
DescribeVirtualGateways(ctx context.Context, params *directconnect.DescribeVirtualGatewaysInput, optFns ...func(*directconnect.Options)) (*directconnect.DescribeVirtualGatewaysOutput, error)
DescribeVirtualInterfaces(ctx context.Context, params *directconnect.DescribeVirtualInterfacesInput, optFns ...func(*directconnect.Options)) (*directconnect.DescribeVirtualInterfacesOutput, error)
}

Expand Down
53 changes: 53 additions & 0 deletions resources/directconnect_virtual_gateways.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package resources

import (
"context"

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

func DirectconnectVirtualGateways() *schema.Table {
return &schema.Table{
Name: "aws_directconnect_virtual_gateways",
Resolver: fetchDirectconnectVirtualGateways,
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: "virtual_gateway_id",
Type: schema.TypeString,
},
{
Name: "virtual_gateway_state",
Type: schema.TypeString,
},
},
}
}

func fetchDirectconnectVirtualGateways(ctx context.Context, meta schema.ClientMeta, parent *schema.Resource, res chan interface{}) error {
var config directconnect.DescribeVirtualGatewaysInput
c := meta.(*client.Client)
svc := c.Services().Directconnect
output, err := svc.DescribeVirtualGateways(ctx, &config, func(options *directconnect.Options) {
options.Region = c.Region
})
if err != nil {
return err
}
res <- output.VirtualGateways
return nil
}
1 change: 1 addition & 0 deletions resources/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ func Provider() *provider.Provider {
"cloudwatchlogs.filters": CloudwatchlogsFilters(),
"s3.buckets": S3Buckets(),
"directconnect.gateways": DirectconnectGateways(),
"directconnect.virtual_gateways": DirectconnectVirtualGateways(),
"directconnect.virtual_interfaces": DirectconnectVirtualInterfaces(),
"ec2.byoip_cidrs": Ec2ByoipCidrs(),
"ec2.customer_gateways": Ec2CustomerGateways(),
Expand Down

0 comments on commit 82dc2fa

Please sign in to comment.