1- // TODO: Enable when IAM is added
2- // import { ServiceConnection } from '@cloudgraph/sdk';
3- // import { Stack } from 'aws-sdk/clients/cloudformation';
4- // import { TagMap } from '../../types'
1+ import isEmpty from 'lodash/isEmpty'
2+ import { ServiceConnection } from '@cloudgraph/sdk' ;
3+ import { StackSet } from 'aws-sdk/clients/cloudformation' ;
4+ import { TagMap } from '../../types'
5+ import services from '../../enums/services'
6+ import { RawAwsIamRole } from '../iamRole/data'
7+ import { globalRegionName } from '../../enums/regions'
58
6- // / **
7- // * Cloud Formation StackSet
8- // */
9+ /**
10+ * Cloud Formation StackSet
11+ */
912
10- // export default ({
11- // service: cfStackSet,
12- // data,
13- // region,
14- // }: {
15- // data: { name: string; data: { [property: string]: any[] } }[]
16- // service: Stack & {
17- // region: string
18- // Tags: TagMap,
19- // },
20- // region: string
21- // }): { [key: string]: ServiceConnection[] } => {
22- // const connections: ServiceConnection[] = []
13+ export default ( {
14+ service : cfStackSet ,
15+ data,
16+ region,
17+ } : {
18+ data : { name : string ; data : { [ property : string ] : any [ ] } } [ ]
19+ service : StackSet & {
20+ region : string
21+ Tags : TagMap ,
22+ } ,
23+ region : string
24+ } ) : { [ key : string ] : ServiceConnection [ ] } => {
25+ const connections : ServiceConnection [ ] = [ ]
2326
24- // const {
25- // StackId : id,
26- // // TODO add connection role
27- // // AdministrationRoleARN: administrationRoleARN
28- // } = cfStackSet
27+ const {
28+ StackSetId : id ,
29+ AdministrationRoleARN : administrationRoleARN ,
30+ ExecutionRoleName : executionRoleName ,
31+ } = cfStackSet
2932
30- // const cfStackSetResult = {
31- // [id]: connections,
32- // }
33- // return cfStackSetResult
34- // }
33+ /**
34+ * Find related IAM Roles
35+ */
36+ const roles : { name : string ; data : { [ property : string ] : any [ ] } } =
37+ data . find ( ( { name } ) => name === services . iamRole )
38+ if ( roles ?. data ?. [ globalRegionName ] ) {
39+ const dataAtRegion : RawAwsIamRole [ ] = roles . data [ globalRegionName ] . filter (
40+ role => role . Arn === administrationRoleARN || role . RoleName === executionRoleName
41+ )
42+ if ( ! isEmpty ( dataAtRegion ) ) {
43+ for ( const instance of dataAtRegion ) {
44+ const { Arn : arn } : RawAwsIamRole = instance
45+
46+ connections . push ( {
47+ id : arn ,
48+ resourceType : services . iamRole ,
49+ relation : 'child' ,
50+ field : 'iamRoles' ,
51+ } )
52+ }
53+ }
54+ }
55+
56+ const cfStackSetResult = {
57+ [ id ] : connections ,
58+ }
59+ return cfStackSetResult
60+ }
0 commit comments