@gradientedge/cdk-utils 8.121.0 → 8.122.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 (72) hide show
  1. package/README.md +2 -1
  2. package/dist/src/lib/aws/common/construct.d.ts +0 -1
  3. package/dist/src/lib/aws/common/construct.js +6 -13
  4. package/dist/src/lib/aws/common/stack.js +2 -2
  5. package/dist/src/lib/aws/common/types.d.ts +2 -8
  6. package/dist/src/lib/aws/types/index.d.ts +6 -1
  7. package/dist/src/lib/aws/types/index.js +0 -15
  8. package/dist/src/lib/aws/utils/index.d.ts +13 -23
  9. package/dist/src/lib/aws/utils/index.js +37 -46
  10. package/dist/src/lib/azure/common/construct.d.ts +35 -0
  11. package/dist/src/lib/azure/common/construct.js +49 -0
  12. package/dist/src/lib/azure/common/index.d.ts +3 -0
  13. package/dist/src/lib/azure/common/index.js +19 -0
  14. package/dist/src/lib/azure/common/stack.d.ts +52 -0
  15. package/dist/src/lib/azure/common/stack.js +136 -0
  16. package/dist/src/lib/azure/common/types.d.ts +7 -0
  17. package/dist/src/lib/azure/index.d.ts +4 -0
  18. package/dist/src/lib/azure/index.js +20 -0
  19. package/dist/src/lib/azure/services/index.d.ts +1 -0
  20. package/dist/src/lib/azure/services/index.js +17 -0
  21. package/dist/src/lib/azure/services/storage/index.d.ts +2 -0
  22. package/dist/src/lib/azure/services/storage/index.js +18 -0
  23. package/dist/src/lib/azure/services/storage/main.d.ts +43 -0
  24. package/dist/src/lib/azure/services/storage/main.js +124 -0
  25. package/dist/src/lib/azure/services/storage/types.d.ts +10 -0
  26. package/dist/src/lib/azure/services/storage/types.js +2 -0
  27. package/dist/src/lib/azure/types/index.d.ts +3 -0
  28. package/dist/src/lib/azure/types/index.js +2 -0
  29. package/dist/src/lib/azure/utils/index.d.ts +3 -0
  30. package/dist/src/lib/azure/utils/index.js +20 -0
  31. package/dist/src/lib/common/construct.d.ts +29 -0
  32. package/dist/src/lib/common/construct.js +8 -0
  33. package/dist/src/lib/common/index.d.ts +5 -0
  34. package/dist/src/lib/common/index.js +29 -0
  35. package/dist/src/lib/common/stack.d.ts +21 -0
  36. package/dist/src/lib/common/stack.js +8 -0
  37. package/dist/src/lib/common/types.d.ts +9 -0
  38. package/dist/src/lib/common/types.js +2 -0
  39. package/dist/src/lib/common/utils.d.ts +26 -0
  40. package/dist/src/lib/common/utils.js +34 -0
  41. package/dist/src/lib/index.d.ts +2 -0
  42. package/dist/src/lib/index.js +2 -0
  43. package/package.json +3 -1
  44. package/setup.js +2 -0
  45. package/src/lib/aws/common/construct.ts +2 -13
  46. package/src/lib/aws/common/stack.ts +1 -1
  47. package/src/lib/aws/common/types.ts +2 -8
  48. package/src/lib/aws/types/index.ts +6 -1
  49. package/src/lib/aws/utils/index.ts +41 -29
  50. package/src/lib/azure/common/construct.ts +57 -0
  51. package/src/lib/azure/common/index.ts +3 -0
  52. package/src/lib/azure/common/stack.ts +145 -0
  53. package/src/lib/azure/common/types.ts +8 -0
  54. package/src/lib/azure/index.ts +4 -0
  55. package/src/lib/azure/services/index.ts +1 -0
  56. package/src/lib/azure/services/storage/index.ts +2 -0
  57. package/src/lib/azure/services/storage/main.ts +134 -0
  58. package/src/lib/azure/services/storage/types.ts +10 -0
  59. package/src/lib/azure/types/index.ts +3 -0
  60. package/src/lib/azure/utils/index.ts +23 -0
  61. package/src/lib/common/construct.ts +35 -0
  62. package/src/lib/common/index.ts +16 -0
  63. package/src/lib/common/stack.ts +26 -0
  64. package/src/lib/common/types.ts +9 -0
  65. package/src/lib/common/utils.ts +27 -0
  66. package/src/lib/index.ts +2 -0
  67. package/dist/src/lib/aws/types/aws/index.d.ts +0 -6
  68. package/dist/src/lib/aws/utils/aws/index.d.ts +0 -17
  69. package/dist/src/lib/aws/utils/aws/index.js +0 -40
  70. package/src/lib/aws/types/aws/index.ts +0 -6
  71. package/src/lib/aws/utils/aws/index.ts +0 -41
  72. /package/dist/src/lib/{aws/types/aws/index.js → azure/common/types.js} +0 -0
package/README.md CHANGED
@@ -25,7 +25,7 @@
25
25
 
26
26
  ## Introduction
27
27
 
28
- Toolkit for working with the [AWS CDK][aws-cdk].
28
+ Toolkit for working with CDK Constructs ([AWS CDK][aws-cdk] & [CDK for Terraform][cdktf]).
29
29
 
30
30
  For more details, see the full [API documentation](https://gradientedge.github.io/cdk-utils/).
31
31
 
@@ -65,6 +65,7 @@ pnpm add @gradientedge/cdk-utils
65
65
  [builds]: https://img.shields.io/github/actions/workflow/status/gradientedge/cdk-utils/ci.yml?branch=main
66
66
  [builds-url]: https://github.com/gradientedge/cdk-utils/actions
67
67
  [cdk-badge]: https://img.shields.io/github/package-json/dependency-version/gradientedge/cdk-utils/aws-cdk-lib
68
+ [cdktf]: https://developer.hashicorp.com/terraform/cdktf
68
69
  [cdk-url]: https://aws.amazon.com/cdk/
69
70
  [checks]: https://img.shields.io/github/checks-status/gradientedge/cdk-utils/main
70
71
  [cmd]: https://img.shields.io/badge/command--line-4D4D4D?logo=windows-terminal&style=for-the-badge
@@ -81,4 +81,3 @@ export declare class CommonConstruct extends Construct {
81
81
  */
82
82
  isProductionStage: () => boolean;
83
83
  }
84
- export declare const applyMixins: (derivedCtor: any, constructors: any[]) => void;
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.applyMixins = exports.CommonConstruct = void 0;
3
+ exports.CommonConstruct = void 0;
4
4
  const constructs_1 = require("constructs");
5
+ const common_1 = require("../../common");
5
6
  const services_1 = require("../services");
6
7
  const utils_1 = require("../utils");
7
8
  /**
@@ -105,29 +106,21 @@ class CommonConstruct extends constructs_1.Construct {
105
106
  * @summary Utility method to determine if the initialisation is in development (dev) stage
106
107
  * This is determined by the stage property injected via cdk context
107
108
  */
108
- isDevelopmentStage = () => (0, utils_1.isDevStage)(this.props.stage);
109
+ isDevelopmentStage = () => (0, common_1.isDevStage)(this.props.stage);
109
110
  /**
110
111
  * @summary Utility method to determine if the initialisation is in test (tst) stage
111
112
  * This is determined by the stage property injected via cdk context
112
113
  */
113
- isTestStage = () => (0, utils_1.isTestStage)(this.props.stage);
114
+ isTestStage = () => (0, common_1.isTestStage)(this.props.stage);
114
115
  /**
115
116
  * @summary Utility method to determine if the initialisation is in uat (uat) stage
116
117
  * This is determined by the stage property injected via cdk context
117
118
  */
118
- isUatStage = () => (0, utils_1.isUatStage)(this.props.stage);
119
+ isUatStage = () => (0, common_1.isUatStage)(this.props.stage);
119
120
  /**
120
121
  * @summary Utility method to determine if the initialisation is in production (prd) stage
121
122
  * This is determined by the stage property injected via cdk context
122
123
  */
123
- isProductionStage = () => (0, utils_1.isPrdStage)(this.props.stage);
124
+ isProductionStage = () => (0, common_1.isPrdStage)(this.props.stage);
124
125
  }
125
126
  exports.CommonConstruct = CommonConstruct;
126
- const applyMixins = (derivedCtor, constructors) => {
127
- constructors.forEach(baseCtor => {
128
- Object.getOwnPropertyNames(baseCtor.prototype).forEach(name => {
129
- Object.defineProperty(derivedCtor.prototype, name, Object.getOwnPropertyDescriptor(baseCtor.prototype, name) || Object.create(null));
130
- });
131
- });
132
- };
133
- exports.applyMixins = applyMixins;
@@ -7,9 +7,9 @@ exports.CommonStack = void 0;
7
7
  const aws_cdk_lib_1 = require("aws-cdk-lib");
8
8
  const aws_lambda_1 = require("aws-cdk-lib/aws-lambda");
9
9
  const fs_1 = __importDefault(require("fs"));
10
- const utils_1 = require("../utils");
11
10
  const construct_1 = require("./construct");
12
11
  const app_root_path_1 = __importDefault(require("app-root-path"));
12
+ const common_1 = require("../../common");
13
13
  /**
14
14
  * @classdesc Common stack to use as a base for all higher level constructs.
15
15
  * @example
@@ -96,7 +96,7 @@ class CommonStack extends aws_cdk_lib_1.Stack {
96
96
  const stageContextPath = this.node.tryGetContext('stageContextPath') || 'cdkEnv';
97
97
  const stageContextFilePath = `${app_root_path_1.default.path}/${stageContextPath}/${stage}.json`;
98
98
  const debug = this.node.tryGetContext('debug');
99
- if ((0, utils_1.isDevStage)(stage)) {
99
+ if ((0, common_1.isDevStage)(stage)) {
100
100
  if (debug)
101
101
  console.debug(`Development stage. Using default stage context properties`);
102
102
  }
@@ -1,17 +1,11 @@
1
1
  import { StackProps } from 'aws-cdk-lib';
2
2
  import { Runtime, Tracing } from 'aws-cdk-lib/aws-lambda';
3
3
  import { RetentionDays } from 'aws-cdk-lib/aws-logs';
4
+ import { BaseProps } from '../../common';
4
5
  /**
5
6
  */
6
- export interface CommonStackProps extends StackProps {
7
- name: string;
7
+ export interface CommonStackProps extends BaseProps, StackProps {
8
8
  region: string;
9
- stage: string;
10
- domainName: string;
11
- subDomain?: string;
12
- extraContexts?: string[];
13
- stageContextPath?: string;
14
- skipStageForARecords: boolean;
15
9
  logRetention?: RetentionDays;
16
10
  defaultReservedLambdaConcurrentExecutions?: number;
17
11
  defaultTracing?: Tracing;
@@ -1 +1,6 @@
1
- export * from './aws';
1
+ /**
2
+ */
3
+ export interface TagProps {
4
+ key: string;
5
+ value: string;
6
+ }
@@ -1,17 +1,2 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./aws"), exports);
@@ -1,30 +1,20 @@
1
- export * from './aws';
1
+ import { AwsCredentialIdentityProvider } from '@aws-sdk/types';
2
+ import { CfnOutput } from 'aws-cdk-lib';
3
+ import { CommonConstruct } from '../common';
2
4
  /**
5
+ * @summary Helper method to add CloudFormation outputs from the construct
6
+ * @param id scoped id of the resource
7
+ * @param scope scope in which this resource is defined
8
+ * @param value the value of the exported output
9
+ * @param description optional description for the output
10
+ * @param overrideId Flag which indicates whether to override the default logical id of the output
11
+ * @returns The CloudFormation output
3
12
  */
4
- export declare enum LogLevel {
5
- DEBUG = "DEBUG",
6
- INFO = "INFO",
7
- WARNING = "WARNING",
8
- TRACE = "TRACE",
9
- ERROR = "ERROR",
10
- CRITICAL = "CRITICAL"
11
- }
13
+ export declare function createCfnOutput(id: string, scope: CommonConstruct, value?: string, description?: string, overrideId?: boolean): CfnOutput;
12
14
  /**
13
- * @param stage
15
+ *
14
16
  */
15
- export declare const isDevStage: (stage: string) => boolean;
16
- /**
17
- * @param stage
18
- */
19
- export declare const isTestStage: (stage: string) => boolean;
20
- /**
21
- * @param stage
22
- */
23
- export declare const isUatStage: (stage: string) => boolean;
24
- /**
25
- * @param stage
26
- */
27
- export declare const isPrdStage: (stage: string) => boolean;
17
+ export declare function determineCredentials(): AwsCredentialIdentityProvider;
28
18
  /**
29
19
  * @param error
30
20
  */
@@ -1,21 +1,43 @@
1
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);
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
15
4
  };
16
5
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.redirectSuccess = exports.redirectError = exports.isPrdStage = exports.isUatStage = exports.isTestStage = exports.isDevStage = exports.LogLevel = void 0;
18
- __exportStar(require("./aws"), exports);
6
+ exports.redirectSuccess = exports.redirectError = exports.determineCredentials = exports.createCfnOutput = void 0;
7
+ const credential_providers_1 = require("@aws-sdk/credential-providers");
8
+ const aws_cdk_lib_1 = require("aws-cdk-lib");
9
+ const lodash_1 = __importDefault(require("lodash"));
10
+ /**
11
+ * @summary Helper method to add CloudFormation outputs from the construct
12
+ * @param id scoped id of the resource
13
+ * @param scope scope in which this resource is defined
14
+ * @param value the value of the exported output
15
+ * @param description optional description for the output
16
+ * @param overrideId Flag which indicates whether to override the default logical id of the output
17
+ * @returns The CloudFormation output
18
+ */
19
+ function createCfnOutput(id, scope, value, description, overrideId = true) {
20
+ const camelName = lodash_1.default.camelCase(id);
21
+ const output = new aws_cdk_lib_1.CfnOutput(scope, id, {
22
+ description,
23
+ exportName: `${scope.props.stackName}-${camelName}`,
24
+ value: value ?? '',
25
+ });
26
+ if (overrideId) {
27
+ output.overrideLogicalId(camelName);
28
+ }
29
+ return output;
30
+ }
31
+ exports.createCfnOutput = createCfnOutput;
32
+ /**
33
+ *
34
+ */
35
+ function determineCredentials() {
36
+ if (process.env.AWS_PROFILE)
37
+ return (0, credential_providers_1.fromIni)();
38
+ return (0, credential_providers_1.fromEnv)();
39
+ }
40
+ exports.determineCredentials = determineCredentials;
19
41
  /**
20
42
  */
21
43
  const defaultResponseObject = {
@@ -26,37 +48,6 @@ const defaultResponseObject = {
26
48
  isBase64Encoded: false,
27
49
  statusCode: 200,
28
50
  };
29
- /**
30
- */
31
- var LogLevel;
32
- (function (LogLevel) {
33
- LogLevel["DEBUG"] = "DEBUG";
34
- LogLevel["INFO"] = "INFO";
35
- LogLevel["WARNING"] = "WARNING";
36
- LogLevel["TRACE"] = "TRACE";
37
- LogLevel["ERROR"] = "ERROR";
38
- LogLevel["CRITICAL"] = "CRITICAL";
39
- })(LogLevel || (exports.LogLevel = LogLevel = {}));
40
- /**
41
- * @param stage
42
- */
43
- const isDevStage = (stage) => stage === 'dev';
44
- exports.isDevStage = isDevStage;
45
- /**
46
- * @param stage
47
- */
48
- const isTestStage = (stage) => stage === 'tst';
49
- exports.isTestStage = isTestStage;
50
- /**
51
- * @param stage
52
- */
53
- const isUatStage = (stage) => stage === 'uat';
54
- exports.isUatStage = isUatStage;
55
- /**
56
- * @param stage
57
- */
58
- const isPrdStage = (stage) => stage === 'prd';
59
- exports.isPrdStage = isPrdStage;
60
51
  /**
61
52
  * @param error
62
53
  */
@@ -0,0 +1,35 @@
1
+ import { TerraformStack } from 'cdktf';
2
+ import { Construct } from 'constructs';
3
+ import { AzureStorageManager } from '../services';
4
+ import { CommonAzureStackProps } from './types';
5
+ export declare class CommonAzureConstruct extends TerraformStack {
6
+ props: CommonAzureStackProps;
7
+ id: string;
8
+ fullyQualifiedDomainName: string;
9
+ storageManager: AzureStorageManager;
10
+ constructor(scope: Construct, id: string, props: CommonAzureStackProps);
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.CommonAzureConstruct = void 0;
4
+ const provider_1 = require("@cdktf/provider-azurerm/lib/provider");
5
+ const cdktf_1 = require("cdktf");
6
+ const common_1 = require("../../common");
7
+ const services_1 = require("../services");
8
+ class CommonAzureConstruct extends cdktf_1.TerraformStack {
9
+ id;
10
+ fullyQualifiedDomainName;
11
+ storageManager;
12
+ constructor(scope, id, props) {
13
+ super(scope, id);
14
+ this.props = props;
15
+ this.id = id;
16
+ this.storageManager = new services_1.AzureStorageManager();
17
+ this.determineFullyQualifiedDomain();
18
+ new provider_1.AzurermProvider(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.CommonAzureConstruct = CommonAzureConstruct;
@@ -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 { CommonAzureConstruct } from './construct';
2
+ import { CommonAzureStackProps } 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 { CommonAzureStack } from '@gradientedge/cdk-utils'
9
+ *
10
+ * class CustomStack extends CommonAzureStack {
11
+ * constructor(parent: App, name: string, props: StackProps) {
12
+ * super(parent, name, props)
13
+ * // provision resources
14
+ * }
15
+ * }
16
+ */
17
+ export declare class CommonAzureStack extends TerraformStack {
18
+ construct: CommonAzureConstruct;
19
+ props: CommonAzureStackProps;
20
+ constructor(parent: Construct, name: string, props: CommonAzureStackProps);
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: CommonAzureStackProps): {
27
+ domainName: any;
28
+ extraContexts: any;
29
+ features: any;
30
+ name: any;
31
+ resourceGroupName: 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,136 @@
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.CommonAzureStack = 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 common_1 = require("../../common");
12
+ /**
13
+ * @classdesc Common stack to use as a base for all higher level constructs.
14
+ * @example
15
+ * import { CommonAzureStack } from '@gradientedge/cdk-utils'
16
+ *
17
+ * class CustomStack extends CommonAzureStack {
18
+ * constructor(parent: App, name: string, props: StackProps) {
19
+ * super(parent, name, props)
20
+ * // provision resources
21
+ * }
22
+ * }
23
+ */
24
+ class CommonAzureStack extends cdktf_1.TerraformStack {
25
+ construct;
26
+ props;
27
+ constructor(parent, name, props) {
28
+ super(parent, name);
29
+ /* determine extra cdk contexts */
30
+ this.determineExtraContexts();
31
+ /* determine extra cdk stage contexts */
32
+ this.determineStageContexts();
33
+ this.props = this.determineConstructProps(props);
34
+ /* initialise the construct */
35
+ this.construct = new construct_1.CommonAzureConstruct(this, 'cdk-utils', this.props);
36
+ }
37
+ /**
38
+ * @summary Method to determine the core CDK construct properties injected via context cdktf.json
39
+ * @param props The stack properties
40
+ * @returns The stack properties
41
+ */
42
+ determineConstructProps(props) {
43
+ return {
44
+ domainName: this.node.tryGetContext('domainName'),
45
+ extraContexts: this.node.tryGetContext('extraContexts'),
46
+ features: this.node.tryGetContext('features'),
47
+ name: this.node.tryGetContext('resourceGroupName'),
48
+ resourceGroupName: this.node.tryGetContext('resourceGroupName'),
49
+ skipStageForARecords: this.node.tryGetContext('skipStageForARecords'),
50
+ stage: this.node.tryGetContext('stage'),
51
+ subDomain: this.node.tryGetContext('subDomain'),
52
+ };
53
+ }
54
+ /**
55
+ * @summary Method to determine extra cdk contexts apart from the main cdktf.json
56
+ * - Sets the properties from the extra contexts into cdk node context
57
+ * - Primary use is to have layered config in separate files to enable easier maintenance and readability
58
+ */
59
+ determineExtraContexts() {
60
+ const extraContexts = this.node.tryGetContext('extraContexts');
61
+ const debug = this.node.tryGetContext('debug');
62
+ if (!extraContexts) {
63
+ if (debug)
64
+ console.debug(`No additional contexts provided. Using default context properties from cdktf.json`);
65
+ return;
66
+ }
67
+ extraContexts.forEach((context) => {
68
+ const extraContextPath = `${app_root_path_1.default.path}/${context}`;
69
+ /* scenario where extra context is configured in cdk.json but absent in file system */
70
+ if (!fs_1.default.existsSync(extraContextPath))
71
+ throw `Extra context properties unavailable in path:${extraContextPath}`;
72
+ /* read the extra properties */
73
+ const extraContextPropsBuffer = fs_1.default.readFileSync(extraContextPath);
74
+ if (debug)
75
+ console.debug(`Adding additional contexts provided in ${extraContextPath}`);
76
+ /* parse as JSON properties */
77
+ const extraContextProps = JSON.parse(extraContextPropsBuffer.toString('utf-8'));
78
+ /* set each of the property into the cdk node context */
79
+ Object.keys(extraContextProps).forEach((propKey) => {
80
+ this.node.setContext(propKey, extraContextProps[propKey]);
81
+ });
82
+ });
83
+ }
84
+ /**
85
+ * @summary Method to determine extra cdk stage contexts apart from the main cdktf.json
86
+ * - Sets the properties from the extra stage contexts into cdk node context
87
+ * - Primary use is to have layered config for each environment which is injected into the context
88
+ */
89
+ determineStageContexts() {
90
+ const stage = this.node.tryGetContext('stage');
91
+ const stageContextPath = this.node.tryGetContext('stageContextPath') || 'cdkEnv';
92
+ const stageContextFilePath = `${app_root_path_1.default.path}/${stageContextPath}/${stage}.json`;
93
+ const debug = this.node.tryGetContext('debug');
94
+ if ((0, common_1.isDevStage)(stage)) {
95
+ if (debug)
96
+ console.debug(`Development stage. Using default stage context properties`);
97
+ }
98
+ /* alert default context usage when extra stage config is missing */
99
+ if (!fs_1.default.existsSync(stageContextFilePath)) {
100
+ if (debug)
101
+ console.debug(`Stage specific context properties unavailable in path:${stageContextFilePath}`);
102
+ if (debug)
103
+ console.debug(`Using default stage context properties for ${stage} stage`);
104
+ return;
105
+ }
106
+ /* read the extra properties */
107
+ const stageContextPropsBuffer = fs_1.default.readFileSync(stageContextFilePath);
108
+ if (debug)
109
+ console.debug(`Adding additional stage contexts provided in ${stageContextFilePath}`);
110
+ /* parse as JSON properties */
111
+ const stageContextProps = JSON.parse(stageContextPropsBuffer.toString('utf-8'));
112
+ /* set each of the property into the cdk node context */
113
+ Object.keys(stageContextProps).forEach((propKey) => {
114
+ /* handle object, array properties */
115
+ if (typeof stageContextProps[propKey] === 'object' && !Array.isArray(stageContextProps[propKey])) {
116
+ this.node.setContext(propKey, {
117
+ ...this.node.tryGetContext(propKey),
118
+ ...stageContextProps[propKey],
119
+ });
120
+ }
121
+ else {
122
+ /* handle all other primitive properties */
123
+ this.node.setContext(propKey, stageContextProps[propKey]);
124
+ }
125
+ });
126
+ }
127
+ /**
128
+ * @summary Determine the fully qualified domain name based on domainName & subDomain
129
+ */
130
+ fullyQualifiedDomain() {
131
+ const domainName = this.node.tryGetContext('domainName');
132
+ const subDomain = this.node.tryGetContext('subDomain');
133
+ return subDomain ? `${subDomain}.${domainName}` : domainName;
134
+ }
135
+ }
136
+ exports.CommonAzureStack = CommonAzureStack;
@@ -0,0 +1,7 @@
1
+ import { AzurermProviderConfig } from '@cdktf/provider-azurerm/lib/provider';
2
+ import { BaseProps } from '../../common';
3
+ /**
4
+ */
5
+ export interface CommonAzureStackProps extends BaseProps, AzurermProviderConfig {
6
+ resourceGroupName?: string;
7
+ }
@@ -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 './storage';
@@ -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("./storage"), 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);