Skip to content

Commit 80a39e1

Browse files
author
Marco Franceschi
committed
fix: Created iamRole connection for emrCluster
1 parent bc158a2 commit 80a39e1

5 files changed

Lines changed: 48 additions & 23 deletions

File tree

src/services/emrCluster/connections.ts

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import { ServiceConnection } from '@cloudgraph/sdk'
22
import { isEmpty } from 'lodash'
33
import { RawAwsEmrCluster } from '../emrCluster/data'
44
import { RawAwsSubnet } from '../subnet/data'
5+
import { RawAwsIamRole } from '../iamRole/data'
56
import services from '../../enums/services'
67

78
export default ({
8-
account,
99
service,
1010
data,
1111
region,
@@ -17,7 +17,13 @@ export default ({
1717
}): {
1818
[property: string]: ServiceConnection[]
1919
} => {
20-
const { ClusterArn: id, Ec2InstanceAttributes, LogEncryptionKmsKeyId } = service
20+
const {
21+
ClusterArn: id,
22+
Ec2InstanceAttributes,
23+
LogEncryptionKmsKeyId,
24+
ServiceRole,
25+
AutoScalingRole,
26+
} = service
2127
const connections: ServiceConnection[] = []
2228
const subnetId = Ec2InstanceAttributes?.Ec2SubnetId
2329

@@ -26,8 +32,8 @@ export default ({
2632
*/
2733
const kmsKeys = data.find(({ name }) => name === services.kms)
2834
if (kmsKeys?.data?.[region]) {
29-
const kmsKeyInRegion = kmsKeys.data[region].filter(kmsKey =>
30-
kmsKey.Arn === LogEncryptionKmsKeyId
35+
const kmsKeyInRegion = kmsKeys.data[region].filter(
36+
kmsKey => kmsKey.Arn === LogEncryptionKmsKeyId
3137
)
3238

3339
if (!isEmpty(kmsKeyInRegion)) {
@@ -66,8 +72,34 @@ export default ({
6672
}
6773
}
6874

75+
/**
76+
* Find IAM Roles
77+
*/
78+
const iamRoles: {
79+
name: string
80+
data: { [property: string]: any[] }
81+
} = data.find(({ name }) => name === services.iamRole)
82+
83+
if (iamRoles?.data?.[region]) {
84+
const iamRolesInRegion: RawAwsIamRole[] = iamRoles.data[region].filter(
85+
({ RoleName }: RawAwsIamRole) =>
86+
RoleName === ServiceRole || RoleName === AutoScalingRole
87+
)
88+
89+
if (!isEmpty(iamRolesInRegion)) {
90+
for (const role of iamRolesInRegion) {
91+
connections.push({
92+
id: role.Arn,
93+
resourceType: services.iamRole,
94+
relation: 'child',
95+
field: 'iamRoles',
96+
})
97+
}
98+
}
99+
}
100+
69101
const result = {
70102
[id]: connections,
71103
}
72104
return result
73-
}
105+
}

src/services/emrCluster/format.ts

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
import cuid from 'cuid'
2-
import {
3-
Configuration,
4-
} from 'aws-sdk/clients/emr'
2+
import { Configuration } from 'aws-sdk/clients/emr'
53
import { AwsEmrCluster } from '../../types/generated'
64
import { formatTagsFromMap } from '../../utils/format'
75
import { RawAwsEmrCluster } from './data'
86

97
export default ({
108
service,
119
account,
12-
region
10+
region,
1311
}: {
1412
service: RawAwsEmrCluster
1513
account: string
@@ -28,12 +26,10 @@ export default ({
2826
AutoTerminate: autoTerminate,
2927
TerminationProtected: terminationProtected,
3028
VisibleToAllUsers: visibleToAllUsers,
31-
ServiceRole: serviceRole,
3229
NormalizedInstanceHours: normalizedInstanceHours,
3330
MasterPublicDnsName: masterPublicDnsName,
3431
Configurations: configurations,
3532
SecurityConfiguration: securityConfiguration,
36-
AutoScalingRole: autoScalingRole,
3733
ScaleDownBehavior: scaleDownBehavior,
3834
CustomAmiId: customAmiId,
3935
EbsRootVolumeSize: ebsRootVolumeSize,
@@ -50,7 +46,7 @@ export default ({
5046
Timeline: timeline,
5147
} = status ?? {}
5248

53-
const {
49+
const {
5450
Ec2KeyName: ec2KeyName,
5551
Ec2SubnetId: ec2SubnetId,
5652
RequestedEc2SubnetIds: requestedEc2SubnetIds,
@@ -73,7 +69,7 @@ export default ({
7369
id: cuid(),
7470
key,
7571
value: app.AdditionalInfo[key],
76-
}))
72+
})),
7773
}))
7874

7975
const {
@@ -92,7 +88,7 @@ export default ({
9288
id: cuid(),
9389
key,
9490
value: config.Properties[key],
95-
}))
91+
})),
9692
})
9793

9894
const placementGroups = service.PlacementGroups?.map(pg => ({
@@ -116,7 +112,7 @@ export default ({
116112
creationDateTime: timeline?.CreationDateTime?.toISOString(),
117113
readyDateTime: timeline?.ReadyDateTime?.toISOString(),
118114
endDateTime: timeline?.EndDateTime?.toISOString(),
119-
}
115+
},
120116
},
121117
ec2InstanceAttributes: {
122118
ec2KeyName,
@@ -141,12 +137,10 @@ export default ({
141137
terminationProtected,
142138
visibleToAllUsers,
143139
applications,
144-
serviceRole,
145140
normalizedInstanceHours,
146141
masterPublicDnsName,
147142
configurations: configurations?.map(child => configConverter(child)),
148143
securityConfiguration,
149-
autoScalingRole,
150144
scaleDownBehavior,
151145
customAmiId,
152146
ebsRootVolumeSize,
@@ -163,4 +157,4 @@ export default ({
163157
placementGroups,
164158
tags: formatTagsFromMap(Tags),
165159
}
166-
}
160+
}

src/services/emrCluster/schema.graphql

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#TODO: add iamRole connection here
21
type awsEmrCluster implements awsBaseService @key(fields: "arn") {
32
status: AwsEmrClusterStatus
43
ec2InstanceAttributes: AwsEmrClusterEc2InstanceAttributes
@@ -12,12 +11,10 @@ type awsEmrCluster implements awsBaseService @key(fields: "arn") {
1211
terminationProtected: Boolean @search
1312
visibleToAllUsers: Boolean @search
1413
applications: [AwsEmrClusterApplication]
15-
serviceRole: String @search(by: [hash, regexp])
1614
normalizedInstanceHours: Int @search
1715
masterPublicDnsName: String @search(by: [hash, regexp])
1816
configurations: [AwsEmrClusterConfiguration]
1917
securityConfiguration: String @search(by: [hash, regexp])
20-
autoScalingRole: String @search(by: [hash, regexp])
2118
scaleDownBehavior: String @search(by: [hash, regexp])
2219
customAmiId: String @search(by: [hash, regexp])
2320
ebsRootVolumeSize: Int @search
@@ -29,6 +26,7 @@ type awsEmrCluster implements awsBaseService @key(fields: "arn") {
2926
tags: [awsRawTag]
3027
kms: [awsKms] @hasInverse(field: emrCluster)
3128
subnet: [awsSubnet] @hasInverse(field: emrCluster) #change to plural
29+
iamRoles: [awsIamRole] @hasInverse(field: emrCluster)
3230
}
3331

3432
type AwsEmrClusterApplication

src/services/iamRole/schema.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,5 @@ type awsIamRole implements awsBaseService @key(fields: "id") {
3737
asg: [awsAsg] @hasInverse(field: iamRole)
3838
awsCognitoIdentityPool: [awsCognitoIdentityPool] @hasInverse(field: iamRoles)
3939
rdsDbInstance: [awsRdsDbInstance] @hasInverse(field: iamRoles)
40+
emrCluster: [awsEmrCluster] @hasInverse(field: iamRoles)
4041
}

src/types/generated.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2742,12 +2742,12 @@ export type AwsElbSourceSecurityGroup = {
27422742

27432743
export type AwsEmrCluster = AwsBaseService & {
27442744
applications?: Maybe<Array<Maybe<AwsEmrClusterApplication>>>;
2745-
autoScalingRole?: Maybe<Scalars['String']>;
27462745
autoTerminate?: Maybe<Scalars['Boolean']>;
27472746
configurations?: Maybe<Array<Maybe<AwsEmrClusterConfiguration>>>;
27482747
customAmiId?: Maybe<Scalars['String']>;
27492748
ebsRootVolumeSize?: Maybe<Scalars['Int']>;
27502749
ec2InstanceAttributes?: Maybe<AwsEmrClusterEc2InstanceAttributes>;
2750+
iamRoles?: Maybe<Array<Maybe<AwsIamRole>>>;
27512751
instanceCollectionType?: Maybe<Scalars['String']>;
27522752
kerberosAttributes?: Maybe<AwsEmrClusterKerberosAttributes>;
27532753
kms?: Maybe<Array<Maybe<AwsKms>>>;
@@ -2763,7 +2763,6 @@ export type AwsEmrCluster = AwsBaseService & {
27632763
runningAmiVersion?: Maybe<Scalars['String']>;
27642764
scaleDownBehavior?: Maybe<Scalars['String']>;
27652765
securityConfiguration?: Maybe<Scalars['String']>;
2766-
serviceRole?: Maybe<Scalars['String']>;
27672766
status?: Maybe<AwsEmrClusterStatus>;
27682767
stepConcurrencyLevel?: Maybe<Scalars['Int']>;
27692768
subnet?: Maybe<Array<Maybe<AwsSubnet>>>;
@@ -3082,6 +3081,7 @@ export type AwsIamRole = AwsBaseService & {
30823081
eksClusters?: Maybe<Array<Maybe<AwsEksCluster>>>;
30833082
elasticBeanstalkApps?: Maybe<Array<Maybe<AwsElasticBeanstalkApp>>>;
30843083
elasticBeanstalkEnvs?: Maybe<Array<Maybe<AwsElasticBeanstalkEnv>>>;
3084+
emrCluster?: Maybe<Array<Maybe<AwsEmrCluster>>>;
30853085
flowLogs?: Maybe<Array<Maybe<AwsFlowLog>>>;
30863086
glueJobs?: Maybe<Array<Maybe<AwsGlueJob>>>;
30873087
guardDutyDetectors?: Maybe<Array<Maybe<AwsGuardDutyDetector>>>;

0 commit comments

Comments
 (0)