Skip to content

Commit 4fdf50c

Browse files
committed
feat: Add cloudfront connection to cloudwatch service
1 parent 30dd364 commit 4fdf50c

4 files changed

Lines changed: 42 additions & 2 deletions

File tree

src/services/cloudfront/schema.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ type awsCloudfront implements awsBaseService @key(fields: "id") {
2121
s3: [awsS3] @hasInverse(field: cloudfrontDistributions)
2222
tags: [awsRawTag]
2323
webAcl: [awsWafV2WebAcl] @hasInverse(field: cloudfront)
24+
cloudwatch: [awsCloudwatch] @hasInverse(field: cloudfront)
2425
}
2526

2627
type awsCloudfrontOriginData {

src/services/cloudwatch/connections.ts

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { ServiceConnection } from '@cloudgraph/sdk'
22
import { isEmpty } from 'lodash'
33
import { RawAwsCloudwatch } from './data'
4+
import { RawAwsCloudfront } from '../cloudfront/data'
45
import services from '../../enums/services'
6+
import { globalRegionName } from '../../enums/regions'
57

68
export default ({
79
service: cloudwatch,
@@ -15,7 +17,11 @@ export default ({
1517
}): {
1618
[property: string]: ServiceConnection[]
1719
} => {
18-
const { AlarmName: id, AlarmActions: alarmActions } = cloudwatch
20+
const {
21+
AlarmName: id,
22+
AlarmActions: alarmActions,
23+
Dimensions: dimensions,
24+
} = cloudwatch
1925
const connections: ServiceConnection[] = []
2026

2127
/**
@@ -40,6 +46,32 @@ export default ({
4046
}
4147
}
4248

49+
/**
50+
* Find Cloudfront
51+
* related to the cloudwatch
52+
*/
53+
const cloudfronts = data.find(({ name }) => name === services.cloudfront)
54+
if (cloudfronts?.data?.[globalRegionName]) {
55+
const cloudfrontsInRegion: RawAwsCloudfront[] = cloudfronts.data[globalRegionName].filter(
56+
({ summary: { Id: cloudfrontId } }: RawAwsCloudfront) =>
57+
dimensions?.some(d => d.Value === cloudfrontId)
58+
)
59+
60+
if (!isEmpty(cloudfrontsInRegion)) {
61+
for (const cf of cloudfrontsInRegion) {
62+
const {
63+
summary: { Id: cloudfrontId },
64+
}: RawAwsCloudfront = cf
65+
connections.push({
66+
id: cloudfrontId,
67+
resourceType: services.cloudfront,
68+
relation: 'child',
69+
field: 'cloudfront',
70+
})
71+
}
72+
}
73+
}
74+
4375
const result = {
4476
[id]: connections,
4577
}

src/services/cloudwatch/schema.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ type awsCloudwatch implements awsBaseService @key(fields: "arn") {
1414
cloudwatchLog: [awsCloudwatchLog] @hasInverse(field: cloudwatch)
1515
sns: [awsSns] @hasInverse(field: cloudwatch)
1616
cloudtrail: [awsCloudtrail] @hasInverse(field: cloudwatch)
17+
cloudfront: [awsCloudfront] @hasInverse(field: cloudwatch)
1718
}
1819

1920
type awsCloudwatchDimensions

src/types/generated.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,7 @@ export type AwsCloudFormationStackSetParameter = {
742742

743743
export type AwsCloudfront = AwsBaseService & {
744744
callerReference?: Maybe<Scalars['String']>;
745+
cloudwatch?: Maybe<Array<Maybe<AwsCloudwatch>>>;
745746
customErrorResponses?: Maybe<Array<Maybe<AwsCloudfrontCustomErrorResponse>>>;
746747
defaultCacheBehavior?: Maybe<AwsCloudfrontCacheBehavior>;
747748
defaultRootObject?: Maybe<Scalars['String']>;
@@ -892,6 +893,7 @@ export type AwsCloudtrailStatus = {
892893
export type AwsCloudwatch = AwsBaseService & {
893894
actions?: Maybe<Array<Maybe<Scalars['String']>>>;
894895
actionsEnabled?: Maybe<Scalars['String']>;
896+
cloudfront?: Maybe<Array<Maybe<AwsCloudfront>>>;
895897
cloudtrail?: Maybe<Array<Maybe<AwsCloudtrail>>>;
896898
cloudwatchLog?: Maybe<Array<Maybe<AwsCloudwatchLog>>>;
897899
comparisonOperator?: Maybe<Scalars['String']>;
@@ -4212,8 +4214,12 @@ export type AwsTransitGateway = AwsBaseService & {
42124214
vpnEcmpSupport?: Maybe<Scalars['String']>;
42134215
};
42144216

4215-
export type AwsTransitGatewayAttachment = AwsBaseService & {
4217+
export type AwsTransitGatewayAttachment = {
4218+
accountId: Scalars['String'];
4219+
arn: Scalars['String'];
42164220
creationTime?: Maybe<Scalars['String']>;
4221+
id: Scalars['String'];
4222+
region?: Maybe<Scalars['String']>;
42174223
resourceId?: Maybe<Scalars['String']>;
42184224
resourceOwnerId?: Maybe<Scalars['String']>;
42194225
resourceType?: Maybe<Scalars['String']>;

0 commit comments

Comments
 (0)