@@ -2,6 +2,7 @@ import { ServiceConnection } from '@cloudgraph/sdk'
22import isEmpty from 'lodash/isEmpty'
33
44import services from '../../enums/services'
5+ import { RawAwsSubnet } from '../subnet/data'
56import { RawAwsVpc } from '../vpc/data'
67import { RawAwsNetworkAcl } from './data'
78
@@ -19,9 +20,40 @@ 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 dataAtRegion : RawAwsSubnet [ ] = subnets . data [ region ] . filter (
40+ ( { SubnetId } : RawAwsSubnet ) =>
41+ ! isEmpty ( subnetIds ) &&
42+ subnetIds . filter ( str =>
43+ str . toLowerCase ( ) . includes ( SubnetId . toLowerCase ( ) )
44+ ) . length > 0
45+ )
46+ if ( ! isEmpty ( dataAtRegion ) ) {
47+ for ( const subnet of dataAtRegion ) {
48+ connections . push ( {
49+ id : subnet . SubnetId ,
50+ resourceType : services . subnet ,
51+ relation : 'child' ,
52+ field : 'subnets' ,
53+ } )
54+ }
55+ }
56+ }
2557
2658 /**
2759 * Find related Vpc
0 commit comments