@gradientedge/cdk-utils 8.135.0 → 8.137.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 (47) hide show
  1. package/dist/src/lib/azure/services/storage/main.d.ts +3 -1
  2. package/dist/src/lib/azure/services/storage/main.js +12 -10
  3. package/dist/src/lib/azure/services/storage/types.d.ts +3 -3
  4. package/dist/src/lib/azure/types/index.d.ts +1 -1
  5. package/dist/src/lib/azure/utils/index.d.ts +1 -1
  6. package/dist/src/lib/azure/utils/index.js +3 -3
  7. package/dist/src/lib/cloudflare/common/construct.d.ts +35 -0
  8. package/dist/src/lib/cloudflare/common/construct.js +49 -0
  9. package/dist/src/lib/cloudflare/common/index.d.ts +3 -0
  10. package/dist/src/lib/cloudflare/common/index.js +19 -0
  11. package/dist/src/lib/cloudflare/common/stack.d.ts +52 -0
  12. package/dist/src/lib/cloudflare/common/stack.js +134 -0
  13. package/dist/src/lib/cloudflare/common/types.d.ts +7 -0
  14. package/dist/src/lib/cloudflare/common/types.js +2 -0
  15. package/dist/src/lib/cloudflare/index.d.ts +4 -0
  16. package/dist/src/lib/cloudflare/index.js +20 -0
  17. package/dist/src/lib/cloudflare/services/index.d.ts +1 -0
  18. package/dist/src/lib/cloudflare/services/index.js +17 -0
  19. package/dist/src/lib/cloudflare/services/zone/index.d.ts +2 -0
  20. package/dist/src/lib/cloudflare/services/zone/index.js +18 -0
  21. package/dist/src/lib/cloudflare/services/zone/main.d.ts +86 -0
  22. package/dist/src/lib/cloudflare/services/zone/main.js +188 -0
  23. package/dist/src/lib/cloudflare/services/zone/types.d.ts +25 -0
  24. package/dist/src/lib/cloudflare/services/zone/types.js +2 -0
  25. package/dist/src/lib/cloudflare/types/index.d.ts +3 -0
  26. package/dist/src/lib/cloudflare/types/index.js +2 -0
  27. package/dist/src/lib/cloudflare/utils/index.d.ts +3 -0
  28. package/dist/src/lib/cloudflare/utils/index.js +20 -0
  29. package/dist/src/lib/index.d.ts +1 -0
  30. package/dist/src/lib/index.js +1 -0
  31. package/package.json +14 -12
  32. package/src/lib/azure/services/storage/main.ts +13 -11
  33. package/src/lib/azure/services/storage/types.ts +3 -3
  34. package/src/lib/azure/types/index.ts +1 -1
  35. package/src/lib/azure/utils/index.ts +1 -1
  36. package/src/lib/cloudflare/common/construct.ts +57 -0
  37. package/src/lib/cloudflare/common/index.ts +3 -0
  38. package/src/lib/cloudflare/common/stack.ts +143 -0
  39. package/src/lib/cloudflare/common/types.ts +8 -0
  40. package/src/lib/cloudflare/index.ts +4 -0
  41. package/src/lib/cloudflare/services/index.ts +1 -0
  42. package/src/lib/cloudflare/services/zone/index.ts +2 -0
  43. package/src/lib/cloudflare/services/zone/main.ts +218 -0
  44. package/src/lib/cloudflare/services/zone/types.ts +19 -0
  45. package/src/lib/cloudflare/types/index.ts +3 -0
  46. package/src/lib/cloudflare/utils/index.ts +23 -0
  47. package/src/lib/index.ts +1 -0
@@ -0,0 +1,188 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CloudflareZoneManager = void 0;
4
+ const data_cloudflare_zone_1 = require("@cdktf/provider-cloudflare/lib/data-cloudflare-zone");
5
+ const zone_1 = require("@cdktf/provider-cloudflare/lib/zone");
6
+ const zone_cache_reserve_1 = require("@cdktf/provider-cloudflare/lib/zone-cache-reserve");
7
+ const zone_cache_variants_1 = require("@cdktf/provider-cloudflare/lib/zone-cache-variants");
8
+ const zone_dnssec_1 = require("@cdktf/provider-cloudflare/lib/zone-dnssec");
9
+ const zone_hold_1 = require("@cdktf/provider-cloudflare/lib/zone-hold");
10
+ const zone_lockdown_1 = require("@cdktf/provider-cloudflare/lib/zone-lockdown");
11
+ const zone_settings_override_1 = require("@cdktf/provider-cloudflare/lib/zone-settings-override");
12
+ const utils_1 = require("../../utils");
13
+ /**
14
+ * @classdesc Provides operations on Cloudflare Zone
15
+ * - A new instance of this class is injected into {@link CommonCloudflareConstruct} constructor.
16
+ * - If a custom construct extends {@link CommonCloudflareConstruct}, an instance is available within the context.
17
+ * @example
18
+ * ```
19
+ * import { CommonCloudflareConstruct, CommonCloudflareConstruct } from '@gradientedge/cdk-utils'
20
+ *
21
+ * class CustomConstruct extends CommonCloudflareConstruct {
22
+ * constructor(parent: Construct, id: string, props: CommonCloudflareStackProps) {
23
+ * super(parent, id, props)
24
+ * this.props = props
25
+ * this.zoneManager.createZone('MyZone', this, props)
26
+ * }
27
+ * }
28
+ * ```
29
+ */
30
+ class CloudflareZoneManager {
31
+ /**
32
+ * @summary Method to create a new zone
33
+ * @param id scoped id of the resource
34
+ * @param scope scope in which this resource is defined
35
+ * @param props zone properties
36
+ * @see [CDKTF Zone Module]{@link https://github.com/cdktf/cdktf-provider-cloudflare/blob/main/docs/zone.typescript.md}
37
+ */
38
+ createZone(id, scope, props) {
39
+ if (!props)
40
+ throw `Props undefined for ${id}`;
41
+ const zone = new zone_1.Zone(scope, `${id}`, {
42
+ ...props,
43
+ accountId: props.accountId ?? scope.props.accountId,
44
+ zone: props.zone ?? scope.props.domainName,
45
+ });
46
+ (0, utils_1.createCloudflareTfOutput)(`${id}-zoneName`, scope, zone.zone);
47
+ (0, utils_1.createCloudflareTfOutput)(`${id}-zoneFriendlyUniqueId`, scope, zone.friendlyUniqueId);
48
+ (0, utils_1.createCloudflareTfOutput)(`${id}-zoneId`, scope, zone.id);
49
+ return zone;
50
+ }
51
+ resolveZone(id, scope, options) {
52
+ if (!options)
53
+ throw `Options undefined for ${id}`;
54
+ const zone = new data_cloudflare_zone_1.DataCloudflareZone(scope, `${id}-data-zone`, {
55
+ accountId: scope.props.accountId,
56
+ name: options.name ?? scope.props.domainName,
57
+ zoneId: options.id,
58
+ });
59
+ return zone;
60
+ }
61
+ /**
62
+ * @summary Method to create a new zone cache reserve
63
+ * @param id scoped id of the resource
64
+ * @param scope scope in which this resource is defined
65
+ * @param props zone cache reserve properties
66
+ * @see [CDKTF Zone Cache Reserve Module]{@link https://github.com/cdktf/cdktf-provider-cloudflare/blob/main/docs/zoneCacheReserve.typescript.md}
67
+ */
68
+ createZoneCacheReserve(id, scope, props) {
69
+ if (!props)
70
+ throw `Props undefined for ${id}`;
71
+ const zoneId = props.zoneId
72
+ ? props.zoneId
73
+ : this.resolveZone(`${id}-data-zone`, scope, { name: scope.props.domainName })?.id;
74
+ const zoneCacheReserve = new zone_cache_reserve_1.ZoneCacheReserve(scope, `${id}`, {
75
+ ...props,
76
+ zoneId,
77
+ });
78
+ (0, utils_1.createCloudflareTfOutput)(`${id}-zoneCacheReserveFriendlyUniqueId`, scope, zoneCacheReserve.friendlyUniqueId);
79
+ (0, utils_1.createCloudflareTfOutput)(`${id}-zoneCacheReserveId`, scope, zoneCacheReserve.id);
80
+ return zoneCacheReserve;
81
+ }
82
+ /**
83
+ * @summary Method to create a new zone cache variants
84
+ * @param id scoped id of the resource
85
+ * @param scope scope in which this resource is defined
86
+ * @param props zone cache variants properties
87
+ * @see [CDKTF Zone Cache Variants Module]{@link https://github.com/cdktf/cdktf-provider-cloudflare/blob/main/docs/zoneCacheVariants.typescript.md}
88
+ */
89
+ createZoneCacheVariants(id, scope, props) {
90
+ if (!props)
91
+ throw `Props undefined for ${id}`;
92
+ const zoneId = props.zoneId
93
+ ? props.zoneId
94
+ : this.resolveZone(`${id}-data-zone`, scope, { name: scope.props.domainName })?.id;
95
+ const zoneCacheVariants = new zone_cache_variants_1.ZoneCacheVariants(scope, `${id}`, {
96
+ ...props,
97
+ zoneId,
98
+ });
99
+ (0, utils_1.createCloudflareTfOutput)(`${id}-zoneCacheVariantsFriendlyUniqueId`, scope, zoneCacheVariants.friendlyUniqueId);
100
+ (0, utils_1.createCloudflareTfOutput)(`${id}-zoneCacheVariantsId`, scope, zoneCacheVariants.id);
101
+ return zoneCacheVariants;
102
+ }
103
+ /**
104
+ * @summary Method to create a new zone dnssec
105
+ * @param id scoped id of the resource
106
+ * @param scope scope in which this resource is defined
107
+ * @param props zone dnssec properties
108
+ * @see [CDKTF Zone DNS Security Module]{@link https://github.com/cdktf/cdktf-provider-cloudflare/blob/main/docs/zoneDnssec.typescript.md}
109
+ */
110
+ createZoneDnssec(id, scope, props) {
111
+ if (!props)
112
+ throw `Props undefined for ${id}`;
113
+ const zoneId = props.zoneId
114
+ ? props.zoneId
115
+ : this.resolveZone(`${id}-data-zone`, scope, { name: scope.props.domainName })?.id;
116
+ const zoneDnssec = new zone_dnssec_1.ZoneDnssec(scope, `${id}`, {
117
+ ...props,
118
+ zoneId,
119
+ });
120
+ (0, utils_1.createCloudflareTfOutput)(`${id}-zoneDnssecFriendlyUniqueId`, scope, zoneDnssec.friendlyUniqueId);
121
+ (0, utils_1.createCloudflareTfOutput)(`${id}-zoneDnssecId`, scope, zoneDnssec.id);
122
+ return zoneDnssec;
123
+ }
124
+ /**
125
+ * @summary Method to create a new zone hold
126
+ * @param id scoped id of the resource
127
+ * @param scope scope in which this resource is defined
128
+ * @param props zone hold properties
129
+ * @see [CDKTF Zone Hold Security Module]{@link https://github.com/cdktf/cdktf-provider-cloudflare/blob/main/docs/zoneHold.typescript.md}
130
+ */
131
+ createZoneHold(id, scope, props) {
132
+ if (!props)
133
+ throw `Props undefined for ${id}`;
134
+ const zoneId = props.zoneId
135
+ ? props.zoneId
136
+ : this.resolveZone(`${id}-data-zone`, scope, { name: scope.props.domainName })?.id;
137
+ const zoneHold = new zone_hold_1.ZoneHold(scope, `${id}`, {
138
+ ...props,
139
+ zoneId,
140
+ });
141
+ (0, utils_1.createCloudflareTfOutput)(`${id}-zoneHoldFriendlyUniqueId`, scope, zoneHold.friendlyUniqueId);
142
+ (0, utils_1.createCloudflareTfOutput)(`${id}-zoneHoldId`, scope, zoneHold.id);
143
+ return zoneHold;
144
+ }
145
+ /**
146
+ * @summary Method to create a new zone lockdown
147
+ * @param id scoped id of the resource
148
+ * @param scope scope in which this resource is defined
149
+ * @param props zone lockdown properties
150
+ * @see [CDKTF Zone Lockdown Module]{@link https://github.com/cdktf/cdktf-provider-cloudflare/blob/main/docs/zoneLockdown.typescript.md}
151
+ */
152
+ createZoneLockdown(id, scope, props) {
153
+ if (!props)
154
+ throw `Props undefined for ${id}`;
155
+ const zoneId = props.zoneId
156
+ ? props.zoneId
157
+ : this.resolveZone(`${id}-data-zone`, scope, { name: scope.props.domainName })?.id;
158
+ const zoneLockdown = new zone_lockdown_1.ZoneLockdown(scope, `${id}`, {
159
+ ...props,
160
+ zoneId,
161
+ });
162
+ (0, utils_1.createCloudflareTfOutput)(`${id}-zoneLockdownFriendlyUniqueId`, scope, zoneLockdown.friendlyUniqueId);
163
+ (0, utils_1.createCloudflareTfOutput)(`${id}-zoneLockdownId`, scope, zoneLockdown.id);
164
+ return zoneLockdown;
165
+ }
166
+ /**
167
+ * @summary Method to create a new zone settings override
168
+ * @param id scoped id of the resource
169
+ * @param scope scope in which this resource is defined
170
+ * @param props zone settings override properties
171
+ * @see [CDKTF Zone Settings Override Module]{@link https://github.com/cdktf/cdktf-provider-cloudflare/blob/main/docs/zoneSettingsOverride.typescript.md}
172
+ */
173
+ createZoneSettingsOverride(id, scope, props) {
174
+ if (!props)
175
+ throw `Props undefined for ${id}`;
176
+ const zoneId = props.zoneId
177
+ ? props.zoneId
178
+ : this.resolveZone(`${id}-data-zone`, scope, { name: scope.props.domainName })?.id;
179
+ const zoneSettingsOverride = new zone_settings_override_1.ZoneSettingsOverride(scope, `${id}`, {
180
+ ...props,
181
+ zoneId,
182
+ });
183
+ (0, utils_1.createCloudflareTfOutput)(`${id}-zoneSettingsOverrideFriendlyUniqueId`, scope, zoneSettingsOverride.friendlyUniqueId);
184
+ (0, utils_1.createCloudflareTfOutput)(`${id}-zoneSettingsOverrideId`, scope, zoneSettingsOverride.id);
185
+ return zoneSettingsOverride;
186
+ }
187
+ }
188
+ exports.CloudflareZoneManager = CloudflareZoneManager;
@@ -0,0 +1,25 @@
1
+ import { ZoneConfig } from '@cdktf/provider-cloudflare/lib/zone';
2
+ import { ZoneCacheReserveConfig } from '@cdktf/provider-cloudflare/lib/zone-cache-reserve';
3
+ import { ZoneCacheVariantsConfig } from '@cdktf/provider-cloudflare/lib/zone-cache-variants';
4
+ import { ZoneDnssecConfig } from '@cdktf/provider-cloudflare/lib/zone-dnssec';
5
+ import { ZoneHoldConfig } from '@cdktf/provider-cloudflare/lib/zone-hold';
6
+ import { ZoneLockdownConfig } from '@cdktf/provider-cloudflare/lib/zone-lockdown';
7
+ import { ZoneSettingsOverrideConfig } from '@cdktf/provider-cloudflare/lib/zone-settings-override';
8
+ export interface ZoneProps extends ZoneConfig {
9
+ }
10
+ export interface ZoneOptions {
11
+ id?: string;
12
+ name?: string;
13
+ }
14
+ export interface ZoneCacheReserveProps extends ZoneCacheReserveConfig {
15
+ }
16
+ export interface ZoneCacheVariantsProps extends ZoneCacheVariantsConfig {
17
+ }
18
+ export interface ZoneDnssecProps extends ZoneDnssecConfig {
19
+ }
20
+ export interface ZoneHoldProps extends ZoneHoldConfig {
21
+ }
22
+ export interface ZoneLockdownProps extends ZoneLockdownConfig {
23
+ }
24
+ export interface ZoneSettingsOverrideProps extends ZoneSettingsOverrideConfig {
25
+ }
@@ -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.135.0",
3
+ "version": "8.137.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.449.0",
50
- "@aws-sdk/credential-providers": "^3.449.0",
51
- "@aws-sdk/types": "^3.449.0",
52
- "@cdktf/provider-azurerm": "^11.0.4",
50
+ "@aws-sdk/client-secrets-manager": "^3.454.0",
51
+ "@aws-sdk/credential-providers": "^3.454.0",
52
+ "@aws-sdk/types": "^3.451.0",
53
+ "@cdktf/provider-azurerm": "^11.0.5",
54
+ "@cdktf/provider-cloudflare": "^10.0.3",
53
55
  "@types/lodash": "^4.14.201",
54
- "@types/node": "^20.9.0",
56
+ "@types/node": "^20.9.2",
55
57
  "@types/uuid": "^9.0.7",
56
58
  "app-root-path": "^3.1.0",
57
- "aws-cdk-lib": "^2.106.1",
59
+ "aws-cdk-lib": "^2.110.0",
58
60
  "cdktf": "^0.19.1",
59
61
  "constructs": "^10.3.0",
60
62
  "lodash": "^4.17.21",
@@ -69,15 +71,15 @@
69
71
  "@babel/eslint-parser": "^7.23.3",
70
72
  "@babel/plugin-proposal-class-properties": "^7.18.6",
71
73
  "@types/jest": "^29.5.8",
72
- "@typescript-eslint/eslint-plugin": "^6.10.0",
73
- "@typescript-eslint/parser": "^6.10.0",
74
- "aws-cdk": "^2.106.1",
74
+ "@typescript-eslint/eslint-plugin": "^6.11.0",
75
+ "@typescript-eslint/parser": "^6.11.0",
76
+ "aws-cdk": "^2.110.0",
75
77
  "better-docs": "^2.7.2",
76
78
  "codecov": "^3.8.3",
77
79
  "commitizen": "^4.3.0",
78
80
  "docdash": "^2.0.2",
79
81
  "dotenv": "^16.3.1",
80
- "eslint": "^8.53.0",
82
+ "eslint": "^8.54.0",
81
83
  "eslint-config-prettier": "^9.0.0",
82
84
  "eslint-plugin-import": "^2.29.0",
83
85
  "eslint-plugin-jsdoc": "^46.9.0",
@@ -93,7 +95,7 @@
93
95
  "prettier": "^3.1.0",
94
96
  "prettier-plugin-organize-imports": "^3.2.4",
95
97
  "rimraf": "^5.0.5",
96
- "semantic-release": "^22.0.7",
98
+ "semantic-release": "^22.0.8",
97
99
  "taffydb": "^2.7.3",
98
100
  "ts-jest": "^29.1.1",
99
101
  "ts-node": "^10.9.1",
@@ -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'