@gradientedge/cdk-utils 8.134.0 → 8.136.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.
Files changed (50) hide show
  1. package/dist/src/lib/aws/construct/site-with-lambda-backend/constants.d.ts +1 -1
  2. package/dist/src/lib/aws/construct/site-with-lambda-backend/constants.js +1 -1
  3. package/dist/src/lib/azure/services/storage/main.d.ts +3 -1
  4. package/dist/src/lib/azure/services/storage/main.js +12 -10
  5. package/dist/src/lib/azure/services/storage/types.d.ts +3 -3
  6. package/dist/src/lib/azure/types/index.d.ts +1 -1
  7. package/dist/src/lib/azure/utils/index.d.ts +1 -1
  8. package/dist/src/lib/azure/utils/index.js +3 -3
  9. package/dist/src/lib/cloudflare/common/construct.d.ts +35 -0
  10. package/dist/src/lib/cloudflare/common/construct.js +49 -0
  11. package/dist/src/lib/cloudflare/common/index.d.ts +3 -0
  12. package/dist/src/lib/cloudflare/common/index.js +19 -0
  13. package/dist/src/lib/cloudflare/common/stack.d.ts +52 -0
  14. package/dist/src/lib/cloudflare/common/stack.js +134 -0
  15. package/dist/src/lib/cloudflare/common/types.d.ts +7 -0
  16. package/dist/src/lib/cloudflare/common/types.js +2 -0
  17. package/dist/src/lib/cloudflare/index.d.ts +4 -0
  18. package/dist/src/lib/cloudflare/index.js +20 -0
  19. package/dist/src/lib/cloudflare/services/index.d.ts +1 -0
  20. package/dist/src/lib/cloudflare/services/index.js +17 -0
  21. package/dist/src/lib/cloudflare/services/zone/index.d.ts +2 -0
  22. package/dist/src/lib/cloudflare/services/zone/index.js +18 -0
  23. package/dist/src/lib/cloudflare/services/zone/main.d.ts +29 -0
  24. package/dist/src/lib/cloudflare/services/zone/main.js +44 -0
  25. package/dist/src/lib/cloudflare/services/zone/types.d.ts +3 -0
  26. package/dist/src/lib/cloudflare/services/zone/types.js +2 -0
  27. package/dist/src/lib/cloudflare/types/index.d.ts +3 -0
  28. package/dist/src/lib/cloudflare/types/index.js +2 -0
  29. package/dist/src/lib/cloudflare/utils/index.d.ts +3 -0
  30. package/dist/src/lib/cloudflare/utils/index.js +20 -0
  31. package/dist/src/lib/index.d.ts +1 -0
  32. package/dist/src/lib/index.js +1 -0
  33. package/package.json +12 -10
  34. package/src/lib/aws/construct/site-with-lambda-backend/constants.ts +1 -1
  35. package/src/lib/azure/services/storage/main.ts +13 -11
  36. package/src/lib/azure/services/storage/types.ts +3 -3
  37. package/src/lib/azure/types/index.ts +1 -1
  38. package/src/lib/azure/utils/index.ts +1 -1
  39. package/src/lib/cloudflare/common/construct.ts +57 -0
  40. package/src/lib/cloudflare/common/index.ts +3 -0
  41. package/src/lib/cloudflare/common/stack.ts +143 -0
  42. package/src/lib/cloudflare/common/types.ts +8 -0
  43. package/src/lib/cloudflare/index.ts +4 -0
  44. package/src/lib/cloudflare/services/index.ts +1 -0
  45. package/src/lib/cloudflare/services/zone/index.ts +2 -0
  46. package/src/lib/cloudflare/services/zone/main.ts +44 -0
  47. package/src/lib/cloudflare/services/zone/types.ts +3 -0
  48. package/src/lib/cloudflare/types/index.ts +3 -0
  49. package/src/lib/cloudflare/utils/index.ts +23 -0
  50. package/src/lib/index.ts +1 -0
@@ -2,4 +2,4 @@ export declare enum SiteWithLambdaBackendResponseHeaderPolicyType {
2
2
  ORIGIN = "origin",
3
3
  STATIC = "static"
4
4
  }
5
- export declare const LAMBDA_ALIAS_NAME_CURRENT = "current";
5
+ export declare const LAMBDA_ALIAS_NAME_CURRENT = "latest";
@@ -6,4 +6,4 @@ var SiteWithLambdaBackendResponseHeaderPolicyType;
6
6
  SiteWithLambdaBackendResponseHeaderPolicyType["ORIGIN"] = "origin";
7
7
  SiteWithLambdaBackendResponseHeaderPolicyType["STATIC"] = "static";
8
8
  })(SiteWithLambdaBackendResponseHeaderPolicyType || (exports.SiteWithLambdaBackendResponseHeaderPolicyType = SiteWithLambdaBackendResponseHeaderPolicyType = {}));
9
- exports.LAMBDA_ALIAS_NAME_CURRENT = 'current';
9
+ exports.LAMBDA_ALIAS_NAME_CURRENT = 'latest';
@@ -15,7 +15,6 @@ import { StorageAccountProps, StorageBlobProps, StorageContainerProps } from './
15
15
  * this.storageManager.createStorageAccount('MyAccount', this, props)
16
16
  * }
17
17
  * }
18
- * @see [CDKTF S3 Module]{@link https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_s3-readme.html}
19
18
  * ```
20
19
  */
21
20
  export declare class AzureStorageManager {
@@ -24,6 +23,7 @@ export declare class AzureStorageManager {
24
23
  * @param id scoped id of the resource
25
24
  * @param scope scope in which this resource is defined
26
25
  * @param props storage account properties
26
+ * @see [CDKTF Storage Account Module]{@link https://github.com/cdktf/cdktf-provider-azurerm/blob/main/docs/storageAccount.typescript.md}
27
27
  */
28
28
  createStorageAccount(id: string, scope: CommonAzureConstruct, props: StorageAccountProps): void;
29
29
  /**
@@ -31,6 +31,7 @@ export declare class AzureStorageManager {
31
31
  * @param id scoped id of the resource
32
32
  * @param scope scope in which this resource is defined
33
33
  * @param props storage container properties
34
+ * @see [CDKTF Storage Container Module]{@link https://github.com/cdktf/cdktf-provider-azurerm/blob/main/docs/storageContainer.typescript.md}
34
35
  */
35
36
  createStorageContainer(id: string, scope: CommonAzureConstruct, props: StorageContainerProps): void;
36
37
  /**
@@ -38,6 +39,7 @@ export declare class AzureStorageManager {
38
39
  * @param id scoped id of the resource
39
40
  * @param scope scope in which this resource is defined
40
41
  * @param props storage blob properties
42
+ * @see [CDKTF Storage Blob Module]{@link https://github.com/cdktf/cdktf-provider-azurerm/blob/main/docs/storageBlob.typescript.md}
41
43
  */
42
44
  createStorageBlob(id: string, scope: CommonAzureConstruct, props: StorageBlobProps): void;
43
45
  }
@@ -23,7 +23,6 @@ const utils_1 = require("../../utils");
23
23
  * this.storageManager.createStorageAccount('MyAccount', this, props)
24
24
  * }
25
25
  * }
26
- * @see [CDKTF S3 Module]{@link https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_s3-readme.html}
27
26
  * ```
28
27
  */
29
28
  class AzureStorageManager {
@@ -32,6 +31,7 @@ class AzureStorageManager {
32
31
  * @param id scoped id of the resource
33
32
  * @param scope scope in which this resource is defined
34
33
  * @param props storage account properties
34
+ * @see [CDKTF Storage Account Module]{@link https://github.com/cdktf/cdktf-provider-azurerm/blob/main/docs/storageAccount.typescript.md}
35
35
  */
36
36
  createStorageAccount(id, scope, props) {
37
37
  if (!props)
@@ -53,15 +53,16 @@ class AzureStorageManager {
53
53
  environment: scope.props.stage,
54
54
  },
55
55
  });
56
- (0, utils_1.createTfOutput)(`${id}-storageAccountName`, scope, storageAccount.name);
57
- (0, utils_1.createTfOutput)(`${id}-storageAccountFriendlyUniqueId`, scope, storageAccount.friendlyUniqueId);
58
- (0, utils_1.createTfOutput)(`${id}-storageAccountId`, scope, storageAccount.id);
56
+ (0, utils_1.createAzureTfOutput)(`${id}-storageAccountName`, scope, storageAccount.name);
57
+ (0, utils_1.createAzureTfOutput)(`${id}-storageAccountFriendlyUniqueId`, scope, storageAccount.friendlyUniqueId);
58
+ (0, utils_1.createAzureTfOutput)(`${id}-storageAccountId`, scope, storageAccount.id);
59
59
  }
60
60
  /**
61
61
  * @summary Method to create a new storage container
62
62
  * @param id scoped id of the resource
63
63
  * @param scope scope in which this resource is defined
64
64
  * @param props storage container properties
65
+ * @see [CDKTF Storage Container Module]{@link https://github.com/cdktf/cdktf-provider-azurerm/blob/main/docs/storageContainer.typescript.md}
65
66
  */
66
67
  createStorageContainer(id, scope, props) {
67
68
  if (!props)
@@ -82,15 +83,16 @@ class AzureStorageManager {
82
83
  name: `${props.name}-${scope.props.stage}`,
83
84
  storageAccountName: storageAccount.name,
84
85
  });
85
- (0, utils_1.createTfOutput)(`${id}-storageContainerName`, scope, storageContainer.name);
86
- (0, utils_1.createTfOutput)(`${id}-storageContainerFriendlyUniqueId`, scope, storageContainer.friendlyUniqueId);
87
- (0, utils_1.createTfOutput)(`${id}-storageContainerId`, scope, storageContainer.id);
86
+ (0, utils_1.createAzureTfOutput)(`${id}-storageContainerName`, scope, storageContainer.name);
87
+ (0, utils_1.createAzureTfOutput)(`${id}-storageContainerFriendlyUniqueId`, scope, storageContainer.friendlyUniqueId);
88
+ (0, utils_1.createAzureTfOutput)(`${id}-storageContainerId`, scope, storageContainer.id);
88
89
  }
89
90
  /**
90
91
  * @summary Method to create a new storage blob
91
92
  * @param id scoped id of the resource
92
93
  * @param scope scope in which this resource is defined
93
94
  * @param props storage blob properties
95
+ * @see [CDKTF Storage Blob Module]{@link https://github.com/cdktf/cdktf-provider-azurerm/blob/main/docs/storageBlob.typescript.md}
94
96
  */
95
97
  createStorageBlob(id, scope, props) {
96
98
  if (!props)
@@ -116,9 +118,9 @@ class AzureStorageManager {
116
118
  storageAccountName: storageAccount.name,
117
119
  storageContainerName: storageContainer.name,
118
120
  });
119
- (0, utils_1.createTfOutput)(`${id}-storageBlobName`, scope, storageBlob.name);
120
- (0, utils_1.createTfOutput)(`${id}-storageBlobFriendlyUniqueId`, scope, storageBlob.friendlyUniqueId);
121
- (0, utils_1.createTfOutput)(`${id}-storageBlobId`, scope, storageBlob.id);
121
+ (0, utils_1.createAzureTfOutput)(`${id}-storageBlobName`, scope, storageBlob.name);
122
+ (0, utils_1.createAzureTfOutput)(`${id}-storageBlobFriendlyUniqueId`, scope, storageBlob.friendlyUniqueId);
123
+ (0, utils_1.createAzureTfOutput)(`${id}-storageBlobId`, scope, storageBlob.id);
122
124
  }
123
125
  }
124
126
  exports.AzureStorageManager = AzureStorageManager;
@@ -1,10 +1,10 @@
1
1
  import { StorageAccountConfig } from '@cdktf/provider-azurerm/lib/storage-account';
2
2
  import { StorageBlobConfig } from '@cdktf/provider-azurerm/lib/storage-blob';
3
3
  import { StorageContainerConfig } from '@cdktf/provider-azurerm/lib/storage-container';
4
- import { BaseConfigProps } from '../../types';
4
+ import { BaseAzureConfigProps } from '../../types';
5
5
  export interface StorageAccountProps extends StorageAccountConfig {
6
6
  }
7
- export interface StorageContainerProps extends BaseConfigProps, StorageContainerConfig {
7
+ export interface StorageContainerProps extends BaseAzureConfigProps, StorageContainerConfig {
8
8
  }
9
- export interface StorageBlobProps extends BaseConfigProps, StorageBlobConfig {
9
+ export interface StorageBlobProps extends BaseAzureConfigProps, StorageBlobConfig {
10
10
  }
@@ -1,3 +1,3 @@
1
- export interface BaseConfigProps {
1
+ export interface BaseAzureConfigProps {
2
2
  resourceGroupName: string;
3
3
  }
@@ -1,3 +1,3 @@
1
1
  import { TerraformOutput } from 'cdktf';
2
2
  import { CommonAzureConstruct } from '../common';
3
- export declare const createTfOutput: (id: string, scope: CommonAzureConstruct, value?: string, description?: string, sensitive?: boolean, overrideId?: boolean) => TerraformOutput;
3
+ export declare const createAzureTfOutput: (id: string, scope: CommonAzureConstruct, value?: string, description?: string, sensitive?: boolean, overrideId?: boolean) => TerraformOutput;
@@ -3,10 +3,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.createTfOutput = void 0;
6
+ exports.createAzureTfOutput = void 0;
7
7
  const cdktf_1 = require("cdktf");
8
8
  const lodash_1 = __importDefault(require("lodash"));
9
- const createTfOutput = (id, scope, value, description, sensitive, overrideId = true) => {
9
+ const createAzureTfOutput = (id, scope, value, description, sensitive, overrideId = true) => {
10
10
  const output = new cdktf_1.TerraformOutput(scope, id, {
11
11
  description,
12
12
  sensitive,
@@ -17,4 +17,4 @@ const createTfOutput = (id, scope, value, description, sensitive, overrideId = t
17
17
  }
18
18
  return output;
19
19
  };
20
- exports.createTfOutput = createTfOutput;
20
+ exports.createAzureTfOutput = createAzureTfOutput;
@@ -0,0 +1,35 @@
1
+ import { TerraformStack } from 'cdktf';
2
+ import { Construct } from 'constructs';
3
+ import { CloudflareZoneManager } from '../services';
4
+ import { CommonCloudflareStackProps } from './types';
5
+ export declare class CommonCloudflareConstruct extends TerraformStack {
6
+ props: CommonCloudflareStackProps;
7
+ id: string;
8
+ fullyQualifiedDomainName: string;
9
+ zoneManager: CloudflareZoneManager;
10
+ constructor(scope: Construct, id: string, props: CommonCloudflareStackProps);
11
+ /**
12
+ * @summary Determine the fully qualified domain name based on domainName & subDomain
13
+ */
14
+ protected determineFullyQualifiedDomain(): void;
15
+ /**
16
+ * @summary Utility method to determine if the initialisation is in development (dev) stage
17
+ * This is determined by the stage property injected via cdk context
18
+ */
19
+ isDevelopmentStage: () => boolean;
20
+ /**
21
+ * @summary Utility method to determine if the initialisation is in test (tst) stage
22
+ * This is determined by the stage property injected via cdk context
23
+ */
24
+ isTestStage: () => boolean;
25
+ /**
26
+ * @summary Utility method to determine if the initialisation is in uat (uat) stage
27
+ * This is determined by the stage property injected via cdk context
28
+ */
29
+ isUatStage: () => boolean;
30
+ /**
31
+ * @summary Utility method to determine if the initialisation is in production (prd) stage
32
+ * This is determined by the stage property injected via cdk context
33
+ */
34
+ isProductionStage: () => boolean;
35
+ }
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CommonCloudflareConstruct = void 0;
4
+ const provider_1 = require("@cdktf/provider-cloudflare/lib/provider");
5
+ const cdktf_1 = require("cdktf");
6
+ const common_1 = require("../../common");
7
+ const services_1 = require("../services");
8
+ class CommonCloudflareConstruct extends cdktf_1.TerraformStack {
9
+ id;
10
+ fullyQualifiedDomainName;
11
+ zoneManager;
12
+ constructor(scope, id, props) {
13
+ super(scope, id);
14
+ this.props = props;
15
+ this.id = id;
16
+ this.zoneManager = new services_1.CloudflareZoneManager();
17
+ this.determineFullyQualifiedDomain();
18
+ new provider_1.CloudflareProvider(this, `${this.id}-provider`, this.props);
19
+ }
20
+ /**
21
+ * @summary Determine the fully qualified domain name based on domainName & subDomain
22
+ */
23
+ determineFullyQualifiedDomain() {
24
+ this.fullyQualifiedDomainName = this.props.subDomain
25
+ ? `${this.props.subDomain}.${this.props.domainName}`
26
+ : this.props.domainName;
27
+ }
28
+ /**
29
+ * @summary Utility method to determine if the initialisation is in development (dev) stage
30
+ * This is determined by the stage property injected via cdk context
31
+ */
32
+ isDevelopmentStage = () => (0, common_1.isDevStage)(this.props.stage);
33
+ /**
34
+ * @summary Utility method to determine if the initialisation is in test (tst) stage
35
+ * This is determined by the stage property injected via cdk context
36
+ */
37
+ isTestStage = () => (0, common_1.isTestStage)(this.props.stage);
38
+ /**
39
+ * @summary Utility method to determine if the initialisation is in uat (uat) stage
40
+ * This is determined by the stage property injected via cdk context
41
+ */
42
+ isUatStage = () => (0, common_1.isUatStage)(this.props.stage);
43
+ /**
44
+ * @summary Utility method to determine if the initialisation is in production (prd) stage
45
+ * This is determined by the stage property injected via cdk context
46
+ */
47
+ isProductionStage = () => (0, common_1.isPrdStage)(this.props.stage);
48
+ }
49
+ exports.CommonCloudflareConstruct = CommonCloudflareConstruct;
@@ -0,0 +1,3 @@
1
+ export * from './construct';
2
+ export * from './stack';
3
+ export * from './types';
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./construct"), exports);
18
+ __exportStar(require("./stack"), exports);
19
+ __exportStar(require("./types"), exports);
@@ -0,0 +1,52 @@
1
+ import { CommonCloudflareConstruct } from './construct';
2
+ import { CommonCloudflareStackProps } from './types';
3
+ import { TerraformStack } from 'cdktf';
4
+ import { Construct } from 'constructs';
5
+ /**
6
+ * @classdesc Common stack to use as a base for all higher level constructs.
7
+ * @example
8
+ * import { CommonCloudflareStack } from '@gradientedge/cdk-utils'
9
+ *
10
+ * class CustomStack extends CommonCloudflareStack {
11
+ * constructor(parent: App, name: string, props: StackProps) {
12
+ * super(parent, name, props)
13
+ * // provision resources
14
+ * }
15
+ * }
16
+ */
17
+ export declare class CommonCloudflareStack extends TerraformStack {
18
+ construct: CommonCloudflareConstruct;
19
+ props: CommonCloudflareStackProps;
20
+ constructor(parent: Construct, name: string, props: CommonCloudflareStackProps);
21
+ /**
22
+ * @summary Method to determine the core CDK construct properties injected via context cdktf.json
23
+ * @param props The stack properties
24
+ * @returns The stack properties
25
+ */
26
+ protected determineConstructProps(props: CommonCloudflareStackProps): {
27
+ accountId: any;
28
+ domainName: any;
29
+ extraContexts: any;
30
+ features: any;
31
+ name: any;
32
+ skipStageForARecords: any;
33
+ stage: any;
34
+ subDomain: any;
35
+ };
36
+ /**
37
+ * @summary Method to determine extra cdk contexts apart from the main cdktf.json
38
+ * - Sets the properties from the extra contexts into cdk node context
39
+ * - Primary use is to have layered config in separate files to enable easier maintenance and readability
40
+ */
41
+ protected determineExtraContexts(): void;
42
+ /**
43
+ * @summary Method to determine extra cdk stage contexts apart from the main cdktf.json
44
+ * - Sets the properties from the extra stage contexts into cdk node context
45
+ * - Primary use is to have layered config for each environment which is injected into the context
46
+ */
47
+ protected determineStageContexts(): void;
48
+ /**
49
+ * @summary Determine the fully qualified domain name based on domainName & subDomain
50
+ */
51
+ protected fullyQualifiedDomain(): any;
52
+ }
@@ -0,0 +1,134 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.CommonCloudflareStack = void 0;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const construct_1 = require("./construct");
9
+ const app_root_path_1 = __importDefault(require("app-root-path"));
10
+ const cdktf_1 = require("cdktf");
11
+ const lodash_1 = __importDefault(require("lodash"));
12
+ const common_1 = require("../../common");
13
+ /**
14
+ * @classdesc Common stack to use as a base for all higher level constructs.
15
+ * @example
16
+ * import { CommonCloudflareStack } from '@gradientedge/cdk-utils'
17
+ *
18
+ * class CustomStack extends CommonCloudflareStack {
19
+ * constructor(parent: App, name: string, props: StackProps) {
20
+ * super(parent, name, props)
21
+ * // provision resources
22
+ * }
23
+ * }
24
+ */
25
+ class CommonCloudflareStack extends cdktf_1.TerraformStack {
26
+ construct;
27
+ props;
28
+ constructor(parent, name, props) {
29
+ super(parent, name);
30
+ /* determine extra cdk contexts */
31
+ this.determineExtraContexts();
32
+ /* determine extra cdk stage contexts */
33
+ this.determineStageContexts();
34
+ this.props = this.determineConstructProps(props);
35
+ /* initialise the construct */
36
+ this.construct = new construct_1.CommonCloudflareConstruct(this, 'cdk-utils', this.props);
37
+ }
38
+ /**
39
+ * @summary Method to determine the core CDK construct properties injected via context cdktf.json
40
+ * @param props The stack properties
41
+ * @returns The stack properties
42
+ */
43
+ determineConstructProps(props) {
44
+ return {
45
+ accountId: this.node.tryGetContext('accountId'),
46
+ domainName: this.node.tryGetContext('domainName'),
47
+ extraContexts: this.node.tryGetContext('extraContexts'),
48
+ features: this.node.tryGetContext('features'),
49
+ name: this.node.tryGetContext('resourceGroupName'),
50
+ skipStageForARecords: this.node.tryGetContext('skipStageForARecords'),
51
+ stage: this.node.tryGetContext('stage'),
52
+ subDomain: this.node.tryGetContext('subDomain'),
53
+ };
54
+ }
55
+ /**
56
+ * @summary Method to determine extra cdk contexts apart from the main cdktf.json
57
+ * - Sets the properties from the extra contexts into cdk node context
58
+ * - Primary use is to have layered config in separate files to enable easier maintenance and readability
59
+ */
60
+ determineExtraContexts() {
61
+ const extraContexts = this.node.tryGetContext('extraContexts');
62
+ const debug = this.node.tryGetContext('debug');
63
+ if (!extraContexts) {
64
+ if (debug)
65
+ console.debug(`No additional contexts provided. Using default context properties from cdktf.json`);
66
+ return;
67
+ }
68
+ lodash_1.default.forEach(extraContexts, (context) => {
69
+ const extraContextPath = `${app_root_path_1.default.path}/${context}`;
70
+ /* scenario where extra context is configured in cdk.json but absent in file system */
71
+ if (!fs_1.default.existsSync(extraContextPath))
72
+ throw `Extra context properties unavailable in path:${extraContextPath}`;
73
+ /* read the extra properties */
74
+ const extraContextPropsBuffer = fs_1.default.readFileSync(extraContextPath);
75
+ if (debug)
76
+ console.debug(`Adding additional contexts provided in ${extraContextPath}`);
77
+ /* parse as JSON properties */
78
+ const extraContextProps = JSON.parse(extraContextPropsBuffer.toString('utf-8'));
79
+ /* set each of the property into the cdk node context */
80
+ lodash_1.default.keys(extraContextProps).forEach((propKey) => {
81
+ this.node.setContext(propKey, extraContextProps[propKey]);
82
+ });
83
+ });
84
+ }
85
+ /**
86
+ * @summary Method to determine extra cdk stage contexts apart from the main cdktf.json
87
+ * - Sets the properties from the extra stage contexts into cdk node context
88
+ * - Primary use is to have layered config for each environment which is injected into the context
89
+ */
90
+ determineStageContexts() {
91
+ const stage = this.node.tryGetContext('stage');
92
+ const stageContextPath = this.node.tryGetContext('stageContextPath') || 'cdkEnv';
93
+ const stageContextFilePath = `${app_root_path_1.default.path}/${stageContextPath}/${stage}.json`;
94
+ const debug = this.node.tryGetContext('debug');
95
+ if ((0, common_1.isDevStage)(stage)) {
96
+ if (debug)
97
+ console.debug(`Development stage. Using default stage context properties`);
98
+ }
99
+ /* alert default context usage when extra stage config is missing */
100
+ if (!fs_1.default.existsSync(stageContextFilePath)) {
101
+ if (debug)
102
+ console.debug(`Stage specific context properties unavailable in path:${stageContextFilePath}`);
103
+ if (debug)
104
+ console.debug(`Using default stage context properties for ${stage} stage`);
105
+ return;
106
+ }
107
+ /* read the extra properties */
108
+ const stageContextPropsBuffer = fs_1.default.readFileSync(stageContextFilePath);
109
+ if (debug)
110
+ console.debug(`Adding additional stage contexts provided in ${stageContextFilePath}`);
111
+ /* parse as JSON properties */
112
+ const stageContextProps = JSON.parse(stageContextPropsBuffer.toString('utf-8'));
113
+ /* set each of the property into the cdk node context */
114
+ lodash_1.default.keys(stageContextProps).forEach((propKey) => {
115
+ /* handle object, array properties */
116
+ if (typeof stageContextProps[propKey] === 'object' && !Array.isArray(stageContextProps[propKey])) {
117
+ this.node.setContext(propKey, lodash_1.default.merge(this.node.tryGetContext(propKey), stageContextProps[propKey]));
118
+ }
119
+ else {
120
+ /* handle all other primitive properties */
121
+ this.node.setContext(propKey, stageContextProps[propKey]);
122
+ }
123
+ });
124
+ }
125
+ /**
126
+ * @summary Determine the fully qualified domain name based on domainName & subDomain
127
+ */
128
+ fullyQualifiedDomain() {
129
+ const domainName = this.node.tryGetContext('domainName');
130
+ const subDomain = this.node.tryGetContext('subDomain');
131
+ return subDomain ? `${subDomain}.${domainName}` : domainName;
132
+ }
133
+ }
134
+ exports.CommonCloudflareStack = CommonCloudflareStack;
@@ -0,0 +1,7 @@
1
+ import { CloudflareProviderConfig } from '@cdktf/provider-cloudflare/lib/provider';
2
+ import { BaseProps } from '../../common';
3
+ /**
4
+ */
5
+ export interface CommonCloudflareStackProps extends BaseProps, CloudflareProviderConfig {
6
+ accountId: string;
7
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,4 @@
1
+ export * from './common';
2
+ export * from './services';
3
+ export * from './types';
4
+ export * from './utils';
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./common"), exports);
18
+ __exportStar(require("./services"), exports);
19
+ __exportStar(require("./types"), exports);
20
+ __exportStar(require("./utils"), exports);
@@ -0,0 +1 @@
1
+ export * from './zone';
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./zone"), exports);
@@ -0,0 +1,2 @@
1
+ export * from './main';
2
+ export * from './types';
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./main"), exports);
18
+ __exportStar(require("./types"), exports);
@@ -0,0 +1,29 @@
1
+ import { ZoneProps } from './types';
2
+ import { CommonCloudflareConstruct } from '../../common';
3
+ /**
4
+ * @classdesc Provides operations on Cloudflare Zone
5
+ * - A new instance of this class is injected into {@link CommonCloudflareConstruct} constructor.
6
+ * - If a custom construct extends {@link CommonCloudflareConstruct}, an instance is available within the context.
7
+ * @example
8
+ * ```
9
+ * import { CommonCloudflareConstruct, CommonCloudflareConstruct } from '@gradientedge/cdk-utils'
10
+ *
11
+ * class CustomConstruct extends CommonCloudflareConstruct {
12
+ * constructor(parent: Construct, id: string, props: CommonCloudflareStackProps) {
13
+ * super(parent, id, props)
14
+ * this.props = props
15
+ * this.zoneManager.createZone('MyZone', this, props)
16
+ * }
17
+ * }
18
+ * ```
19
+ */
20
+ export declare class CloudflareZoneManager {
21
+ /**
22
+ * @summary Method to create a new zone
23
+ * @param id scoped id of the resource
24
+ * @param scope scope in which this resource is defined
25
+ * @param props zone properties
26
+ * @see [CDKTF Zone Module]{@link https://github.com/cdktf/cdktf-provider-cloudflare/blob/main/docs/zone.typescript.md}
27
+ */
28
+ createZone(id: string, scope: CommonCloudflareConstruct, props: ZoneProps): void;
29
+ }
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CloudflareZoneManager = void 0;
4
+ const zone_1 = require("@cdktf/provider-cloudflare/lib/zone");
5
+ const utils_1 = require("../../utils");
6
+ /**
7
+ * @classdesc Provides operations on Cloudflare Zone
8
+ * - A new instance of this class is injected into {@link CommonCloudflareConstruct} constructor.
9
+ * - If a custom construct extends {@link CommonCloudflareConstruct}, an instance is available within the context.
10
+ * @example
11
+ * ```
12
+ * import { CommonCloudflareConstruct, CommonCloudflareConstruct } from '@gradientedge/cdk-utils'
13
+ *
14
+ * class CustomConstruct extends CommonCloudflareConstruct {
15
+ * constructor(parent: Construct, id: string, props: CommonCloudflareStackProps) {
16
+ * super(parent, id, props)
17
+ * this.props = props
18
+ * this.zoneManager.createZone('MyZone', this, props)
19
+ * }
20
+ * }
21
+ * ```
22
+ */
23
+ class CloudflareZoneManager {
24
+ /**
25
+ * @summary Method to create a new zone
26
+ * @param id scoped id of the resource
27
+ * @param scope scope in which this resource is defined
28
+ * @param props zone properties
29
+ * @see [CDKTF Zone Module]{@link https://github.com/cdktf/cdktf-provider-cloudflare/blob/main/docs/zone.typescript.md}
30
+ */
31
+ createZone(id, scope, props) {
32
+ if (!props)
33
+ throw `Props undefined for ${id}`;
34
+ const zone = new zone_1.Zone(scope, `${id}`, {
35
+ ...props,
36
+ accountId: props.accountId ?? scope.props.accountId,
37
+ zone: props.zone ?? scope.props.domainName,
38
+ });
39
+ (0, utils_1.createCloudflareTfOutput)(`${id}-zoneName`, scope, zone.zone);
40
+ (0, utils_1.createCloudflareTfOutput)(`${id}-zoneFriendlyUniqueId`, scope, zone.friendlyUniqueId);
41
+ (0, utils_1.createCloudflareTfOutput)(`${id}-zoneId`, scope, zone.id);
42
+ }
43
+ }
44
+ exports.CloudflareZoneManager = CloudflareZoneManager;
@@ -0,0 +1,3 @@
1
+ import { ZoneConfig } from '@cdktf/provider-cloudflare/lib/zone';
2
+ export interface ZoneProps extends ZoneConfig {
3
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,3 @@
1
+ export interface BaseCloudflareProps {
2
+ accountId: string;
3
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,3 @@
1
+ import { TerraformOutput } from 'cdktf';
2
+ import { CommonCloudflareConstruct } from '../common';
3
+ export declare const createCloudflareTfOutput: (id: string, scope: CommonCloudflareConstruct, value?: string, description?: string, sensitive?: boolean, overrideId?: boolean) => TerraformOutput;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.createCloudflareTfOutput = void 0;
7
+ const cdktf_1 = require("cdktf");
8
+ const lodash_1 = __importDefault(require("lodash"));
9
+ const createCloudflareTfOutput = (id, scope, value, description, sensitive, overrideId = true) => {
10
+ const output = new cdktf_1.TerraformOutput(scope, id, {
11
+ description,
12
+ sensitive,
13
+ value,
14
+ });
15
+ if (overrideId) {
16
+ output.overrideLogicalId(lodash_1.default.camelCase(id));
17
+ }
18
+ return output;
19
+ };
20
+ exports.createCloudflareTfOutput = createCloudflareTfOutput;
@@ -1,3 +1,4 @@
1
1
  export * from './aws';
2
2
  export * from './azure';
3
+ export * from './cloudflare';
3
4
  export * from './common';
@@ -16,4 +16,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./aws"), exports);
18
18
  __exportStar(require("./azure"), exports);
19
+ __exportStar(require("./cloudflare"), exports);
19
20
  __exportStar(require("./common"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gradientedge/cdk-utils",
3
- "version": "8.134.0",
3
+ "version": "8.136.0",
4
4
  "description": "Utilities for AWS CDK provisioning",
5
5
  "main": "dist/index.js",
6
6
  "engines": {
@@ -18,6 +18,7 @@
18
18
  "keywords": [
19
19
  "gradientedge",
20
20
  "cdk",
21
+ "cdktf",
21
22
  "awscdk"
22
23
  ],
23
24
  "license": "MIT",
@@ -46,15 +47,16 @@
46
47
  }
47
48
  },
48
49
  "dependencies": {
49
- "@aws-sdk/client-secrets-manager": "^3.445.0",
50
- "@aws-sdk/credential-providers": "^3.445.0",
51
- "@aws-sdk/types": "^3.433.0",
52
- "@cdktf/provider-azurerm": "^11.0.3",
50
+ "@aws-sdk/client-secrets-manager": "^3.449.0",
51
+ "@aws-sdk/credential-providers": "^3.449.0",
52
+ "@aws-sdk/types": "^3.449.0",
53
+ "@cdktf/provider-azurerm": "^11.0.4",
54
+ "@cdktf/provider-cloudflare": "^10.0.3",
53
55
  "@types/lodash": "^4.14.201",
54
56
  "@types/node": "^20.9.0",
55
57
  "@types/uuid": "^9.0.7",
56
58
  "app-root-path": "^3.1.0",
57
- "aws-cdk-lib": "^2.105.0",
59
+ "aws-cdk-lib": "^2.106.1",
58
60
  "cdktf": "^0.19.1",
59
61
  "constructs": "^10.3.0",
60
62
  "lodash": "^4.17.21",
@@ -71,7 +73,7 @@
71
73
  "@types/jest": "^29.5.8",
72
74
  "@typescript-eslint/eslint-plugin": "^6.10.0",
73
75
  "@typescript-eslint/parser": "^6.10.0",
74
- "aws-cdk": "^2.105.0",
76
+ "aws-cdk": "^2.106.1",
75
77
  "better-docs": "^2.7.2",
76
78
  "codecov": "^3.8.3",
77
79
  "commitizen": "^4.3.0",
@@ -80,7 +82,7 @@
80
82
  "eslint": "^8.53.0",
81
83
  "eslint-config-prettier": "^9.0.0",
82
84
  "eslint-plugin-import": "^2.29.0",
83
- "eslint-plugin-jsdoc": "^46.8.2",
85
+ "eslint-plugin-jsdoc": "^46.9.0",
84
86
  "husky": "^8.0.3",
85
87
  "jest": "^29.7.0",
86
88
  "jest-extended": "^4.0.2",
@@ -90,8 +92,8 @@
90
92
  "jsdoc-mermaid": "^1.0.0",
91
93
  "jsdoc-plugin-typescript": "^2.2.1",
92
94
  "jsdoc-to-markdown": "^8.0.0",
93
- "prettier": "^3.0.3",
94
- "prettier-plugin-organize-imports": "^3.2.3",
95
+ "prettier": "^3.1.0",
96
+ "prettier-plugin-organize-imports": "^3.2.4",
95
97
  "rimraf": "^5.0.5",
96
98
  "semantic-release": "^22.0.7",
97
99
  "taffydb": "^2.7.3",
@@ -3,4 +3,4 @@ export enum SiteWithLambdaBackendResponseHeaderPolicyType {
3
3
  STATIC = 'static',
4
4
  }
5
5
 
6
- export const LAMBDA_ALIAS_NAME_CURRENT = 'current'
6
+ export const LAMBDA_ALIAS_NAME_CURRENT = 'latest'
@@ -5,7 +5,7 @@ import { StorageAccount } from '@cdktf/provider-azurerm/lib/storage-account'
5
5
  import { StorageBlob } from '@cdktf/provider-azurerm/lib/storage-blob'
6
6
  import { StorageContainer } from '@cdktf/provider-azurerm/lib/storage-container'
7
7
  import { CommonAzureConstruct } from '../../common'
8
- import { createTfOutput } from '../../utils'
8
+ import { createAzureTfOutput } from '../../utils'
9
9
  import { StorageAccountProps, StorageBlobProps, StorageContainerProps } from './types'
10
10
 
11
11
  /**
@@ -23,7 +23,6 @@ import { StorageAccountProps, StorageBlobProps, StorageContainerProps } from './
23
23
  * this.storageManager.createStorageAccount('MyAccount', this, props)
24
24
  * }
25
25
  * }
26
- * @see [CDKTF S3 Module]{@link https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_s3-readme.html}
27
26
  * ```
28
27
  */
29
28
  export class AzureStorageManager {
@@ -32,6 +31,7 @@ export class AzureStorageManager {
32
31
  * @param id scoped id of the resource
33
32
  * @param scope scope in which this resource is defined
34
33
  * @param props storage account properties
34
+ * @see [CDKTF Storage Account Module]{@link https://github.com/cdktf/cdktf-provider-azurerm/blob/main/docs/storageAccount.typescript.md}
35
35
  */
36
36
  public createStorageAccount(id: string, scope: CommonAzureConstruct, props: StorageAccountProps) {
37
37
  if (!props) throw `Props undefined for ${id}`
@@ -55,9 +55,9 @@ export class AzureStorageManager {
55
55
  },
56
56
  })
57
57
 
58
- createTfOutput(`${id}-storageAccountName`, scope, storageAccount.name)
59
- createTfOutput(`${id}-storageAccountFriendlyUniqueId`, scope, storageAccount.friendlyUniqueId)
60
- createTfOutput(`${id}-storageAccountId`, scope, storageAccount.id)
58
+ createAzureTfOutput(`${id}-storageAccountName`, scope, storageAccount.name)
59
+ createAzureTfOutput(`${id}-storageAccountFriendlyUniqueId`, scope, storageAccount.friendlyUniqueId)
60
+ createAzureTfOutput(`${id}-storageAccountId`, scope, storageAccount.id)
61
61
  }
62
62
 
63
63
  /**
@@ -65,6 +65,7 @@ export class AzureStorageManager {
65
65
  * @param id scoped id of the resource
66
66
  * @param scope scope in which this resource is defined
67
67
  * @param props storage container properties
68
+ * @see [CDKTF Storage Container Module]{@link https://github.com/cdktf/cdktf-provider-azurerm/blob/main/docs/storageContainer.typescript.md}
68
69
  */
69
70
  public createStorageContainer(id: string, scope: CommonAzureConstruct, props: StorageContainerProps) {
70
71
  if (!props) throw `Props undefined for ${id}`
@@ -88,9 +89,9 @@ export class AzureStorageManager {
88
89
  storageAccountName: storageAccount.name,
89
90
  })
90
91
 
91
- createTfOutput(`${id}-storageContainerName`, scope, storageContainer.name)
92
- createTfOutput(`${id}-storageContainerFriendlyUniqueId`, scope, storageContainer.friendlyUniqueId)
93
- createTfOutput(`${id}-storageContainerId`, scope, storageContainer.id)
92
+ createAzureTfOutput(`${id}-storageContainerName`, scope, storageContainer.name)
93
+ createAzureTfOutput(`${id}-storageContainerFriendlyUniqueId`, scope, storageContainer.friendlyUniqueId)
94
+ createAzureTfOutput(`${id}-storageContainerId`, scope, storageContainer.id)
94
95
  }
95
96
 
96
97
  /**
@@ -98,6 +99,7 @@ export class AzureStorageManager {
98
99
  * @param id scoped id of the resource
99
100
  * @param scope scope in which this resource is defined
100
101
  * @param props storage blob properties
102
+ * @see [CDKTF Storage Blob Module]{@link https://github.com/cdktf/cdktf-provider-azurerm/blob/main/docs/storageBlob.typescript.md}
101
103
  */
102
104
  public createStorageBlob(id: string, scope: CommonAzureConstruct, props: StorageBlobProps) {
103
105
  if (!props) throw `Props undefined for ${id}`
@@ -127,8 +129,8 @@ export class AzureStorageManager {
127
129
  storageContainerName: storageContainer.name,
128
130
  })
129
131
 
130
- createTfOutput(`${id}-storageBlobName`, scope, storageBlob.name)
131
- createTfOutput(`${id}-storageBlobFriendlyUniqueId`, scope, storageBlob.friendlyUniqueId)
132
- createTfOutput(`${id}-storageBlobId`, scope, storageBlob.id)
132
+ createAzureTfOutput(`${id}-storageBlobName`, scope, storageBlob.name)
133
+ createAzureTfOutput(`${id}-storageBlobFriendlyUniqueId`, scope, storageBlob.friendlyUniqueId)
134
+ createAzureTfOutput(`${id}-storageBlobId`, scope, storageBlob.id)
133
135
  }
134
136
  }
@@ -1,10 +1,10 @@
1
1
  import { StorageAccountConfig } from '@cdktf/provider-azurerm/lib/storage-account'
2
2
  import { StorageBlobConfig } from '@cdktf/provider-azurerm/lib/storage-blob'
3
3
  import { StorageContainerConfig } from '@cdktf/provider-azurerm/lib/storage-container'
4
- import { BaseConfigProps } from '../../types'
4
+ import { BaseAzureConfigProps } from '../../types'
5
5
 
6
6
  export interface StorageAccountProps extends StorageAccountConfig {}
7
7
 
8
- export interface StorageContainerProps extends BaseConfigProps, StorageContainerConfig {}
8
+ export interface StorageContainerProps extends BaseAzureConfigProps, StorageContainerConfig {}
9
9
 
10
- export interface StorageBlobProps extends BaseConfigProps, StorageBlobConfig {}
10
+ export interface StorageBlobProps extends BaseAzureConfigProps, StorageBlobConfig {}
@@ -1,3 +1,3 @@
1
- export interface BaseConfigProps {
1
+ export interface BaseAzureConfigProps {
2
2
  resourceGroupName: string
3
3
  }
@@ -2,7 +2,7 @@ import { TerraformOutput } from 'cdktf'
2
2
  import _ from 'lodash'
3
3
  import { CommonAzureConstruct } from '../common'
4
4
 
5
- export const createTfOutput = (
5
+ export const createAzureTfOutput = (
6
6
  id: string,
7
7
  scope: CommonAzureConstruct,
8
8
  value?: string,
@@ -0,0 +1,57 @@
1
+ import { CloudflareProvider } from '@cdktf/provider-cloudflare/lib/provider'
2
+ import { TerraformStack } from 'cdktf'
3
+ import { Construct } from 'constructs'
4
+ import { isDevStage, isPrdStage, isTestStage, isUatStage } from '../../common'
5
+ import { CloudflareZoneManager } from '../services'
6
+ import { CommonCloudflareStackProps } from './types'
7
+
8
+ export class CommonCloudflareConstruct extends TerraformStack {
9
+ declare props: CommonCloudflareStackProps
10
+ id: string
11
+ fullyQualifiedDomainName: string
12
+ zoneManager: CloudflareZoneManager
13
+
14
+ constructor(scope: Construct, id: string, props: CommonCloudflareStackProps) {
15
+ super(scope, id)
16
+ this.props = props
17
+ this.id = id
18
+
19
+ this.zoneManager = new CloudflareZoneManager()
20
+
21
+ this.determineFullyQualifiedDomain()
22
+ new CloudflareProvider(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,3 @@
1
+ export * from './construct'
2
+ export * from './stack'
3
+ export * from './types'
@@ -0,0 +1,143 @@
1
+ import fs from 'fs'
2
+ import { CommonCloudflareConstruct } from './construct'
3
+ import { CommonCloudflareStackProps } 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 { CommonCloudflareStack } from '@gradientedge/cdk-utils'
15
+ *
16
+ * class CustomStack extends CommonCloudflareStack {
17
+ * constructor(parent: App, name: string, props: StackProps) {
18
+ * super(parent, name, props)
19
+ * // provision resources
20
+ * }
21
+ * }
22
+ */
23
+ export class CommonCloudflareStack extends TerraformStack {
24
+ construct: CommonCloudflareConstruct
25
+ props: CommonCloudflareStackProps
26
+
27
+ constructor(parent: Construct, name: string, props: CommonCloudflareStackProps) {
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 CommonCloudflareConstruct(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: CommonCloudflareStackProps) {
48
+ return {
49
+ accountId: this.node.tryGetContext('accountId'),
50
+ domainName: this.node.tryGetContext('domainName'),
51
+ extraContexts: this.node.tryGetContext('extraContexts'),
52
+ features: this.node.tryGetContext('features'),
53
+ name: 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,8 @@
1
+ import { CloudflareProviderConfig } from '@cdktf/provider-cloudflare/lib/provider'
2
+ import { BaseProps } from '../../common'
3
+
4
+ /**
5
+ */
6
+ export interface CommonCloudflareStackProps extends BaseProps, CloudflareProviderConfig {
7
+ accountId: string
8
+ }
@@ -0,0 +1,4 @@
1
+ export * from './common'
2
+ export * from './services'
3
+ export * from './types'
4
+ export * from './utils'
@@ -0,0 +1 @@
1
+ export * from './zone'
@@ -0,0 +1,2 @@
1
+ export * from './main'
2
+ export * from './types'
@@ -0,0 +1,44 @@
1
+ import { Zone } from '@cdktf/provider-cloudflare/lib/zone'
2
+ import { ZoneProps } from './types'
3
+ import { createCloudflareTfOutput } from '../../utils'
4
+ import { CommonCloudflareConstruct } from '../../common'
5
+
6
+ /**
7
+ * @classdesc Provides operations on Cloudflare Zone
8
+ * - A new instance of this class is injected into {@link CommonCloudflareConstruct} constructor.
9
+ * - If a custom construct extends {@link CommonCloudflareConstruct}, an instance is available within the context.
10
+ * @example
11
+ * ```
12
+ * import { CommonCloudflareConstruct, CommonCloudflareConstruct } from '@gradientedge/cdk-utils'
13
+ *
14
+ * class CustomConstruct extends CommonCloudflareConstruct {
15
+ * constructor(parent: Construct, id: string, props: CommonCloudflareStackProps) {
16
+ * super(parent, id, props)
17
+ * this.props = props
18
+ * this.zoneManager.createZone('MyZone', this, props)
19
+ * }
20
+ * }
21
+ * ```
22
+ */
23
+ export class CloudflareZoneManager {
24
+ /**
25
+ * @summary Method to create a new zone
26
+ * @param id scoped id of the resource
27
+ * @param scope scope in which this resource is defined
28
+ * @param props zone properties
29
+ * @see [CDKTF Zone Module]{@link https://github.com/cdktf/cdktf-provider-cloudflare/blob/main/docs/zone.typescript.md}
30
+ */
31
+ public createZone(id: string, scope: CommonCloudflareConstruct, props: ZoneProps) {
32
+ if (!props) throw `Props undefined for ${id}`
33
+
34
+ const zone = new Zone(scope, `${id}`, {
35
+ ...props,
36
+ accountId: props.accountId ?? scope.props.accountId,
37
+ zone: props.zone ?? scope.props.domainName,
38
+ })
39
+
40
+ createCloudflareTfOutput(`${id}-zoneName`, scope, zone.zone)
41
+ createCloudflareTfOutput(`${id}-zoneFriendlyUniqueId`, scope, zone.friendlyUniqueId)
42
+ createCloudflareTfOutput(`${id}-zoneId`, scope, zone.id)
43
+ }
44
+ }
@@ -0,0 +1,3 @@
1
+ import { ZoneConfig } from '@cdktf/provider-cloudflare/lib/zone'
2
+
3
+ export interface ZoneProps extends ZoneConfig {}
@@ -0,0 +1,3 @@
1
+ export interface BaseCloudflareProps {
2
+ accountId: string
3
+ }
@@ -0,0 +1,23 @@
1
+ import { TerraformOutput } from 'cdktf'
2
+ import _ from 'lodash'
3
+ import { CommonCloudflareConstruct } from '../common'
4
+
5
+ export const createCloudflareTfOutput = (
6
+ id: string,
7
+ scope: CommonCloudflareConstruct,
8
+ value?: string,
9
+ description?: string,
10
+ sensitive?: boolean,
11
+ overrideId = true
12
+ ) => {
13
+ const output = new TerraformOutput(scope, id, {
14
+ description,
15
+ sensitive,
16
+ value,
17
+ })
18
+
19
+ if (overrideId) {
20
+ output.overrideLogicalId(_.camelCase(id))
21
+ }
22
+ return output
23
+ }
package/src/lib/index.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './aws'
2
2
  export * from './azure'
3
+ export * from './cloudflare'
3
4
  export * from './common'