Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions plugins/source/aws/docs/tables/aws_directconnect_gateways.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

https://docs.aws.amazon.com/directconnect/latest/APIReference/API_DirectConnectGateway.html

The primary key for this table is **arn**.
The composite primary key for this table is (**account_id**, **region**, **arn**).

## Relations

Expand All @@ -18,8 +18,8 @@ The following tables depend on aws_directconnect_gateways:
|_cq_sync_time|Timestamp|
|_cq_id|UUID|
|_cq_parent_id|UUID|
|account_id|String|
|region|String|
|account_id (PK)|String|
|region (PK)|String|
|arn (PK)|String|
|id|String|
|amazon_side_asn|Int|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ func Gateways() *schema.Table {
Multiplex: client.ServiceAccountRegionMultiplexer("directconnect"),
Transform: transformers.TransformWithStruct(&types.DirectConnectGateway{}),
Columns: []schema.Column{
client.DefaultAccountIDColumn(false),
client.DefaultRegionColumn(false),
client.DefaultAccountIDColumn(true),
client.DefaultRegionColumn(true),
{
Name: "arn",
Type: schema.TypeString,
Resolver: resolveGatewayARN(),
Resolver: resolveGatewayARN,
CreationOptions: schema.ColumnCreationOptions{
PrimaryKey: true,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package directconnect

import (
"context"
"strings"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/aws/arn"
"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"
Expand Down Expand Up @@ -66,8 +68,14 @@ func fetchDirectconnectGatewayAttachments(ctx context.Context, meta schema.Clien
return nil
}

func resolveGatewayARN() schema.ColumnResolver {
return client.ResolveARNWithAccount(client.DirectConnectService, func(resource *schema.Resource) ([]string, error) {
return []string{"dx-gateway", *resource.Item.(types.DirectConnectGateway).DirectConnectGatewayId}, nil
})
func resolveGatewayARN(_ context.Context, meta schema.ClientMeta, resource *schema.Resource, c schema.Column) error {
cl := meta.(*client.Client)
gw := resource.Item.(types.DirectConnectGateway)

return resource.Set(c.Name, arn.ARN{
Partition: cl.Partition,
Service: "directconnect",
AccountID: *gw.OwnerAccount,
Resource: strings.Join([]string{"dx-gateway", *gw.DirectConnectGatewayId}, "/"),
}.String())
}