@@ -19,6 +19,8 @@ import { ssmManagedInstanceArn } from '../../utils/generateArns'
1919import { RawAwsElasticBeanstalkEnv } from '../elasticBeanstalkEnvironment/data'
2020import { RawAwsEksCluster } from '../eksCluster/data'
2121import { getEksClusterName , getElasticBeanstalkEnvId } from './utils'
22+ import { RawAwsInstanceProfile } from '../iamInstanceProfile/data'
23+ import { globalRegionName } from '../../enums/regions'
2224
2325/**
2426 * EC2
@@ -48,6 +50,7 @@ export default ({
4850 NetworkInterfaces : instanceNetworkInterfaces = [ ] ,
4951 SubnetId : subnetId ,
5052 Tags : tags ,
53+ IamInstanceProfile : iamInstanceProfile ,
5154 } = instance
5255
5356 /**
@@ -293,7 +296,7 @@ export default ({
293296 } = data . find ( ( { name } ) => name === services . elasticBeanstalkEnv )
294297 if ( elasticBeanstalkEnvs ?. data ?. [ region ] ) {
295298 const elasticBeanstalkEnvsInRegion : RawAwsElasticBeanstalkEnv [ ] =
296- elasticBeanstalkEnvs . data [ region ] . filter (
299+ elasticBeanstalkEnvs . data [ region ] . filter (
297300 ( { EnvironmentId } : RawAwsElasticBeanstalkEnv ) =>
298301 elasticBeanstalkEnvId === EnvironmentId
299302 )
@@ -310,6 +313,32 @@ export default ({
310313 }
311314 }
312315
316+ /**
317+ * Find IAM Instance Profiles
318+ * related to this EC2 instance
319+ */
320+ const iamInstanceProfiles : {
321+ name : string
322+ data : { [ property : string ] : any [ ] }
323+ } = data . find ( ( { name } ) => name === services . iamInstanceProfile )
324+ if ( iamInstanceProfiles ?. data ?. [ globalRegionName ] ) {
325+ const dataAtRegion : RawAwsInstanceProfile [ ] = iamInstanceProfiles . data [
326+ globalRegionName
327+ ] . filter ( instanceProfile => instanceProfile . Arn === iamInstanceProfile ?. Arn )
328+ if ( ! isEmpty ( dataAtRegion ) ) {
329+ for ( const iamInstance of dataAtRegion ) {
330+ const { InstanceProfileId : instanceProfileId } : RawAwsInstanceProfile = iamInstance
331+
332+ connections . push ( {
333+ id : instanceProfileId ,
334+ resourceType : services . iamInstanceProfile ,
335+ relation : 'child' ,
336+ field : 'iamInstanceProfile' ,
337+ } )
338+ }
339+ }
340+ }
341+
313342 const ec2Result = {
314343 [ id ] : connections ,
315344 }
0 commit comments