Skip to content

Commit f0b6e94

Browse files
authored
Merge pull request #35 from cloudgraphdev/fix/CG-1067
fix: Added iamRole connections to emrCluster service
2 parents bc158a2 + 3920480 commit f0b6e94

6 files changed

Lines changed: 145 additions & 117 deletions

File tree

README.md

Lines changed: 94 additions & 94 deletions
Large diffs are not rendered by default.

src/services/emrCluster/connections.ts

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ 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'
7+
import { globalRegionName } from '../../enums/regions'
68

79
export default ({
8-
account,
910
service,
1011
data,
1112
region,
@@ -17,7 +18,13 @@ export default ({
1718
}): {
1819
[property: string]: ServiceConnection[]
1920
} => {
20-
const { ClusterArn: id, Ec2InstanceAttributes, LogEncryptionKmsKeyId } = service
21+
const {
22+
ClusterArn: id,
23+
Ec2InstanceAttributes,
24+
LogEncryptionKmsKeyId,
25+
ServiceRole,
26+
AutoScalingRole,
27+
} = service
2128
const connections: ServiceConnection[] = []
2229
const subnetId = Ec2InstanceAttributes?.Ec2SubnetId
2330

@@ -26,8 +33,8 @@ export default ({
2633
*/
2734
const kmsKeys = data.find(({ name }) => name === services.kms)
2835
if (kmsKeys?.data?.[region]) {
29-
const kmsKeyInRegion = kmsKeys.data[region].filter(kmsKey =>
30-
kmsKey.Arn === LogEncryptionKmsKeyId
36+
const kmsKeyInRegion = kmsKeys.data[region].filter(
37+
kmsKey => kmsKey.Arn === LogEncryptionKmsKeyId
3138
)
3239

3340
if (!isEmpty(kmsKeyInRegion)) {
@@ -66,8 +73,36 @@ export default ({
6673
}
6774
}
6875

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

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)