Skip to content

Commit 7706a02

Browse files
Christopher BrandtMarco Franceschi
authored andcommitted
feat(rdsCluster): add subnet connection, add missing properties
1 parent 7658127 commit 7706a02

7 files changed

Lines changed: 74 additions & 9 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ CloudGraph AWS Provider will ask you what regions you would like to crawl and wi
137137
| natGateway | networkInterface, subnet, vpc |
138138
| networkInterface | ec2, eip, efsMountTarget, natGateway, sageMakerNotebookInstance, subnet, vpc, flowLog, securityGroup |
139139
| organization |
140-
| rdsCluster | appSync, rdsClusterSnapshot, rdsDbInstance, securityGroup, iamRole, kms |
140+
| rdsCluster | appSync, rdsClusterSnapshot, rdsDbInstance, securityGroup, subnet, iamRole, kms |
141141
| rdsClusterSnapshot | kms, rdsCluster, vpc |
142142
| rdsDbInstance | rdsCluster, securityGroup, vpc, subnet |
143143
| redshiftCluster | kms, vpc |
@@ -153,7 +153,7 @@ CloudGraph AWS Provider will ask you what regions you would like to crawl and wi
153153
| ses | |
154154
| sns | kms, cloudtrail, cloudwatch, s3 |
155155
| sqs | s3 |
156-
| subnet | alb, asg, codebuild, dmsReplicationInstance, ec2, ecsService, efsMountTarget, elastiCacheCluster, elasticSearchDomain, elb, lambda, managedAirflow, natGateway, networkInterface, sageMakerNotebookInstance, routeTable, vpc, eksCluster, emrCluster, flowLog |
156+
| subnet | alb, asg, codebuild, dmsReplicationInstance, ec2, ecsService, efsMountTarget, elastiCacheCluster, elasticSearchDomain, elb, lambda, managedAirflow, natGateway, networkInterface, rdsCluster, sageMakerNotebookInstance, routeTable, vpc, eksCluster, emrCluster, flowLog |
157157
| systemsManagerInstance | ec2, iamRole |
158158
| systemsManagerDocument | |
159159
| transitGateway | routeTable, transitGatewayAttachment, vpnConnection |

src/services/rdsCluster/connections.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ import { SecurityGroup } from 'aws-sdk/clients/ec2'
44
import { DBInstance, DBCluster } from 'aws-sdk/clients/rds'
55

66
import services from '../../enums/services'
7+
import { RawAwsRdsCluster } from './data'
78
import { RawAwsRdsClusterSnapshot } from '../rdsClusterSnapshot/data'
89
import { RawAwsIamRole } from '../iamRole/data'
10+
import { RawAwsSubnet } from '../subnet/data'
911
import { AwsKms } from '../kms/data'
1012
import { globalRegionName } from '../../enums/regions'
1113

@@ -14,7 +16,7 @@ export default ({
1416
data,
1517
region,
1618
}: {
17-
service: DBCluster
19+
service: RawAwsRdsCluster
1820
data: Array<{ name: string; data: { [property: string]: any[] } }>
1921
region: string
2022
}): {
@@ -24,6 +26,7 @@ export default ({
2426
const {
2527
DBClusterArn: id,
2628
DBClusterIdentifier: clusterId,
29+
dbSubnetGroups,
2730
MonitoringRoleArn: monitoringRoleArn,
2831
AssociatedRoles: associatedRoles = [],
2932
KmsKeyId,
@@ -208,6 +211,33 @@ export default ({
208211
}
209212
}
210213

214+
/**
215+
* Find Subnets
216+
* related to this RDS Cluster
217+
*/
218+
const subnets = data.find(({ name }) => name === services.subnet)
219+
const subnetIds = dbSubnetGroups?.map(
220+
({ Subnets }) => Subnets?.map(subnet => subnet.SubnetIdentifier)
221+
)
222+
if (subnets?.data?.[region]) {
223+
const subnetsInRegion = subnets.data[region].filter(
224+
(subnet: RawAwsSubnet) =>
225+
subnetIds.some(ids => ids.includes(subnet.SubnetId))
226+
)
227+
if (!isEmpty(subnetsInRegion)) {
228+
for (const subnet of subnetsInRegion) {
229+
const { SubnetId } = subnet
230+
231+
connections.push({
232+
id: SubnetId,
233+
resourceType: services.subnet,
234+
relation: 'child',
235+
field: 'subnets',
236+
})
237+
}
238+
}
239+
}
240+
211241
const rdsClusterResult = {
212242
[id]: connections,
213243
}

src/services/rdsCluster/data.ts

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import RDS, {
44
TagListMessage,
55
DescribeDBClustersMessage,
66
DBClusterMessage,
7+
DBSubnetGroup,
8+
DBSubnetGroupMessage,
79
} from 'aws-sdk/clients/rds'
810
import { AWSError } from 'aws-sdk/lib/error'
911
import groupBy from 'lodash/groupBy'
@@ -57,6 +59,29 @@ const listClustersForRegion = async rds =>
5759
listAllClusters()
5860
})
5961

62+
const describeDBSubnetGroups = async (rds: RDS, DBSubnetGroupName: string): Promise<DBSubnetGroup[]> =>
63+
new Promise(resolve => {
64+
try {
65+
rds.describeDBSubnetGroups(
66+
{ DBSubnetGroupName },
67+
(err: AWSError, data: DBSubnetGroupMessage) => {
68+
if (err) {
69+
errorLog.generateAwsErrorLog({
70+
functionName: 'rds:describeDBSubnetGroups',
71+
err,
72+
})
73+
return resolve([])
74+
}
75+
if (!isEmpty(data)) {
76+
resolve(data.DBSubnetGroups)
77+
}
78+
}
79+
)
80+
} catch (error) {
81+
resolve([])
82+
}
83+
})
84+
6085
const getResourceTags = async (rds: RDS, arn: string): Promise<TagMap> =>
6186
new Promise(resolve => {
6287
try {
@@ -80,6 +105,7 @@ const getResourceTags = async (rds: RDS, arn: string): Promise<TagMap> =>
80105
})
81106

82107
export interface RawAwsRdsCluster extends DBCluster {
108+
dbSubnetGroups: DBSubnetGroup[]
83109
Tags?: TagMap
84110
region: string
85111
}
@@ -104,10 +130,11 @@ export default async ({
104130

105131
if (!isEmpty(clusters)) {
106132
rdsData.push(
107-
...clusters.map(cluster => ({
133+
...await Promise.all(clusters.map(async (cluster) => ({
108134
...cluster,
135+
dbSubnetGroups: await describeDBSubnetGroups(rds, cluster.DBSubnetGroup),
109136
region,
110-
}))
137+
})))
111138
)
112139
}
113140
resolveRegion()

src/services/rdsCluster/format.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ export default ({
1414
const {
1515
DBClusterArn: arn,
1616
DBClusterIdentifier: dbClusterIdentifier,
17-
DBSubnetGroup: subnets,
17+
DBClusterParameterGroup: dbClusterParameterGroup,
18+
DBSubnetGroup: dbSubnetGroup,
1819
Status: status,
1920
Engine: engine,
2021
EngineVersion: engineVersion,
@@ -55,7 +56,8 @@ export default ({
5556
characterSetName,
5657
databaseName,
5758
dbClusterIdentifier,
58-
subnets,
59+
dbClusterParameterGroup,
60+
dbSubnetGroup,
5961
status,
6062
percentProgress,
6163
readerEndpoint,

src/services/rdsCluster/schema.graphql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ type awsRdsCluster implements awsBaseService @key(fields: "arn") {
44
characterSetName: String @search(by: [hash, regexp])
55
databaseName: String @search(by: [hash, regexp])
66
dbClusterIdentifier: String @search(by: [hash])
7-
subnets: String @search(by: [hash])
7+
dbClusterParameterGroup: String @search(by: [hash])
8+
dbSubnetGroup: String @search(by: [hash])
89
status: String @search(by: [hash, regexp])
910
percentProgress: String @search(by: [hash, regexp])
1011
readerEndpoint: String @search(by: [hash, regexp])
@@ -32,6 +33,7 @@ type awsRdsCluster implements awsBaseService @key(fields: "arn") {
3233
instances: [awsRdsDbInstance] @hasInverse(field: cluster)
3334
snapshots: [awsRdsClusterSnapshot] @hasInverse(field: cluster)
3435
securityGroups: [awsSecurityGroup] @hasInverse(field: rdsCluster)
36+
subnets: [awsSubnet] @hasInverse(field: rdsCluster)
3537
appSync: [awsAppSync] @hasInverse(field: rdsCluster)
3638
monitoringIamRole: [awsIamRole] @hasInverse(field: rdsClusterMonitoringRole)
3739
iamRoles: [awsIamRole] @hasInverse(field: rdsClusterIamRoles)

src/services/subnet/schema.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,5 @@ type awsSubnet implements awsBaseService @key(fields: "id") {
3232
@hasInverse(field: subnets)
3333
sageMakerNotebookInstances: [awsSageMakerNotebookInstance]
3434
@hasInverse(field: subnet)
35+
rdsCluster: [awsRdsCluster] @hasInverse(field: subnets)
3536
}

src/types/generated.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3515,6 +3515,8 @@ export type AwsRdsCluster = AwsBaseService & {
35153515
crossAccountClone?: Maybe<Scalars['Boolean']>;
35163516
databaseName?: Maybe<Scalars['String']>;
35173517
dbClusterIdentifier?: Maybe<Scalars['String']>;
3518+
dbClusterParameterGroup?: Maybe<Scalars['String']>;
3519+
dbSubnetGroup?: Maybe<Scalars['String']>;
35183520
deletionProtection?: Maybe<Scalars['Boolean']>;
35193521
encrypted?: Maybe<Scalars['Boolean']>;
35203522
engine?: Maybe<Scalars['String']>;
@@ -3539,7 +3541,7 @@ export type AwsRdsCluster = AwsBaseService & {
35393541
snapshots?: Maybe<Array<Maybe<AwsRdsClusterSnapshot>>>;
35403542
status?: Maybe<Scalars['String']>;
35413543
storageEncryptedKms?: Maybe<Array<Maybe<AwsKms>>>;
3542-
subnets?: Maybe<Scalars['String']>;
3544+
subnets?: Maybe<Array<Maybe<AwsSubnet>>>;
35433545
tags?: Maybe<Array<Maybe<AwsRawTag>>>;
35443546
username?: Maybe<Scalars['String']>;
35453547
};
@@ -4007,6 +4009,7 @@ export type AwsSubnet = AwsBaseService & {
40074009
nacls?: Maybe<Array<Maybe<AwsNetworkAcl>>>;
40084010
natGateway?: Maybe<Array<Maybe<AwsNatGateway>>>;
40094011
networkInterface?: Maybe<Array<Maybe<AwsNetworkInterface>>>;
4012+
rdsCluster?: Maybe<Array<Maybe<AwsRdsCluster>>>;
40104013
rdsDbInstance?: Maybe<Array<Maybe<AwsRdsDbInstance>>>;
40114014
routeTable?: Maybe<Array<Maybe<AwsRouteTable>>>;
40124015
sageMakerNotebookInstances?: Maybe<Array<Maybe<AwsSageMakerNotebookInstance>>>;

0 commit comments

Comments
 (0)