Skip to content

Commit 6ed6dee

Browse files
committed
fix: add connection between nacl and subnet services
1 parent 2f94abd commit 6ed6dee

4 files changed

Lines changed: 36 additions & 3 deletions

File tree

src/services/nacl/connections.ts

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { ServiceConnection } from '@cloudgraph/sdk'
22
import isEmpty from 'lodash/isEmpty'
33

44
import services from '../../enums/services'
5+
import { RawAwsSubnet } from '../subnet/data'
56
import { RawAwsVpc } from '../vpc/data'
67
import { RawAwsNetworkAcl } from './data'
78

@@ -19,9 +20,38 @@ export default ({
1920
service: RawAwsNetworkAcl
2021
}): { [key: string]: ServiceConnection[] } => {
2122
const connections: ServiceConnection[] = []
22-
const { NetworkAclId: id, VpcId: NaclVpcId } = nacl
23+
const {
24+
NetworkAclId: id,
25+
VpcId: NaclVpcId,
26+
Associations: naclSubnetAssociations,
27+
} = nacl
2328

24-
// TODO: Add subnet connection
29+
const subnetIds = naclSubnetAssociations.map(({ SubnetId }) => SubnetId)
30+
31+
/**
32+
* Find related Subnets
33+
*/
34+
const subnets: {
35+
name: string
36+
data: { [property: string]: RawAwsSubnet[] }
37+
} = data.find(({ name }) => name === services.subnet)
38+
if (subnets?.data?.[region]) {
39+
const subnet: RawAwsSubnet = subnets.data[region].find(
40+
({ SubnetId }: RawAwsSubnet) =>
41+
!isEmpty(subnetIds) &&
42+
subnetIds.filter(str =>
43+
str.toLowerCase().includes(SubnetId.toLowerCase())
44+
).length > 0
45+
)
46+
if (!isEmpty(subnet)) {
47+
connections.push({
48+
id: subnet.VpcId,
49+
resourceType: services.subnet,
50+
relation: 'child',
51+
field: 'subnets',
52+
})
53+
}
54+
}
2555

2656
/**
2757
* Find related Vpc

src/services/nacl/schema.graphql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ type awsNetworkAcl implements awsBaseService @key(fields: "id") {
55
associatedSubnets: [awsNetworkAclAssociatedSubnet]
66
tags: [awsRawTag]
77
vpc: [awsVpc] @hasInverse(field: nacl)
8-
# subnet: [awsSubnet] @hasInverse(field: nacl) #change to plural
8+
subnets: [awsSubnet] @hasInverse(field: nacls)
99
vpcId: String @search(by: [hash, regexp])
1010
}
1111

src/services/subnet/schema.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ type awsSubnet implements awsBaseService @key(fields: "id") {
1313
ec2Instances: [awsEc2] @hasInverse(field: subnets) #change to plural
1414
elb: [awsElb] @hasInverse(field: subnet) #change to plural
1515
lambda: [awsLambda] @hasInverse(field: subnet) #change to plural
16+
nacls: [awsNetworkAcl] @hasInverse(field: subnets)
1617
natGateway: [awsNatGateway] @hasInverse(field: subnet) #change to plural
1718
networkInterface: [awsNetworkInterface] @hasInverse(field: subnet) #change to plural
1819
routeTable: [awsRouteTable] @hasInverse(field: subnet)

src/types/generated.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3392,6 +3392,7 @@ export type AwsNetworkAcl = AwsBaseService & {
33923392
default?: Maybe<Scalars['Boolean']>;
33933393
inboundRules?: Maybe<Array<Maybe<AwsNetworkAclRule>>>;
33943394
outboundRules?: Maybe<Array<Maybe<AwsNetworkAclRule>>>;
3395+
subnets?: Maybe<Array<Maybe<AwsSubnet>>>;
33953396
tags?: Maybe<Array<Maybe<AwsRawTag>>>;
33963397
vpc?: Maybe<Array<Maybe<AwsVpc>>>;
33973398
vpcId?: Maybe<Scalars['String']>;
@@ -3919,6 +3920,7 @@ export type AwsSubnet = AwsBaseService & {
39193920
ipV6Cidr?: Maybe<Scalars['String']>;
39203921
lambda?: Maybe<Array<Maybe<AwsLambda>>>;
39213922
managedAirflows?: Maybe<Array<Maybe<AwsManagedAirflow>>>;
3923+
nacls?: Maybe<Array<Maybe<AwsNetworkAcl>>>;
39223924
natGateway?: Maybe<Array<Maybe<AwsNatGateway>>>;
39233925
networkInterface?: Maybe<Array<Maybe<AwsNetworkInterface>>>;
39243926
rdsDbInstance?: Maybe<Array<Maybe<AwsRdsDbInstance>>>;

0 commit comments

Comments
 (0)