diff --git a/plugins/source/aws/docs/tables/README.md b/plugins/source/aws/docs/tables/README.md index 09b7bdb6418f83..19047ed105b9ff 100644 --- a/plugins/source/aws/docs/tables/README.md +++ b/plugins/source/aws/docs/tables/README.md @@ -113,6 +113,7 @@ - [aws_directconnect_gateway_associations](aws_directconnect_gateway_associations.md) - [aws_directconnect_gateway_attachments](aws_directconnect_gateway_attachments.md) - [aws_directconnect_lags](aws_directconnect_lags.md) +- [aws_directconnect_locations](aws_directconnect_locations.md) - [aws_directconnect_virtual_gateways](aws_directconnect_virtual_gateways.md) - [aws_directconnect_virtual_interfaces](aws_directconnect_virtual_interfaces.md) - [aws_dms_replication_instances](aws_dms_replication_instances.md) diff --git a/plugins/source/aws/docs/tables/aws_directconnect_locations.md b/plugins/source/aws/docs/tables/aws_directconnect_locations.md new file mode 100644 index 00000000000000..f5bd2fd310200a --- /dev/null +++ b/plugins/source/aws/docs/tables/aws_directconnect_locations.md @@ -0,0 +1,21 @@ +# Table: aws_directconnect_locations + +https://docs.aws.amazon.com/directconnect/latest/APIReference/API_Location.html + +The composite primary key for this table is (**account_id**, **region**, **location_code**). + +## Columns + +| Name | Type | +| ------------- | ------------- | +|_cq_source_name|String| +|_cq_sync_time|Timestamp| +|_cq_id|UUID| +|_cq_parent_id|UUID| +|account_id (PK)|String| +|region (PK)|String| +|available_mac_sec_port_speeds|StringArray| +|available_port_speeds|StringArray| +|available_providers|StringArray| +|location_code (PK)|String| +|location_name|String| \ No newline at end of file diff --git a/plugins/source/aws/resources/plugin/tables.go b/plugins/source/aws/resources/plugin/tables.go index 5557322c42c21f..9df3fe63108556 100644 --- a/plugins/source/aws/resources/plugin/tables.go +++ b/plugins/source/aws/resources/plugin/tables.go @@ -162,6 +162,7 @@ func tables() []*schema.Table { directconnect.Connections(), directconnect.Gateways(), directconnect.Lags(), + directconnect.Locations(), directconnect.VirtualGateways(), directconnect.VirtualInterfaces(), dms.ReplicationInstances(), diff --git a/plugins/source/aws/resources/services/directconnect/locations.go b/plugins/source/aws/resources/services/directconnect/locations.go new file mode 100644 index 00000000000000..31c52d74ec8223 --- /dev/null +++ b/plugins/source/aws/resources/services/directconnect/locations.go @@ -0,0 +1,22 @@ +package directconnect + +import ( + "github.com/aws/aws-sdk-go-v2/service/directconnect/types" + "github.com/cloudquery/cloudquery/plugins/source/aws/client" + "github.com/cloudquery/plugin-sdk/schema" + "github.com/cloudquery/plugin-sdk/transformers" +) + +func Locations() *schema.Table { + return &schema.Table{ + Name: "aws_directconnect_locations", + Description: `https://docs.aws.amazon.com/directconnect/latest/APIReference/API_Location.html`, + Resolver: fetchDirectConnectLocations, + Multiplex: client.ServiceAccountRegionMultiplexer("directconnect"), + Transform: transformers.TransformWithStruct(&types.Location{}, transformers.WithPrimaryKeys("LocationCode")), + Columns: []schema.Column{ + client.DefaultAccountIDColumn(true), + client.DefaultRegionColumn(true), + }, + } +} diff --git a/plugins/source/aws/resources/services/directconnect/locations_fetch.go b/plugins/source/aws/resources/services/directconnect/locations_fetch.go new file mode 100644 index 00000000000000..7dcf2ef8cabb51 --- /dev/null +++ b/plugins/source/aws/resources/services/directconnect/locations_fetch.go @@ -0,0 +1,21 @@ +package directconnect + +import ( + "context" + + "github.com/aws/aws-sdk-go-v2/service/directconnect" + "github.com/cloudquery/cloudquery/plugins/source/aws/client" + "github.com/cloudquery/plugin-sdk/schema" +) + +func fetchDirectConnectLocations(ctx context.Context, meta schema.ClientMeta, parent *schema.Resource, res chan<- any) error { + var config directconnect.DescribeLocationsInput + c := meta.(*client.Client) + svc := c.Services().Directconnect + output, err := svc.DescribeLocations(ctx, &config) + if err != nil { + return err + } + res <- output.Locations + return nil +} diff --git a/plugins/source/aws/resources/services/directconnect/locations_mock_test.go b/plugins/source/aws/resources/services/directconnect/locations_mock_test.go new file mode 100644 index 00000000000000..c3c0f283c33a7a --- /dev/null +++ b/plugins/source/aws/resources/services/directconnect/locations_mock_test.go @@ -0,0 +1,32 @@ +package directconnect + +import ( + "testing" + + "github.com/aws/aws-sdk-go-v2/service/directconnect" + "github.com/aws/aws-sdk-go-v2/service/directconnect/types" + "github.com/cloudquery/cloudquery/plugins/source/aws/client" + "github.com/cloudquery/cloudquery/plugins/source/aws/client/mocks" + "github.com/cloudquery/plugin-sdk/faker" + "github.com/golang/mock/gomock" +) + +func buildDirectconnectLocations(t *testing.T, ctrl *gomock.Controller) client.Services { + m := mocks.NewMockDirectconnectClient(ctrl) + loc := types.Location{} + err := faker.FakeObject(&loc) + if err != nil { + t.Fatal(err) + } + m.EXPECT().DescribeLocations(gomock.Any(), gomock.Any(), gomock.Any()).Return( + &directconnect.DescribeLocationsOutput{ + Locations: []types.Location{loc}, + }, nil) + return client.Services{ + Directconnect: m, + } +} + +func TestDirectconnectLocation(t *testing.T) { + client.AwsMockTestHelper(t, Locations(), buildDirectconnectLocations, client.TestOptions{}) +} diff --git a/website/pages/docs/plugins/sources/aws/tables.md b/website/pages/docs/plugins/sources/aws/tables.md index c83b35b3284c86..f8220e98b44ba5 100644 --- a/website/pages/docs/plugins/sources/aws/tables.md +++ b/website/pages/docs/plugins/sources/aws/tables.md @@ -113,6 +113,7 @@ - [aws_directconnect_gateway_associations](https://github.com/cloudquery/cloudquery/blob/main/plugins/source/aws/docs/tables/aws_directconnect_gateway_associations.md) - [aws_directconnect_gateway_attachments](https://github.com/cloudquery/cloudquery/blob/main/plugins/source/aws/docs/tables/aws_directconnect_gateway_attachments.md) - [aws_directconnect_lags](https://github.com/cloudquery/cloudquery/blob/main/plugins/source/aws/docs/tables/aws_directconnect_lags.md) +- [aws_directconnect_locations](https://github.com/cloudquery/cloudquery/blob/main/plugins/source/aws/docs/tables/aws_directconnect_locations.md) - [aws_directconnect_virtual_gateways](https://github.com/cloudquery/cloudquery/blob/main/plugins/source/aws/docs/tables/aws_directconnect_virtual_gateways.md) - [aws_directconnect_virtual_interfaces](https://github.com/cloudquery/cloudquery/blob/main/plugins/source/aws/docs/tables/aws_directconnect_virtual_interfaces.md) - [aws_dms_replication_instances](https://github.com/cloudquery/cloudquery/blob/main/plugins/source/aws/docs/tables/aws_dms_replication_instances.md)