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

Commit

Permalink
feat: directconnect lags
Browse files Browse the repository at this point in the history
  • Loading branch information
James Quigley committed Jul 22, 2021
1 parent 45b2c28 commit 00eccee
Show file tree
Hide file tree
Showing 9 changed files with 307 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ jobs:
- name: build-docs
run: |
go run ./docs/docs.go
- name: Fail if docs are changed
- name: Fail if docs aren't changed
run: |
test "$(git status -s ./docs/tables | wc -l)" -eq 0
3 changes: 2 additions & 1 deletion adding_a_new_resource.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ If the service to which the resource belongs has not been used before in cq-prov
1. Create a file under `resources/` that follows the pattern of `<service>_<resource>`.
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. Add a test in [clients/mocks/resources_test.go](./client/mocks/resources_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.
1. Add a test file at `resources/<service>_<resource>_test.go`. Follow other examples to create a test for the resource.
1. Run `go run docs/docs.go` to generate the documentation for the new resource

### Implementation

Expand Down
20 changes: 20 additions & 0 deletions client/mocks/mock_directconnect.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 @@ -133,6 +133,7 @@ type DirectconnectClient interface {
DescribeDirectConnectGateways(ctx context.Context, params *directconnect.DescribeDirectConnectGatewaysInput, optFns ...func(*directconnect.Options)) (*directconnect.DescribeDirectConnectGatewaysOutput, error)
DescribeDirectConnectGatewayAssociations(ctx context.Context, params *directconnect.DescribeDirectConnectGatewayAssociationsInput, optFns ...func(*directconnect.Options)) (*directconnect.DescribeDirectConnectGatewayAssociationsOutput, error)
DescribeDirectConnectGatewayAttachments(ctx context.Context, params *directconnect.DescribeDirectConnectGatewayAttachmentsInput, optFns ...func(*directconnect.Options)) (*directconnect.DescribeDirectConnectGatewayAttachmentsOutput, error)
DescribeLags(ctx context.Context, params *directconnect.DescribeLagsInput, optFns ...func(*directconnect.Options)) (*directconnect.DescribeLagsOutput, 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
12 changes: 12 additions & 0 deletions docs/tables/aws_directconnect_lag_mac_sec_keys.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

# Table: aws_directconnect_lag_mac_sec_keys
The MAC Security (MACsec) security keys associated with the LAG.
## Columns
| Name | Type | Description |
| ------------- | ------------- | ----- |
|lag_cq_id|uuid|Unique CloudQuery ID of aws_directconnect_lags table (FK)|
|lag_id|text|The ID of the LAG.|
|ckn|text|The Connection Key Name (CKN) for the MAC Security secret key.|
|secret_arn|text|The Amazon Resource Name (ARN) of the MAC Security (MACsec) secret key.|
|start_on|text|The date that the MAC Security (MACsec) secret key takes effect. The value is displayed in UTC format.|
|state|text|The state of the MAC Security secret key. The possible values are: associating, associated, disassociating, disassociated|
25 changes: 25 additions & 0 deletions docs/tables/aws_directconnect_lags.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

# Table: aws_directconnect_lags
Information about Direct Connect Link Aggregation Group (LAG)
## Columns
| Name | Type | Description |
| ------------- | ------------- | ----- |
|account_id|text|The AWS Account ID of the resource.|
|region|text|The AWS Region of the resource.|
|allows_hosted_connections|boolean|Indicates whether the LAG can host other connections.|
|aws_device_v2|text|The AWS Direct Connect endpoint that hosts the LAG.|
|connection_ids|text[]|The list of IDs of Direct Connect Connections bundled by the LAG|
|connections_bandwidth|text|The individual bandwidth of the physical connections bundled by the LAG.|
|encryption_mode|text|The LAG MAC Security (MACsec) encryption mode.|
|has_logical_redundancy|text|Indicates whether the LAG supports a secondary BGP peer in the same address family (IPv4/IPv6).|
|jumbo_frame_capable|boolean|Indicates whether jumbo frames (9001 MTU) are supported.|
|id|text|The ID of the LAG.|
|name|text|The name of the LAG.|
|lag_state|text|The state of the LAG. Possible values are: requested, pending, available, down, deleting, deleted, unknown|
|location|text|The location of the LAG.|
|mac_sec_capable|boolean|Indicates whether the LAG supports MAC Security (MACsec).|
|minimum_links|integer|The minimum number of physical dedicated connections that must be operational for the LAG itself to be operational.|
|number_of_connections|integer|The number of physical dedicated connections bundled by the LAG, up to a maximum of 10.|
|owner_account|text|The ID of the AWS account that owns the LAG.|
|provider_name|text|The name of the service provider associated with the LAG.|
|tags|jsonb|The tags associated with the LAG.|
213 changes: 213 additions & 0 deletions resources/directconnect_lags.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
package resources

import (
"context"
"fmt"

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

func DirectconnectLags() *schema.Table {
return &schema.Table{
Name: "aws_directconnect_lags",
Description: "Information about Direct Connect Link Aggregation Group (LAG)",
Resolver: fetchDirectconnectLags,
Multiplex: client.AccountRegionMultiplex,
IgnoreError: client.IgnoreAccessDeniedServiceDisabled,
DeleteFilter: client.DeleteAccountRegionFilter,
Options: schema.TableCreationOptions{PrimaryKeys: []string{"account_id", "id"}},
Columns: []schema.Column{
{
Name: "account_id",
Description: "The AWS Account ID of the resource.",
Type: schema.TypeString,
Resolver: client.ResolveAWSAccount,
},
{
Name: "region",
Description: "The AWS Region of the resource.",
Type: schema.TypeString,
Resolver: client.ResolveAWSRegion,
},
{
Name: "allows_hosted_connections",
Description: "Indicates whether the LAG can host other connections.",
Type: schema.TypeBool,
},
{
Name: "aws_device_v2",
Description: "The AWS Direct Connect endpoint that hosts the LAG.",
Type: schema.TypeString,
},
{
Name: "connection_ids",
Description: "The list of IDs of Direct Connect Connections bundled by the LAG",
Type: schema.TypeStringArray,
Resolver: resolveDirectconnectLagConnectionIds,
},
{
Name: "connections_bandwidth",
Description: "The individual bandwidth of the physical connections bundled by the LAG.",
Type: schema.TypeString,
},
{
Name: "encryption_mode",
Description: "The LAG MAC Security (MACsec) encryption mode.",
Type: schema.TypeString,
},
{
Name: "has_logical_redundancy",
Description: "Indicates whether the LAG supports a secondary BGP peer in the same address family (IPv4/IPv6).",
Type: schema.TypeString,
},
{
Name: "jumbo_frame_capable",
Description: "Indicates whether jumbo frames (9001 MTU) are supported.",
Type: schema.TypeBool,
},
{
Name: "id",
Description: "The ID of the LAG.",
Type: schema.TypeString,
Resolver: schema.PathResolver("LagId"),
},
{
Name: "name",
Description: "The name of the LAG.",
Type: schema.TypeString,
Resolver: schema.PathResolver("LagName"),
},
{
Name: "lag_state",
Description: "The state of the LAG. Possible values are: requested, pending, available, down, deleting, deleted, unknown",
Type: schema.TypeString,
},
{
Name: "location",
Description: "The location of the LAG.",
Type: schema.TypeString,
},
{
Name: "mac_sec_capable",
Description: "Indicates whether the LAG supports MAC Security (MACsec).",
Type: schema.TypeBool,
},
{
Name: "minimum_links",
Description: "The minimum number of physical dedicated connections that must be operational for the LAG itself to be operational.",
Type: schema.TypeInt,
},
{
Name: "number_of_connections",
Description: "The number of physical dedicated connections bundled by the LAG, up to a maximum of 10.",
Type: schema.TypeInt,
},
{
Name: "owner_account",
Description: "The ID of the AWS account that owns the LAG.",
Type: schema.TypeString,
},
{
Name: "provider_name",
Description: "The name of the service provider associated with the LAG.",
Type: schema.TypeString,
},
{
Name: "tags",
Description: "The tags associated with the LAG.",
Type: schema.TypeJSON,
Resolver: resolveDirectconnectLagTags,
},
},
Relations: []*schema.Table{
{
Name: "aws_directconnect_lag_mac_sec_keys",
Description: "The MAC Security (MACsec) security keys associated with the LAG.",
Resolver: fetchDirectconnectLagMacSecKeys,
Options: schema.TableCreationOptions{PrimaryKeys: []string{"lag_cq_id", "secret_arn"}},
Columns: []schema.Column{
{
Name: "lag_cq_id",
Description: "Unique CloudQuery ID of aws_directconnect_lags table (FK)",
Type: schema.TypeUUID,
Resolver: schema.ParentIdResolver,
},
{
Name: "lag_id",
Description: "The ID of the LAG.",
Type: schema.TypeString,
Resolver: schema.ParentResourceFieldResolver("id"),
},
{
Name: "ckn",
Description: "The Connection Key Name (CKN) for the MAC Security secret key.",
Type: schema.TypeString,
},
{
Name: "secret_arn",
Description: "The Amazon Resource Name (ARN) of the MAC Security (MACsec) secret key.",
Type: schema.TypeString,
Resolver: schema.PathResolver("SecretARN"),
},
{
Name: "start_on",
Description: "The date that the MAC Security (MACsec) secret key takes effect. The value is displayed in UTC format.",
Type: schema.TypeString,
},
{
Name: "state",
Description: "The state of the MAC Security secret key. The possible values are: associating, associated, disassociating, disassociated",
Type: schema.TypeString,
},
},
},
},
}
}

// ====================================================================================================================
// Table Resolver Functions
// ====================================================================================================================
func fetchDirectconnectLags(ctx context.Context, meta schema.ClientMeta, parent *schema.Resource, res chan interface{}) error {
var config directconnect.DescribeLagsInput
c := meta.(*client.Client)
svc := c.Services().Directconnect
output, err := svc.DescribeLags(ctx, &config, func(options *directconnect.Options) {
options.Region = c.Region
})
if err != nil {
return err
}
res <- output.Lags
return nil
}

func resolveDirectconnectLagTags(ctx context.Context, meta schema.ClientMeta, resource *schema.Resource, c schema.Column) error {
r := resource.Item.(types.Lag)
tags := map[string]*string{}
for _, t := range r.Tags {
tags[*t.Key] = t.Value
}
return resource.Set("tags", tags)
}

func fetchDirectconnectLagMacSecKeys(ctx context.Context, meta schema.ClientMeta, parent *schema.Resource, res chan interface{}) error {
connection, ok := parent.Item.(types.Lag)
if !ok {
return fmt.Errorf("not a direct connect LAG")
}
res <- connection.MacSecKeys
return nil
}

func resolveDirectconnectLagConnectionIds(ctx context.Context, meta schema.ClientMeta, resource *schema.Resource, c schema.Column) error {
r := resource.Item.(types.Lag)
connectionIds := make([]*string, len(r.Connections))
for i, connection := range r.Connections {
connectionIds[i] = connection.ConnectionId
}
return resource.Set("connection_ids", connectionIds)
}
32 changes: 32 additions & 0 deletions resources/directconnect_lags_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package resources

import (
"testing"

"github.com/aws/aws-sdk-go-v2/service/directconnect"
"github.com/aws/aws-sdk-go-v2/service/directconnect/types"
"github.com/cloudquery/cq-provider-aws/client"
"github.com/cloudquery/cq-provider-aws/client/mocks"
"github.com/cloudquery/faker/v3"
"github.com/golang/mock/gomock"
)

func buildDirectconnectLag(t *testing.T, ctrl *gomock.Controller) client.Services {
m := mocks.NewMockDirectconnectClient(ctrl)
lag := types.Lag{}
err := faker.FakeData(&lag)
if err != nil {
t.Fatal(err)
}
m.EXPECT().DescribeLags(gomock.Any(), gomock.Any(), gomock.Any()).Return(
&directconnect.DescribeLagsOutput{
Lags: []types.Lag{lag},
}, nil)
return client.Services{
Directconnect: m,
}
}

func TestDirectconnectLag(t *testing.T) {
awsTestHelper(t, DirectconnectLags(), buildDirectconnectLag, TestOptions{})
}
1 change: 1 addition & 0 deletions resources/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func Provider() *provider.Provider {
"s3.buckets": S3Buckets(),
"directconnect.connections": DirectconnectConnections(),
"directconnect.gateways": DirectconnectGateways(),
"directconnect.lags": DirectconnectLags(),
"directconnect.virtual_gateways": DirectconnectVirtualGateways(),
"directconnect.virtual_interfaces": DirectconnectVirtualInterfaces(),
"cognito.identity_pools": CognitoIdentityPools(),
Expand Down

0 comments on commit 00eccee

Please sign in to comment.