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

Commit

Permalink
fix: DirectConnect Gateways are global (#513)
Browse files Browse the repository at this point in the history
  • Loading branch information
disq authored Mar 1, 2022
1 parent 7253db6 commit 0eaa035
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 21 deletions.
1 change: 0 additions & 1 deletion docs/tables/aws_directconnect_gateways.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ Information about a Direct Connect gateway, which enables you to connect virtual
| Name | Type | Description |
| ------------- | ------------- | ----- |
|account_id|text|The AWS Account ID of the resource.|
|region|text|The AWS Region of the resource.|
|arn|text|The Amazon Resource Name (ARN) for the resource.|
|amazon_side_asn|bigint|The autonomous system number (ASN) for the Amazon side of the connection.|
|id|text|The ID of the Direct Connect gateway.|
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ require (
github.com/aws/aws-sdk-go-v2/service/wafv2 v1.5.1
github.com/aws/smithy-go v1.9.1
github.com/bxcodec/faker v2.0.1+incompatible
github.com/cloudquery/cq-provider-sdk v0.8.3
github.com/cloudquery/cq-provider-sdk v0.8.4
github.com/cloudquery/faker/v3 v3.7.5
github.com/gocarina/gocsv v0.0.0-20210516172204-ca9e8a8ddea8
github.com/golang/mock v1.6.0
Expand Down
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -318,10 +318,8 @@ github.com/cilium/ebpf v0.4.0/go.mod h1:4tRaxcgiL706VnOzHOdBlY8IEAIdxINsQBcU4xJJ
github.com/cilium/ebpf v0.6.2/go.mod h1:4tRaxcgiL706VnOzHOdBlY8IEAIdxINsQBcU4xJJXRs=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/cloudflare/golz4 v0.0.0-20150217214814-ef862a3cdc58/go.mod h1:EOBUe0h4xcZ5GoxqC5SDxFQ8gwyZPKQoEzownBlhI80=
github.com/cloudquery/cq-provider-sdk v0.8.2 h1:qvDmEyFpy8KeJgK0IMfP/yxu83wpN0e4eFsYXjlH0Pg=
github.com/cloudquery/cq-provider-sdk v0.8.2/go.mod h1:IHxqY7TOttWhNQhMRqYl1vBo2JS2szLAf5Mhg78MwTQ=
github.com/cloudquery/cq-provider-sdk v0.8.3 h1:NdOS3PK6E+4SblT7yB6PTg/tx24G1A9oNrIr+SH5OQs=
github.com/cloudquery/cq-provider-sdk v0.8.3/go.mod h1:IHxqY7TOttWhNQhMRqYl1vBo2JS2szLAf5Mhg78MwTQ=
github.com/cloudquery/cq-provider-sdk v0.8.4 h1:rwVtBpk5Xe7/dBioGgeNbmAKwM3eoo+PPWV4HP/sG5s=
github.com/cloudquery/cq-provider-sdk v0.8.4/go.mod h1:IHxqY7TOttWhNQhMRqYl1vBo2JS2szLAf5Mhg78MwTQ=
github.com/cloudquery/faker/v3 v3.7.4/go.mod h1:1b8WVG9Gh0T2hVo1a8dWeXfu0AhqSB6J/mmJaesqOeo=
github.com/cloudquery/faker/v3 v3.7.5 h1:G7ANdEEcm8TvAAjIwNWSLrYK36CFCiSlrCqOTGCccL0=
github.com/cloudquery/faker/v3 v3.7.5/go.mod h1:1b8WVG9Gh0T2hVo1a8dWeXfu0AhqSB6J/mmJaesqOeo=
Expand Down
7 changes: 7 additions & 0 deletions resources/provider/migrations/postgres/20_v0.10.9.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- Resource: directconnect.gateways
ALTER TABLE IF EXISTS "aws_directconnect_gateways" ADD COLUMN IF NOT EXISTS "region" text;

ALTER TABLE IF EXISTS aws_directconnect_gateways
DROP CONSTRAINT aws_directconnect_gateways_pk;
ALTER TABLE IF EXISTS aws_directconnect_gateways
ADD CONSTRAINT aws_directconnect_gateways_pk PRIMARY KEY (account_id,region,id);
9 changes: 9 additions & 0 deletions resources/provider/migrations/postgres/20_v0.10.9.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-- Resource: directconnect.gateways
TRUNCATE aws_directconnect_gateways CASCADE;

ALTER TABLE IF EXISTS aws_directconnect_gateways
DROP CONSTRAINT aws_directconnect_gateways_pk;
ALTER TABLE IF EXISTS aws_directconnect_gateways
ADD CONSTRAINT aws_directconnect_gateways_pk PRIMARY KEY (account_id,id);

ALTER TABLE IF EXISTS "aws_directconnect_gateways" DROP COLUMN IF EXISTS "region";
7 changes: 7 additions & 0 deletions resources/provider/migrations/timescale/20_v0.10.9.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- Resource: directconnect.gateways
ALTER TABLE IF EXISTS "aws_directconnect_gateways" ADD COLUMN IF NOT EXISTS "region" text;

ALTER TABLE IF EXISTS aws_directconnect_gateways
DROP CONSTRAINT aws_directconnect_gateways_pk;
ALTER TABLE IF EXISTS aws_directconnect_gateways
ADD CONSTRAINT aws_directconnect_gateways_pk PRIMARY KEY (cq_fetch_date,account_id,region,id);
9 changes: 9 additions & 0 deletions resources/provider/migrations/timescale/20_v0.10.9.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-- Resource: directconnect.gateways
TRUNCATE aws_directconnect_gateways CASCADE;

ALTER TABLE IF EXISTS aws_directconnect_gateways
DROP CONSTRAINT aws_directconnect_gateways_pk;
ALTER TABLE IF EXISTS aws_directconnect_gateways
ADD CONSTRAINT aws_directconnect_gateways_pk PRIMARY KEY (cq_fetch_date,account_id,id);

ALTER TABLE IF EXISTS "aws_directconnect_gateways" DROP COLUMN IF EXISTS "region";
20 changes: 5 additions & 15 deletions resources/services/directconnect/gateways.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ func DirectconnectGateways() *schema.Table {
Name: "aws_directconnect_gateways",
Description: "Information about a Direct Connect gateway, which enables you to connect virtual interfaces and virtual private gateway or transit gateways.",
Resolver: fetchDirectconnectGateways,
Multiplex: client.ServiceAccountRegionMultiplexer("directconnect"),
Multiplex: client.AccountMultiplex,
IgnoreError: client.IgnoreAccessDeniedServiceDisabled,
DeleteFilter: client.DeleteAccountRegionFilter,
Options: schema.TableCreationOptions{PrimaryKeys: []string{"account_id", "region", "id"}},
DeleteFilter: client.DeleteAccountFilter,
Options: schema.TableCreationOptions{PrimaryKeys: []string{"account_id", "id"}},
IgnoreInTests: true,
Columns: []schema.Column{
{
Expand All @@ -28,12 +28,6 @@ func DirectconnectGateways() *schema.Table {
Type: schema.TypeString,
Resolver: client.ResolveAWSAccount,
},
{
Name: "region",
Description: "The AWS Region of the resource.",
Type: schema.TypeString,
Resolver: client.ResolveAWSRegion,
},
{
Name: "arn",
Description: "The Amazon Resource Name (ARN) for the resource.",
Expand Down Expand Up @@ -226,9 +220,7 @@ func fetchDirectconnectGateways(ctx context.Context, meta schema.ClientMeta, par
c := meta.(*client.Client)
svc := c.Services().Directconnect
for {
output, err := svc.DescribeDirectConnectGateways(ctx, &config, func(options *directconnect.Options) {
options.Region = c.Region
})
output, err := svc.DescribeDirectConnectGateways(ctx, &config)
if err != nil {
return err
}
Expand All @@ -247,9 +239,7 @@ func fetchDirectconnectGatewayAssociations(ctx context.Context, meta schema.Clie
svc := c.Services().Directconnect
config := directconnect.DescribeDirectConnectGatewayAssociationsInput{DirectConnectGatewayId: gateway.DirectConnectGatewayId}
for {
output, err := svc.DescribeDirectConnectGatewayAssociations(ctx, &config, func(options *directconnect.Options) {
options.Region = c.Region
})
output, err := svc.DescribeDirectConnectGatewayAssociations(ctx, &config)
if err != nil {
return err
}
Expand Down

0 comments on commit 0eaa035

Please sign in to comment.