⚠ This page is served via a proxy. Original site: https://github.com
This service does not collect credentials or authentication data.
Skip to content
Merged
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
17 changes: 14 additions & 3 deletions cmd/ctrlc/root/sync/aws/networks/networks.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func runSync(regions *[]string, name *string) func(cmd *cobra.Command, args []st
return
}

awsSubnets, err := getAwsSubnets(ctx, ec2Client, regionName)
awsSubnets, err := getAwsSubnets(ctx, ec2Client, regionName, accountId)
if err != nil {
log.Error("Failed to get subnets", "region", regionName, "error", err)
mu.Lock()
Expand Down Expand Up @@ -193,6 +193,7 @@ func processNetworks(
for {
output, err := ec2Client.DescribeVpcs(ctx, &ec2.DescribeVpcsInput{
NextToken: nextToken,
Filters: getOwnerFilter(accountId),
})
if err != nil {
return nil, fmt.Errorf("failed to list VPCs: %w", err)
Expand Down Expand Up @@ -289,13 +290,13 @@ func initNetworkMetadata(vpc types.Vpc, region string, subnetCount int) map[stri

// getSubnetsForVpc retrieves subnets as AWS SDK objects
// these objects are processed differently for VPC and subnet resources
func getAwsSubnets(ctx context.Context, ec2Client *ec2.Client, region string) ([]types.Subnet, error) {
func getAwsSubnets(ctx context.Context, ec2Client *ec2.Client, region string, accountId string) ([]types.Subnet, error) {
var subnets []types.Subnet
var nextToken *string

for {
subnetInput := &ec2.DescribeSubnetsInput{
Filters: []types.Filter{},
Filters: getOwnerFilter(accountId),
NextToken: nextToken,
}

Expand Down Expand Up @@ -406,6 +407,16 @@ func getVpcName(vpc types.Vpc) string {
return vpcName
}

func getOwnerFilter(accountId string) []types.Filter {
ownerId := "owner-id"
return []types.Filter{
{
Name: &ownerId,
Values: []string{accountId},
},
}
}

func getSubnetConsoleUrl(subnet types.Subnet, region string) string {
return fmt.Sprintf(
"https://%s.console.aws.amazon.com/vpcconsole/home?region=%s#SubnetDetails:subnetId=%s",
Expand Down