@gradientedge/cdk-utils 8.121.0 → 8.123.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/dist/src/lib/aws/common/construct.d.ts +0 -1
- package/dist/src/lib/aws/common/construct.js +6 -13
- package/dist/src/lib/aws/common/stack.js +7 -9
- package/dist/src/lib/aws/common/types.d.ts +2 -8
- package/dist/src/lib/aws/construct/api-to-any-target/main.js +24 -26
- package/dist/src/lib/aws/construct/api-to-eventbridge-target/main.js +85 -103
- package/dist/src/lib/aws/construct/api-to-eventbridge-target-with-sns/main.js +94 -120
- package/dist/src/lib/aws/construct/api-to-lambda-target/main.js +8 -10
- package/dist/src/lib/aws/construct/graphql-api-lambda/main.js +7 -3
- package/dist/src/lib/aws/construct/graphql-api-lambda-with-cache/main.js +5 -1
- package/dist/src/lib/aws/construct/lambda-with-iam-access/main.js +5 -1
- package/dist/src/lib/aws/construct/rest-api-lambda/main.js +7 -3
- package/dist/src/lib/aws/construct/rest-api-lambda-with-cache/main.js +5 -1
- package/dist/src/lib/aws/construct/site-with-ecs-backend/main.js +8 -6
- package/dist/src/lib/aws/construct/static-asset-deployment/main.js +5 -1
- package/dist/src/lib/aws/services/api-gateway/main.js +18 -10
- package/dist/src/lib/aws/services/cloudfront/main.js +11 -7
- package/dist/src/lib/aws/services/cloudwatch/logs.js +8 -4
- package/dist/src/lib/aws/services/cloudwatch/main.js +36 -78
- package/dist/src/lib/aws/services/dynamodb/main.js +6 -2
- package/dist/src/lib/aws/services/elastic-container-service/main.js +8 -4
- package/dist/src/lib/aws/services/elastic-file-system/main.js +5 -1
- package/dist/src/lib/aws/services/elasticache/main.js +6 -2
- package/dist/src/lib/aws/services/eventbridge/main.js +8 -4
- package/dist/src/lib/aws/services/lambda/main.js +7 -3
- package/dist/src/lib/aws/services/simple-notification-service/main.js +6 -2
- package/dist/src/lib/aws/services/simple-queue-service/main.js +6 -2
- package/dist/src/lib/aws/services/simple-storage-service/main.js +8 -4
- package/dist/src/lib/aws/services/step-function/main.js +52 -32
- package/dist/src/lib/aws/services/virtual-private-cloud/main.js +8 -4
- package/dist/src/lib/aws/types/index.d.ts +6 -1
- package/dist/src/lib/aws/types/index.js +0 -15
- package/dist/src/lib/aws/utils/index.d.ts +13 -23
- package/dist/src/lib/aws/utils/index.js +37 -46
- package/dist/src/lib/azure/common/construct.d.ts +35 -0
- package/dist/src/lib/azure/common/construct.js +49 -0
- package/dist/src/lib/azure/common/index.d.ts +3 -0
- package/dist/src/lib/azure/common/index.js +19 -0
- package/dist/src/lib/azure/common/stack.d.ts +52 -0
- package/dist/src/lib/azure/common/stack.js +134 -0
- package/dist/src/lib/azure/common/types.d.ts +7 -0
- package/dist/src/lib/azure/index.d.ts +4 -0
- package/dist/src/lib/azure/index.js +20 -0
- package/dist/src/lib/azure/services/index.d.ts +1 -0
- package/dist/src/lib/azure/services/index.js +17 -0
- package/dist/src/lib/azure/services/storage/index.d.ts +2 -0
- package/dist/src/lib/azure/services/storage/index.js +18 -0
- package/dist/src/lib/azure/services/storage/main.d.ts +43 -0
- package/dist/src/lib/azure/services/storage/main.js +124 -0
- package/dist/src/lib/azure/services/storage/types.d.ts +10 -0
- package/dist/src/lib/azure/services/storage/types.js +2 -0
- package/dist/src/lib/azure/types/index.d.ts +3 -0
- package/dist/src/lib/azure/types/index.js +2 -0
- package/dist/src/lib/azure/utils/index.d.ts +3 -0
- package/dist/src/lib/azure/utils/index.js +20 -0
- package/dist/src/lib/common/construct.d.ts +29 -0
- package/dist/src/lib/common/construct.js +8 -0
- package/dist/src/lib/common/index.d.ts +5 -0
- package/dist/src/lib/common/index.js +33 -0
- package/dist/src/lib/common/stack.d.ts +21 -0
- package/dist/src/lib/common/stack.js +8 -0
- package/dist/src/lib/common/types.d.ts +9 -0
- package/dist/src/lib/common/types.js +2 -0
- package/dist/src/lib/common/utils.d.ts +26 -0
- package/dist/src/lib/common/utils.js +34 -0
- package/dist/src/lib/index.d.ts +2 -0
- package/dist/src/lib/index.js +2 -0
- package/package.json +9 -7
- package/setup.js +2 -0
- package/src/lib/aws/common/construct.ts +2 -13
- package/src/lib/aws/common/stack.ts +6 -8
- package/src/lib/aws/common/types.ts +2 -8
- package/src/lib/aws/construct/api-to-any-target/main.ts +25 -27
- package/src/lib/aws/construct/api-to-eventbridge-target/main.ts +85 -103
- package/src/lib/aws/construct/api-to-eventbridge-target-with-sns/main.ts +94 -120
- package/src/lib/aws/construct/api-to-lambda-target/main.ts +8 -10
- package/src/lib/aws/construct/graphql-api-lambda/main.ts +4 -3
- package/src/lib/aws/construct/graphql-api-lambda-with-cache/main.ts +2 -1
- package/src/lib/aws/construct/lambda-with-iam-access/main.ts +2 -1
- package/src/lib/aws/construct/rest-api-lambda/main.ts +4 -3
- package/src/lib/aws/construct/rest-api-lambda-with-cache/main.ts +2 -1
- package/src/lib/aws/construct/site-with-ecs-backend/main.ts +8 -9
- package/src/lib/aws/construct/static-asset-deployment/main.ts +2 -1
- package/src/lib/aws/services/api-gateway/main.ts +9 -6
- package/src/lib/aws/services/cloudfront/main.ts +8 -7
- package/src/lib/aws/services/cloudwatch/logs.ts +6 -5
- package/src/lib/aws/services/cloudwatch/main.ts +35 -81
- package/src/lib/aws/services/dynamodb/main.ts +3 -2
- package/src/lib/aws/services/elastic-container-service/main.ts +5 -4
- package/src/lib/aws/services/elastic-file-system/main.ts +2 -1
- package/src/lib/aws/services/elasticache/main.ts +3 -2
- package/src/lib/aws/services/eventbridge/main.ts +5 -4
- package/src/lib/aws/services/lambda/main.ts +4 -3
- package/src/lib/aws/services/simple-notification-service/main.ts +3 -2
- package/src/lib/aws/services/simple-queue-service/main.ts +3 -2
- package/src/lib/aws/services/simple-storage-service/main.ts +5 -4
- package/src/lib/aws/services/step-function/main.ts +17 -16
- package/src/lib/aws/services/virtual-private-cloud/main.ts +5 -4
- package/src/lib/aws/types/index.ts +6 -1
- package/src/lib/aws/utils/index.ts +41 -29
- package/src/lib/azure/common/construct.ts +57 -0
- package/src/lib/azure/common/index.ts +3 -0
- package/src/lib/azure/common/stack.ts +143 -0
- package/src/lib/azure/common/types.ts +8 -0
- package/src/lib/azure/index.ts +4 -0
- package/src/lib/azure/services/index.ts +1 -0
- package/src/lib/azure/services/storage/index.ts +2 -0
- package/src/lib/azure/services/storage/main.ts +134 -0
- package/src/lib/azure/services/storage/types.ts +10 -0
- package/src/lib/azure/types/index.ts +3 -0
- package/src/lib/azure/utils/index.ts +23 -0
- package/src/lib/common/construct.ts +35 -0
- package/src/lib/common/index.ts +18 -0
- package/src/lib/common/stack.ts +26 -0
- package/src/lib/common/types.ts +9 -0
- package/src/lib/common/utils.ts +27 -0
- package/src/lib/index.ts +2 -0
- package/dist/src/lib/aws/types/aws/index.d.ts +0 -6
- package/dist/src/lib/aws/utils/aws/index.d.ts +0 -17
- package/dist/src/lib/aws/utils/aws/index.js +0 -40
- package/src/lib/aws/types/aws/index.ts +0 -6
- package/src/lib/aws/utils/aws/index.ts +0 -41
- /package/dist/src/lib/{aws/types/aws/index.js → azure/common/types.js} +0 -0
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
LayerVersion,
|
|
16
16
|
} from 'aws-cdk-lib/aws-lambda'
|
|
17
17
|
import { SqsEventSource } from 'aws-cdk-lib/aws-lambda-event-sources'
|
|
18
|
+
import _ from 'lodash'
|
|
18
19
|
import { CommonConstruct, CommonStack } from '../../common'
|
|
19
20
|
import { createCfnOutput } from '../../utils'
|
|
20
21
|
import { CloudFrontManager } from '../cloudfront'
|
|
@@ -144,7 +145,7 @@ export class LambdaManager {
|
|
|
144
145
|
)
|
|
145
146
|
}
|
|
146
147
|
|
|
147
|
-
if (props.lambdaAliases && props.lambdaAliases
|
|
148
|
+
if (props.lambdaAliases && !_.isEmpty(props.lambdaAliases)) {
|
|
148
149
|
props.lambdaAliases.forEach(alias => {
|
|
149
150
|
const aliasId = alias.id ?? `${id}-${alias.aliasName}`
|
|
150
151
|
const functionAlias = this.createLambdaFunctionAlias(`${aliasId}`, scope, alias, lambdaFunction.currentVersion)
|
|
@@ -160,8 +161,8 @@ export class LambdaManager {
|
|
|
160
161
|
})
|
|
161
162
|
}
|
|
162
163
|
|
|
163
|
-
if (props.tags && props.tags
|
|
164
|
-
props.tags
|
|
164
|
+
if (props.tags && !_.isEmpty(props.tags)) {
|
|
165
|
+
_.forEach(props.tags, tag => {
|
|
165
166
|
Tags.of(lambdaFunction).add(tag.key, tag.value)
|
|
166
167
|
})
|
|
167
168
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { IFunction } from 'aws-cdk-lib/aws-lambda'
|
|
2
2
|
import { Topic } from 'aws-cdk-lib/aws-sns'
|
|
3
3
|
import { EmailSubscription, LambdaSubscription } from 'aws-cdk-lib/aws-sns-subscriptions'
|
|
4
|
+
import _ from 'lodash'
|
|
4
5
|
import { CommonConstruct } from '../../common'
|
|
5
6
|
import { createCfnOutput } from '../../utils'
|
|
6
7
|
import { SubscriptionProps } from './types'
|
|
@@ -43,8 +44,8 @@ export class SnsManager {
|
|
|
43
44
|
topicName: `${props.topicName}-${scope.props.stage}`,
|
|
44
45
|
})
|
|
45
46
|
|
|
46
|
-
if (emails && emails
|
|
47
|
-
|
|
47
|
+
if (emails && !_.isEmpty(emails)) {
|
|
48
|
+
_.forEach(emails, (email: string) => topic.addSubscription(new EmailSubscription(email)))
|
|
48
49
|
}
|
|
49
50
|
|
|
50
51
|
createCfnOutput(`${id}-subscriptionArn`, scope, topic.topicArn)
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Duration, RemovalPolicy, Tags } from 'aws-cdk-lib'
|
|
2
2
|
import { IQueue, Queue } from 'aws-cdk-lib/aws-sqs'
|
|
3
|
+
import _ from 'lodash'
|
|
3
4
|
import { CommonConstruct } from '../../common'
|
|
4
5
|
import { createCfnOutput } from '../../utils'
|
|
5
6
|
import { LambdaProps } from '../lambda'
|
|
@@ -59,8 +60,8 @@ export class SqsManager {
|
|
|
59
60
|
: props.visibilityTimeout,
|
|
60
61
|
})
|
|
61
62
|
|
|
62
|
-
if (props.tags && props.tags
|
|
63
|
-
props.tags
|
|
63
|
+
if (props.tags && !_.isEmpty(props.tags)) {
|
|
64
|
+
_.forEach(props.tags, tag => {
|
|
64
65
|
Tags.of(queue).add(tag.key, tag.value)
|
|
65
66
|
})
|
|
66
67
|
}
|
|
@@ -3,6 +3,7 @@ import { IDistribution } from 'aws-cdk-lib/aws-cloudfront'
|
|
|
3
3
|
import { Effect, PolicyDocument, PolicyStatement, ServicePrincipal } from 'aws-cdk-lib/aws-iam'
|
|
4
4
|
import { BlockPublicAccess, Bucket, BucketEncryption, CfnBucket, CfnBucketPolicy, IBucket } from 'aws-cdk-lib/aws-s3'
|
|
5
5
|
import { BucketDeployment, ISource, ServerSideEncryption, Source } from 'aws-cdk-lib/aws-s3-deployment'
|
|
6
|
+
import _ from 'lodash'
|
|
6
7
|
import { CommonConstruct } from '../../common'
|
|
7
8
|
import { createCfnOutput } from '../../utils'
|
|
8
9
|
import { LifecycleRule, S3BucketProps } from './types'
|
|
@@ -32,7 +33,7 @@ export class S3Manager {
|
|
|
32
33
|
if (!props.lifecycleRules) return undefined
|
|
33
34
|
|
|
34
35
|
const bucketLifecycleRules: LifecycleRule[] = []
|
|
35
|
-
props.lifecycleRules
|
|
36
|
+
_.forEach(props.lifecycleRules, lifecycleRule => {
|
|
36
37
|
bucketLifecycleRules.push({
|
|
37
38
|
abortIncompleteMultipartUploadAfter: lifecycleRule.abortIncompleteMultipartUploadAfter,
|
|
38
39
|
enabled: lifecycleRule.enabled,
|
|
@@ -135,8 +136,8 @@ export class S3Manager {
|
|
|
135
136
|
}
|
|
136
137
|
}
|
|
137
138
|
|
|
138
|
-
if (props.tags && props.tags
|
|
139
|
-
props.tags
|
|
139
|
+
if (props.tags && !_.isEmpty(props.tags)) {
|
|
140
|
+
_.forEach(props.tags, tag => {
|
|
140
141
|
Tags.of(bucket).add(tag.key, tag.value)
|
|
141
142
|
})
|
|
142
143
|
}
|
|
@@ -222,7 +223,7 @@ export class S3Manager {
|
|
|
222
223
|
throw `Folder unspecified for ${id}`
|
|
223
224
|
}
|
|
224
225
|
|
|
225
|
-
|
|
226
|
+
_.forEach(folders, folder => {
|
|
226
227
|
new BucketDeployment(scope, `${id}-${folder}`, {
|
|
227
228
|
destinationBucket: bucket,
|
|
228
229
|
destinationKeyPrefix: folder,
|
|
@@ -30,6 +30,7 @@ import {
|
|
|
30
30
|
SqsSendMessage,
|
|
31
31
|
StepFunctionsStartExecution,
|
|
32
32
|
} from 'aws-cdk-lib/aws-stepfunctions-tasks'
|
|
33
|
+
import _ from 'lodash'
|
|
33
34
|
import { v4 as uuidv4 } from 'uuid'
|
|
34
35
|
import { CommonConstruct } from '../../common'
|
|
35
36
|
import { createCfnOutput } from '../../utils'
|
|
@@ -214,12 +215,12 @@ export class SfnManager {
|
|
|
214
215
|
retries = DEFAULT_RETRY_CONFIG
|
|
215
216
|
}
|
|
216
217
|
|
|
217
|
-
|
|
218
|
+
_.forEach(retries, retry => {
|
|
218
219
|
step.addRetry({
|
|
219
220
|
...retry,
|
|
220
221
|
...{ interval: retry.intervalInSecs ? Duration.seconds(retry.intervalInSecs) : retry.interval },
|
|
221
222
|
})
|
|
222
|
-
)
|
|
223
|
+
})
|
|
223
224
|
|
|
224
225
|
return step
|
|
225
226
|
}
|
|
@@ -267,12 +268,12 @@ export class SfnManager {
|
|
|
267
268
|
retries = DEFAULT_RETRY_CONFIG
|
|
268
269
|
}
|
|
269
270
|
|
|
270
|
-
|
|
271
|
+
_.forEach(retries, retry => {
|
|
271
272
|
step.addRetry({
|
|
272
273
|
...retry,
|
|
273
274
|
...{ interval: retry.intervalInSecs ? Duration.seconds(retry.intervalInSecs) : retry.interval },
|
|
274
275
|
})
|
|
275
|
-
)
|
|
276
|
+
})
|
|
276
277
|
|
|
277
278
|
return step
|
|
278
279
|
}
|
|
@@ -320,12 +321,12 @@ export class SfnManager {
|
|
|
320
321
|
retries = DEFAULT_RETRY_CONFIG
|
|
321
322
|
}
|
|
322
323
|
|
|
323
|
-
|
|
324
|
+
_.forEach(retries, retry => {
|
|
324
325
|
step.addRetry({
|
|
325
326
|
...retry,
|
|
326
327
|
...{ interval: retry.intervalInSecs ? Duration.seconds(retry.intervalInSecs) : retry.interval },
|
|
327
328
|
})
|
|
328
|
-
)
|
|
329
|
+
})
|
|
329
330
|
|
|
330
331
|
return step
|
|
331
332
|
}
|
|
@@ -364,12 +365,12 @@ export class SfnManager {
|
|
|
364
365
|
retries = DEFAULT_RETRY_CONFIG
|
|
365
366
|
}
|
|
366
367
|
|
|
367
|
-
|
|
368
|
+
_.forEach(retries, retry => {
|
|
368
369
|
step.addRetry({
|
|
369
370
|
...retry,
|
|
370
371
|
...{ interval: retry.intervalInSecs ? Duration.seconds(retry.intervalInSecs) : retry.interval },
|
|
371
372
|
})
|
|
372
|
-
)
|
|
373
|
+
})
|
|
373
374
|
|
|
374
375
|
return step
|
|
375
376
|
}
|
|
@@ -396,12 +397,12 @@ export class SfnManager {
|
|
|
396
397
|
retries = DEFAULT_RETRY_CONFIG
|
|
397
398
|
}
|
|
398
399
|
|
|
399
|
-
|
|
400
|
+
_.forEach(retries, retry => {
|
|
400
401
|
step.addRetry({
|
|
401
402
|
...retry,
|
|
402
403
|
...{ interval: retry.intervalInSecs ? Duration.seconds(retry.intervalInSecs) : retry.interval },
|
|
403
404
|
})
|
|
404
|
-
)
|
|
405
|
+
})
|
|
405
406
|
|
|
406
407
|
return step
|
|
407
408
|
}
|
|
@@ -436,12 +437,12 @@ export class SfnManager {
|
|
|
436
437
|
retries = DEFAULT_RETRY_CONFIG
|
|
437
438
|
}
|
|
438
439
|
|
|
439
|
-
|
|
440
|
+
_.forEach(retries, retry => {
|
|
440
441
|
step.addRetry({
|
|
441
442
|
...retry,
|
|
442
443
|
...{ interval: retry.intervalInSecs ? Duration.seconds(retry.intervalInSecs) : retry.interval },
|
|
443
444
|
})
|
|
444
|
-
)
|
|
445
|
+
})
|
|
445
446
|
|
|
446
447
|
return step
|
|
447
448
|
}
|
|
@@ -474,12 +475,12 @@ export class SfnManager {
|
|
|
474
475
|
retries = DEFAULT_RETRY_CONFIG
|
|
475
476
|
}
|
|
476
477
|
|
|
477
|
-
|
|
478
|
+
_.forEach(retries, retry => {
|
|
478
479
|
step.addRetry({
|
|
479
480
|
...retry,
|
|
480
481
|
...{ interval: retry.intervalInSecs ? Duration.seconds(retry.intervalInSecs) : retry.interval },
|
|
481
482
|
})
|
|
482
|
-
)
|
|
483
|
+
})
|
|
483
484
|
|
|
484
485
|
return step
|
|
485
486
|
}
|
|
@@ -510,12 +511,12 @@ export class SfnManager {
|
|
|
510
511
|
retries = DEFAULT_RETRY_CONFIG
|
|
511
512
|
}
|
|
512
513
|
|
|
513
|
-
|
|
514
|
+
_.forEach(retries, retry => {
|
|
514
515
|
step.addRetry({
|
|
515
516
|
...retry,
|
|
516
517
|
...{ interval: retry.intervalInSecs ? Duration.seconds(retry.intervalInSecs) : retry.interval },
|
|
517
518
|
})
|
|
518
|
-
)
|
|
519
|
+
})
|
|
519
520
|
|
|
520
521
|
return step
|
|
521
522
|
}
|
|
@@ -2,6 +2,7 @@ import { Tags } from 'aws-cdk-lib'
|
|
|
2
2
|
import { Vpc, VpcProps } from 'aws-cdk-lib/aws-ec2'
|
|
3
3
|
import { CommonConstruct } from '../../common'
|
|
4
4
|
import { createCfnOutput } from '../../utils'
|
|
5
|
+
import _ from 'lodash'
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
*/
|
|
@@ -38,17 +39,17 @@ export class VpcManager {
|
|
|
38
39
|
})
|
|
39
40
|
|
|
40
41
|
createCfnOutput(`${id}Id`, scope, vpc.vpcId)
|
|
41
|
-
createCfnOutput(`${id}PublicSubnetIds`, scope, vpc.publicSubnets
|
|
42
|
-
createCfnOutput(`${id}PrivateSubnetIds`, scope, vpc.privateSubnets
|
|
42
|
+
createCfnOutput(`${id}PublicSubnetIds`, scope, _.map(vpc.publicSubnets, subnet => subnet.subnetId).toString())
|
|
43
|
+
createCfnOutput(`${id}PrivateSubnetIds`, scope, _.map(vpc.privateSubnets, subnet => subnet.subnetId).toString())
|
|
43
44
|
createCfnOutput(
|
|
44
45
|
`${id}PublicSubnetRouteTableIds`,
|
|
45
46
|
scope,
|
|
46
|
-
vpc.publicSubnets
|
|
47
|
+
_.map(vpc.publicSubnets, subnet => subnet.routeTable.routeTableId).toString()
|
|
47
48
|
)
|
|
48
49
|
createCfnOutput(
|
|
49
50
|
`${id}PrivateSubnetRouteTableIds`,
|
|
50
51
|
scope,
|
|
51
|
-
vpc.privateSubnets
|
|
52
|
+
_.map(vpc.privateSubnets, subnet => subnet.routeTable.routeTableId).toString()
|
|
52
53
|
)
|
|
53
54
|
createCfnOutput(`${id}AvailabilityZones`, scope, vpc.availabilityZones.toString())
|
|
54
55
|
createCfnOutput(`${id}DefaultSecurityGroup`, scope, vpc.vpcDefaultSecurityGroup.toString())
|
|
@@ -1,43 +1,55 @@
|
|
|
1
|
-
|
|
1
|
+
import { fromEnv, fromIni } from '@aws-sdk/credential-providers'
|
|
2
|
+
import { AwsCredentialIdentityProvider } from '@aws-sdk/types'
|
|
3
|
+
import { CfnOutput } from 'aws-cdk-lib'
|
|
4
|
+
import _ from 'lodash'
|
|
5
|
+
import { CommonConstruct } from '../common'
|
|
2
6
|
|
|
3
7
|
/**
|
|
8
|
+
* @summary Helper method to add CloudFormation outputs from the construct
|
|
9
|
+
* @param id scoped id of the resource
|
|
10
|
+
* @param scope scope in which this resource is defined
|
|
11
|
+
* @param value the value of the exported output
|
|
12
|
+
* @param description optional description for the output
|
|
13
|
+
* @param overrideId Flag which indicates whether to override the default logical id of the output
|
|
14
|
+
* @returns The CloudFormation output
|
|
4
15
|
*/
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
16
|
+
export function createCfnOutput(
|
|
17
|
+
id: string,
|
|
18
|
+
scope: CommonConstruct,
|
|
19
|
+
value?: string,
|
|
20
|
+
description?: string,
|
|
21
|
+
overrideId = true
|
|
22
|
+
): CfnOutput {
|
|
23
|
+
const camelName = _.camelCase(id)
|
|
24
|
+
const output = new CfnOutput(scope, id, {
|
|
25
|
+
description,
|
|
26
|
+
exportName: `${scope.props.stackName}-${camelName}`,
|
|
27
|
+
value: value ?? '',
|
|
28
|
+
})
|
|
29
|
+
if (overrideId) {
|
|
30
|
+
output.overrideLogicalId(camelName)
|
|
31
|
+
}
|
|
32
|
+
return output
|
|
12
33
|
}
|
|
13
34
|
|
|
14
35
|
/**
|
|
36
|
+
*
|
|
15
37
|
*/
|
|
16
|
-
export
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
WARNING = 'WARNING',
|
|
20
|
-
TRACE = 'TRACE',
|
|
21
|
-
ERROR = 'ERROR',
|
|
22
|
-
CRITICAL = 'CRITICAL',
|
|
38
|
+
export function determineCredentials(): AwsCredentialIdentityProvider {
|
|
39
|
+
if (process.env.AWS_PROFILE) return fromIni()
|
|
40
|
+
return fromEnv()
|
|
23
41
|
}
|
|
24
42
|
|
|
25
43
|
/**
|
|
26
|
-
* @param stage
|
|
27
|
-
*/
|
|
28
|
-
export const isDevStage = (stage: string) => stage === 'dev'
|
|
29
|
-
/**
|
|
30
|
-
* @param stage
|
|
31
|
-
*/
|
|
32
|
-
export const isTestStage = (stage: string) => stage === 'tst'
|
|
33
|
-
/**
|
|
34
|
-
* @param stage
|
|
35
|
-
*/
|
|
36
|
-
export const isUatStage = (stage: string) => stage === 'uat'
|
|
37
|
-
/**
|
|
38
|
-
* @param stage
|
|
39
44
|
*/
|
|
40
|
-
|
|
45
|
+
const defaultResponseObject = {
|
|
46
|
+
body: '',
|
|
47
|
+
headers: {
|
|
48
|
+
'Access-Control-Allow-Origin': '*',
|
|
49
|
+
},
|
|
50
|
+
isBase64Encoded: false,
|
|
51
|
+
statusCode: 200,
|
|
52
|
+
}
|
|
41
53
|
|
|
42
54
|
/**
|
|
43
55
|
* @param error
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { AzurermProvider } from '@cdktf/provider-azurerm/lib/provider'
|
|
2
|
+
import { TerraformStack } from 'cdktf'
|
|
3
|
+
import { Construct } from 'constructs'
|
|
4
|
+
import { isDevStage, isPrdStage, isTestStage, isUatStage } from '../../common'
|
|
5
|
+
import { AzureStorageManager } from '../services'
|
|
6
|
+
import { CommonAzureStackProps } from './types'
|
|
7
|
+
|
|
8
|
+
export class CommonAzureConstruct extends TerraformStack {
|
|
9
|
+
declare props: CommonAzureStackProps
|
|
10
|
+
id: string
|
|
11
|
+
fullyQualifiedDomainName: string
|
|
12
|
+
storageManager: AzureStorageManager
|
|
13
|
+
|
|
14
|
+
constructor(scope: Construct, id: string, props: CommonAzureStackProps) {
|
|
15
|
+
super(scope, id)
|
|
16
|
+
this.props = props
|
|
17
|
+
this.id = id
|
|
18
|
+
|
|
19
|
+
this.storageManager = new AzureStorageManager()
|
|
20
|
+
|
|
21
|
+
this.determineFullyQualifiedDomain()
|
|
22
|
+
new AzurermProvider(this, `${this.id}-provider`, this.props)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @summary Determine the fully qualified domain name based on domainName & subDomain
|
|
27
|
+
*/
|
|
28
|
+
protected determineFullyQualifiedDomain(): void {
|
|
29
|
+
this.fullyQualifiedDomainName = this.props.subDomain
|
|
30
|
+
? `${this.props.subDomain}.${this.props.domainName}`
|
|
31
|
+
: this.props.domainName
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* @summary Utility method to determine if the initialisation is in development (dev) stage
|
|
36
|
+
* This is determined by the stage property injected via cdk context
|
|
37
|
+
*/
|
|
38
|
+
public isDevelopmentStage = () => isDevStage(this.props.stage)
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* @summary Utility method to determine if the initialisation is in test (tst) stage
|
|
42
|
+
* This is determined by the stage property injected via cdk context
|
|
43
|
+
*/
|
|
44
|
+
public isTestStage = () => isTestStage(this.props.stage)
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* @summary Utility method to determine if the initialisation is in uat (uat) stage
|
|
48
|
+
* This is determined by the stage property injected via cdk context
|
|
49
|
+
*/
|
|
50
|
+
public isUatStage = () => isUatStage(this.props.stage)
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* @summary Utility method to determine if the initialisation is in production (prd) stage
|
|
54
|
+
* This is determined by the stage property injected via cdk context
|
|
55
|
+
*/
|
|
56
|
+
public isProductionStage = () => isPrdStage(this.props.stage)
|
|
57
|
+
}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import fs from 'fs'
|
|
2
|
+
import { CommonAzureConstruct } from './construct'
|
|
3
|
+
import { CommonAzureStackProps } from './types'
|
|
4
|
+
|
|
5
|
+
import appRoot from 'app-root-path'
|
|
6
|
+
import { TerraformStack } from 'cdktf'
|
|
7
|
+
import { Construct } from 'constructs'
|
|
8
|
+
import _ from 'lodash'
|
|
9
|
+
import { isDevStage } from '../../common'
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @classdesc Common stack to use as a base for all higher level constructs.
|
|
13
|
+
* @example
|
|
14
|
+
* import { CommonAzureStack } from '@gradientedge/cdk-utils'
|
|
15
|
+
*
|
|
16
|
+
* class CustomStack extends CommonAzureStack {
|
|
17
|
+
* constructor(parent: App, name: string, props: StackProps) {
|
|
18
|
+
* super(parent, name, props)
|
|
19
|
+
* // provision resources
|
|
20
|
+
* }
|
|
21
|
+
* }
|
|
22
|
+
*/
|
|
23
|
+
export class CommonAzureStack extends TerraformStack {
|
|
24
|
+
construct: CommonAzureConstruct
|
|
25
|
+
props: CommonAzureStackProps
|
|
26
|
+
|
|
27
|
+
constructor(parent: Construct, name: string, props: CommonAzureStackProps) {
|
|
28
|
+
super(parent, name)
|
|
29
|
+
|
|
30
|
+
/* determine extra cdk contexts */
|
|
31
|
+
this.determineExtraContexts()
|
|
32
|
+
|
|
33
|
+
/* determine extra cdk stage contexts */
|
|
34
|
+
this.determineStageContexts()
|
|
35
|
+
|
|
36
|
+
this.props = this.determineConstructProps(props)
|
|
37
|
+
|
|
38
|
+
/* initialise the construct */
|
|
39
|
+
this.construct = new CommonAzureConstruct(this, 'cdk-utils', this.props)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* @summary Method to determine the core CDK construct properties injected via context cdktf.json
|
|
44
|
+
* @param props The stack properties
|
|
45
|
+
* @returns The stack properties
|
|
46
|
+
*/
|
|
47
|
+
protected determineConstructProps(props: CommonAzureStackProps) {
|
|
48
|
+
return {
|
|
49
|
+
domainName: this.node.tryGetContext('domainName'),
|
|
50
|
+
extraContexts: this.node.tryGetContext('extraContexts'),
|
|
51
|
+
features: this.node.tryGetContext('features'),
|
|
52
|
+
name: this.node.tryGetContext('resourceGroupName'),
|
|
53
|
+
resourceGroupName: this.node.tryGetContext('resourceGroupName'),
|
|
54
|
+
skipStageForARecords: this.node.tryGetContext('skipStageForARecords'),
|
|
55
|
+
stage: this.node.tryGetContext('stage'),
|
|
56
|
+
subDomain: this.node.tryGetContext('subDomain'),
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* @summary Method to determine extra cdk contexts apart from the main cdktf.json
|
|
62
|
+
* - Sets the properties from the extra contexts into cdk node context
|
|
63
|
+
* - Primary use is to have layered config in separate files to enable easier maintenance and readability
|
|
64
|
+
*/
|
|
65
|
+
protected determineExtraContexts() {
|
|
66
|
+
const extraContexts = this.node.tryGetContext('extraContexts')
|
|
67
|
+
const debug = this.node.tryGetContext('debug')
|
|
68
|
+
|
|
69
|
+
if (!extraContexts) {
|
|
70
|
+
if (debug) console.debug(`No additional contexts provided. Using default context properties from cdktf.json`)
|
|
71
|
+
return
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
_.forEach(extraContexts, (context: string) => {
|
|
75
|
+
const extraContextPath = `${appRoot.path}/${context}`
|
|
76
|
+
|
|
77
|
+
/* scenario where extra context is configured in cdk.json but absent in file system */
|
|
78
|
+
if (!fs.existsSync(extraContextPath)) throw `Extra context properties unavailable in path:${extraContextPath}`
|
|
79
|
+
|
|
80
|
+
/* read the extra properties */
|
|
81
|
+
const extraContextPropsBuffer = fs.readFileSync(extraContextPath)
|
|
82
|
+
if (debug) console.debug(`Adding additional contexts provided in ${extraContextPath}`)
|
|
83
|
+
|
|
84
|
+
/* parse as JSON properties */
|
|
85
|
+
const extraContextProps = JSON.parse(extraContextPropsBuffer.toString('utf-8'))
|
|
86
|
+
|
|
87
|
+
/* set each of the property into the cdk node context */
|
|
88
|
+
_.keys(extraContextProps).forEach((propKey: any) => {
|
|
89
|
+
this.node.setContext(propKey, extraContextProps[propKey])
|
|
90
|
+
})
|
|
91
|
+
})
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* @summary Method to determine extra cdk stage contexts apart from the main cdktf.json
|
|
96
|
+
* - Sets the properties from the extra stage contexts into cdk node context
|
|
97
|
+
* - Primary use is to have layered config for each environment which is injected into the context
|
|
98
|
+
*/
|
|
99
|
+
protected determineStageContexts() {
|
|
100
|
+
const stage = this.node.tryGetContext('stage')
|
|
101
|
+
const stageContextPath = this.node.tryGetContext('stageContextPath') || 'cdkEnv'
|
|
102
|
+
const stageContextFilePath = `${appRoot.path}/${stageContextPath}/${stage}.json`
|
|
103
|
+
const debug = this.node.tryGetContext('debug')
|
|
104
|
+
|
|
105
|
+
if (isDevStage(stage)) {
|
|
106
|
+
if (debug) console.debug(`Development stage. Using default stage context properties`)
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/* alert default context usage when extra stage config is missing */
|
|
110
|
+
if (!fs.existsSync(stageContextFilePath)) {
|
|
111
|
+
if (debug) console.debug(`Stage specific context properties unavailable in path:${stageContextFilePath}`)
|
|
112
|
+
if (debug) console.debug(`Using default stage context properties for ${stage} stage`)
|
|
113
|
+
return
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/* read the extra properties */
|
|
117
|
+
const stageContextPropsBuffer = fs.readFileSync(stageContextFilePath)
|
|
118
|
+
if (debug) console.debug(`Adding additional stage contexts provided in ${stageContextFilePath}`)
|
|
119
|
+
|
|
120
|
+
/* parse as JSON properties */
|
|
121
|
+
const stageContextProps = JSON.parse(stageContextPropsBuffer.toString('utf-8'))
|
|
122
|
+
|
|
123
|
+
/* set each of the property into the cdk node context */
|
|
124
|
+
_.keys(stageContextProps).forEach((propKey: any) => {
|
|
125
|
+
/* handle object, array properties */
|
|
126
|
+
if (typeof stageContextProps[propKey] === 'object' && !Array.isArray(stageContextProps[propKey])) {
|
|
127
|
+
this.node.setContext(propKey, _.merge(this.node.tryGetContext(propKey), stageContextProps[propKey]))
|
|
128
|
+
} else {
|
|
129
|
+
/* handle all other primitive properties */
|
|
130
|
+
this.node.setContext(propKey, stageContextProps[propKey])
|
|
131
|
+
}
|
|
132
|
+
})
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* @summary Determine the fully qualified domain name based on domainName & subDomain
|
|
137
|
+
*/
|
|
138
|
+
protected fullyQualifiedDomain() {
|
|
139
|
+
const domainName = this.node.tryGetContext('domainName')
|
|
140
|
+
const subDomain = this.node.tryGetContext('subDomain')
|
|
141
|
+
return subDomain ? `${subDomain}.${domainName}` : domainName
|
|
142
|
+
}
|
|
143
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './storage'
|