@gradientedge/cdk-utils 10.0.0 → 10.2.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 (112) hide show
  1. package/dist/src/lib/azure/common/constants.d.ts +3 -2
  2. package/dist/src/lib/azure/common/constants.js +2 -1
  3. package/dist/src/lib/azure/common/construct.d.ts +26 -12
  4. package/dist/src/lib/azure/common/construct.js +31 -45
  5. package/dist/src/lib/azure/common/resource-name-formatter.d.ts +9 -4
  6. package/dist/src/lib/azure/common/resource-name-formatter.js +9 -5
  7. package/dist/src/lib/azure/common/stack.d.ts +18 -32
  8. package/dist/src/lib/azure/common/stack.js +77 -74
  9. package/dist/src/lib/azure/common/tagging.d.ts +29 -8
  10. package/dist/src/lib/azure/common/tagging.js +72 -26
  11. package/dist/src/lib/azure/common/types.d.ts +19 -4
  12. package/dist/src/lib/azure/services/api-management/main.d.ts +29 -32
  13. package/dist/src/lib/azure/services/api-management/main.js +100 -121
  14. package/dist/src/lib/azure/services/api-management/types.d.ts +33 -18
  15. package/dist/src/lib/azure/services/app-configuration/main.d.ts +6 -7
  16. package/dist/src/lib/azure/services/app-configuration/main.js +23 -26
  17. package/dist/src/lib/azure/services/app-configuration/types.d.ts +2 -2
  18. package/dist/src/lib/azure/services/app-service/main.d.ts +10 -12
  19. package/dist/src/lib/azure/services/app-service/main.js +37 -49
  20. package/dist/src/lib/azure/services/app-service/types.d.ts +4 -4
  21. package/dist/src/lib/azure/services/application-insights/main.d.ts +7 -8
  22. package/dist/src/lib/azure/services/application-insights/main.js +20 -26
  23. package/dist/src/lib/azure/services/application-insights/types.d.ts +2 -4
  24. package/dist/src/lib/azure/services/cosmosdb/main.d.ts +12 -15
  25. package/dist/src/lib/azure/services/cosmosdb/main.js +42 -61
  26. package/dist/src/lib/azure/services/cosmosdb/types.d.ts +4 -6
  27. package/dist/src/lib/azure/services/dns/main.d.ts +13 -17
  28. package/dist/src/lib/azure/services/dns/main.js +33 -51
  29. package/dist/src/lib/azure/services/dns/types.d.ts +5 -8
  30. package/dist/src/lib/azure/services/eventgrid/main.d.ts +20 -22
  31. package/dist/src/lib/azure/services/eventgrid/main.js +61 -89
  32. package/dist/src/lib/azure/services/eventgrid/types.d.ts +7 -8
  33. package/dist/src/lib/azure/services/function/main.d.ts +15 -15
  34. package/dist/src/lib/azure/services/function/main.js +54 -59
  35. package/dist/src/lib/azure/services/function/types.d.ts +18 -6
  36. package/dist/src/lib/azure/services/index.d.ts +1 -1
  37. package/dist/src/lib/azure/services/index.js +1 -1
  38. package/dist/src/lib/azure/services/key-vault/main.d.ts +6 -7
  39. package/dist/src/lib/azure/services/key-vault/main.js +29 -28
  40. package/dist/src/lib/azure/services/key-vault/types.d.ts +3 -2
  41. package/dist/src/lib/azure/services/monitor/main.d.ts +7 -8
  42. package/dist/src/lib/azure/services/monitor/main.js +10 -15
  43. package/dist/src/lib/azure/services/monitor/types.d.ts +2 -2
  44. package/dist/src/lib/azure/services/operational-insights/main.d.ts +29 -0
  45. package/dist/src/lib/azure/services/operational-insights/main.js +50 -0
  46. package/dist/src/lib/azure/services/operational-insights/types.d.ts +3 -0
  47. package/dist/src/lib/azure/services/redis/main.d.ts +8 -9
  48. package/dist/src/lib/azure/services/redis/main.js +24 -26
  49. package/dist/src/lib/azure/services/redis/types.d.ts +2 -2
  50. package/dist/src/lib/azure/services/resource-group/main.d.ts +6 -7
  51. package/dist/src/lib/azure/services/resource-group/main.js +9 -14
  52. package/dist/src/lib/azure/services/resource-group/types.d.ts +2 -2
  53. package/dist/src/lib/azure/services/servicebus/main.d.ts +17 -22
  54. package/dist/src/lib/azure/services/servicebus/main.js +47 -70
  55. package/dist/src/lib/azure/services/servicebus/types.d.ts +6 -10
  56. package/dist/src/lib/azure/services/storage/main.d.ts +24 -27
  57. package/dist/src/lib/azure/services/storage/main.js +70 -88
  58. package/dist/src/lib/azure/services/storage/types.d.ts +10 -8
  59. package/dist/src/lib/azure/types/index.d.ts +2 -1
  60. package/dist/src/lib/azure/utils/index.d.ts +19 -3
  61. package/dist/src/lib/azure/utils/index.js +19 -13
  62. package/dist/src/lib/cloudflare/common/stack.js +1 -1
  63. package/package.json +28 -27
  64. package/src/lib/azure/common/constants.ts +2 -1
  65. package/src/lib/azure/common/construct.ts +32 -48
  66. package/src/lib/azure/common/resource-name-formatter.ts +10 -6
  67. package/src/lib/azure/common/stack.ts +78 -78
  68. package/src/lib/azure/common/tagging.ts +78 -29
  69. package/src/lib/azure/common/types.ts +21 -4
  70. package/src/lib/azure/services/api-management/main.ts +172 -169
  71. package/src/lib/azure/services/api-management/types.ts +39 -16
  72. package/src/lib/azure/services/app-configuration/main.ts +33 -31
  73. package/src/lib/azure/services/app-configuration/types.ts +2 -2
  74. package/src/lib/azure/services/app-service/main.ts +61 -62
  75. package/src/lib/azure/services/app-service/types.ts +4 -4
  76. package/src/lib/azure/services/application-insights/main.ts +29 -30
  77. package/src/lib/azure/services/application-insights/types.ts +2 -5
  78. package/src/lib/azure/services/cosmosdb/main.ts +78 -77
  79. package/src/lib/azure/services/cosmosdb/types.ts +10 -6
  80. package/src/lib/azure/services/dns/main.ts +65 -72
  81. package/src/lib/azure/services/dns/types.ts +9 -9
  82. package/src/lib/azure/services/eventgrid/main.ts +120 -122
  83. package/src/lib/azure/services/eventgrid/types.ts +13 -8
  84. package/src/lib/azure/services/function/main.ts +75 -72
  85. package/src/lib/azure/services/function/types.ts +21 -6
  86. package/src/lib/azure/services/index.ts +1 -1
  87. package/src/lib/azure/services/key-vault/main.ts +38 -32
  88. package/src/lib/azure/services/key-vault/types.ts +4 -2
  89. package/src/lib/azure/services/monitor/main.ts +17 -21
  90. package/src/lib/azure/services/monitor/types.ts +2 -2
  91. package/src/lib/azure/services/operational-insights/main.ts +61 -0
  92. package/src/lib/azure/services/operational-insights/types.ts +3 -0
  93. package/src/lib/azure/services/redis/main.ts +30 -30
  94. package/src/lib/azure/services/redis/types.ts +2 -2
  95. package/src/lib/azure/services/resource-group/main.ts +20 -20
  96. package/src/lib/azure/services/resource-group/types.ts +2 -2
  97. package/src/lib/azure/services/servicebus/main.ts +103 -94
  98. package/src/lib/azure/services/servicebus/types.ts +17 -11
  99. package/src/lib/azure/services/storage/main.ts +113 -114
  100. package/src/lib/azure/services/storage/types.ts +16 -8
  101. package/src/lib/azure/types/index.ts +2 -1
  102. package/src/lib/azure/utils/index.ts +20 -22
  103. package/src/lib/cloudflare/common/stack.ts +1 -1
  104. package/dist/src/lib/azure/services/log-analytics-workspace/main.d.ts +0 -30
  105. package/dist/src/lib/azure/services/log-analytics-workspace/main.js +0 -55
  106. package/dist/src/lib/azure/services/log-analytics-workspace/types.d.ts +0 -3
  107. package/src/lib/azure/services/log-analytics-workspace/main.ts +0 -61
  108. package/src/lib/azure/services/log-analytics-workspace/types.ts +0 -3
  109. /package/dist/src/lib/azure/services/{log-analytics-workspace → operational-insights}/index.d.ts +0 -0
  110. /package/dist/src/lib/azure/services/{log-analytics-workspace → operational-insights}/index.js +0 -0
  111. /package/dist/src/lib/azure/services/{log-analytics-workspace → operational-insights}/types.js +0 -0
  112. /package/src/lib/azure/services/{log-analytics-workspace → operational-insights}/index.ts +0 -0
@@ -89,7 +89,7 @@ export class CommonCloudflareStack extends ComponentResource {
89
89
  * - Primary use is to have layered config for each environment which is injected into the context
90
90
  */
91
91
  determineStageContexts(props) {
92
- const stageContextFilePath = path.join(appRoot.path, props.stageContextPath ?? 'cdkEnv', `${props.stage}.json`);
92
+ const stageContextFilePath = path.join(appRoot.path, props.stageContextPath ?? 'env', `${props.stage}.json`);
93
93
  if (isDevStage(props.stage)) {
94
94
  if (props.debug)
95
95
  console.debug(`Development stage. Using default stage context properties`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gradientedge/cdk-utils",
3
- "version": "10.0.0",
3
+ "version": "10.2.0",
4
4
  "description": "Utilities for AWS CDK provisioning",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -14,7 +14,7 @@
14
14
  "node": ">=22 <=24",
15
15
  "pnpm": "=10"
16
16
  },
17
- "packageManager": "pnpm@10.26.0",
17
+ "packageManager": "pnpm@10.28.2",
18
18
  "repository": {
19
19
  "type": "git",
20
20
  "url": "git+https://github.com/gradientedge/cdk-utils.git"
@@ -55,27 +55,28 @@
55
55
  "prepare": "husky"
56
56
  },
57
57
  "dependencies": {
58
- "@aws-sdk/client-secrets-manager": "^3.953.0",
59
- "@aws-sdk/credential-providers": "^3.953.0",
60
- "@aws-sdk/types": "^3.953.0",
58
+ "@aws-sdk/client-secrets-manager": "^3.975.0",
59
+ "@aws-sdk/credential-providers": "^3.975.0",
60
+ "@aws-sdk/types": "^3.973.1",
61
61
  "@cdktf/provider-aws": "^21.22.1",
62
62
  "@cdktf/provider-azurerm": "^14.23.1",
63
63
  "@cdktf/provider-cloudflare": "^13.9.1",
64
- "@pulumi/aws": "^7.14.0",
65
- "@pulumi/azure-native": "^3.11.0",
66
- "@pulumi/cloudflare": "^6.11.0",
64
+ "@pulumi/aws": "^7.16.0",
65
+ "@pulumi/azure": "^6.31.0",
66
+ "@pulumi/azure-native": "^3.12.1",
67
+ "@pulumi/cloudflare": "^6.13.0",
67
68
  "@pulumi/command": "^1.1.3",
68
- "@pulumi/pulumi": "^3.213.0",
69
+ "@pulumi/pulumi": "^3.217.1",
69
70
  "@pulumi/std": "^2.2.0",
70
- "@types/lodash": "^4.17.21",
71
- "@types/node": "^25.0.3",
71
+ "@types/lodash": "^4.17.23",
72
+ "@types/node": "^25.0.10",
72
73
  "@types/uuid": "^11.0.0",
73
74
  "app-root-path": "^3.1.0",
74
- "aws-cdk-lib": "^2.232.2",
75
+ "aws-cdk-lib": "^2.236.0",
75
76
  "cdktf": "^0.21.0",
76
77
  "cdktf-local-exec": "^0.6.28",
77
- "constructs": "^10.4.4",
78
- "lodash": "^4.17.21",
78
+ "constructs": "^10.4.5",
79
+ "lodash": "^4.17.23",
79
80
  "moment": "^2.30.1",
80
81
  "nconf": "^0.13.0",
81
82
  "pluralize": "^8.0.0",
@@ -83,16 +84,16 @@
83
84
  "uuid": "^13.0.0"
84
85
  },
85
86
  "devDependencies": {
86
- "@babel/core": "^7.28.5",
87
- "@babel/eslint-parser": "^7.28.5",
87
+ "@babel/core": "^7.28.6",
88
+ "@babel/eslint-parser": "^7.28.6",
88
89
  "@babel/plugin-proposal-class-properties": "^7.18.6",
89
90
  "@eslint/config-array": "^0.23.0",
90
91
  "@eslint/object-schema": "^3.0.0",
91
- "@types/node": "^25.0.3",
92
- "@typescript-eslint/eslint-plugin": "^8.50.0",
93
- "@typescript-eslint/parser": "^8.50.0",
94
- "@vitest/coverage-v8": "^2.1.8",
95
- "aws-cdk": "^2.1100.1",
92
+ "@types/node": "^25.0.10",
93
+ "@typescript-eslint/eslint-plugin": "^8.54.0",
94
+ "@typescript-eslint/parser": "^8.54.0",
95
+ "@vitest/coverage-v8": "^4.0.18",
96
+ "aws-cdk": "^2.1103.0",
96
97
  "better-docs": "^2.7.3",
97
98
  "codecov": "^3.8.3",
98
99
  "commitizen": "^4.3.1",
@@ -102,25 +103,25 @@
102
103
  "eslint": "^9.39.2",
103
104
  "eslint-config-prettier": "^10.1.8",
104
105
  "eslint-plugin-import": "^2.32.0",
105
- "eslint-plugin-jsdoc": "^61.5.0",
106
+ "eslint-plugin-jsdoc": "^62.4.1",
106
107
  "husky": "^9.1.7",
107
108
  "jsdoc": "^4.0.5",
108
109
  "jsdoc-babel": "^0.5.0",
109
110
  "jsdoc-mermaid": "^1.0.0",
110
111
  "jsdoc-plugin-typescript": "^3.2.0",
111
112
  "jsdoc-to-markdown": "^9.1.3",
112
- "prettier": "^3.7.4",
113
+ "prettier": "^3.8.1",
113
114
  "prettier-plugin-organize-imports": "^4.3.0",
114
115
  "rimraf": "^6.1.2",
115
- "rollup": "^4.53.5",
116
+ "rollup": "^4.57.0",
116
117
  "semantic-release": "^25.0.2",
117
118
  "@semantic-release/changelog": "^6.0.3",
118
- "@semantic-release/github": "^11.0.0",
119
- "@semantic-release/npm": "^13.0.0",
119
+ "@semantic-release/github": "^12.0.2",
120
+ "@semantic-release/npm": "^13.1.3",
120
121
  "taffydb": "^2.7.3",
121
122
  "ts-node": "^10.9.2",
122
123
  "typescript": "5.9.3",
123
- "vitest": "^2.1.8",
124
+ "vitest": "^4.0.18",
124
125
  "yaml": "^2.8.2"
125
126
  },
126
127
  "optionalDependencies": {
@@ -1,6 +1,7 @@
1
1
  export enum AzureRemoteBackend {
2
- local = 'local',
3
2
  azurerm = 'azurerm',
3
+ pulumi = 'pulumi',
4
+ local = 'local',
4
5
  }
5
6
 
6
7
  /**
@@ -1,8 +1,4 @@
1
- import { DataAzurermClientConfig } from '@cdktf/provider-azurerm/lib/data-azurerm-client-config/index.js'
2
- import { AzurermProvider } from '@cdktf/provider-azurerm/lib/provider/index.js'
3
- import { AzurermBackend, TerraformStack } from 'cdktf'
4
- import { Provider } from 'cdktf-local-exec'
5
- import { Construct } from 'constructs'
1
+ import { ComponentResource, ComponentResourceOptions } from '@pulumi/pulumi'
6
2
  import { isDevStage, isPrdStage, isTestStage, isUatStage } from '../../common/index.js'
7
3
  import {
8
4
  AzureApiManagementManager,
@@ -14,19 +10,38 @@ import {
14
10
  AzureEventgridManager,
15
11
  AzureFunctionManager,
16
12
  AzureKeyVaultManager,
17
- AzureLogAnalyticsWorkspaceManager,
13
+ AzureOperationalInsightsManager,
18
14
  AzureMonitorManager,
19
15
  AzureRedisManager,
20
16
  AzureResourceGroupManager,
21
17
  AzureServicebusManager,
22
18
  AzureStorageManager,
23
19
  } from '../services/index.js'
24
- import { AzureRemoteBackend } from './constants.js'
25
20
  import { AzureResourceNameFormatter } from './resource-name-formatter.js'
26
21
  import { CommonAzureStackProps } from './types.js'
27
22
 
28
- export class CommonAzureConstruct extends TerraformStack {
23
+ /**
24
+ * @classdesc Common Azure construct to use as a base for all higher level constructs using Pulumi
25
+ * - Provides manager instances for all Azure services
26
+ * - Handles resource naming conventions
27
+ * - Manages common properties and utilities
28
+ * @example
29
+ * ```typescript
30
+ * import { CommonAzureConstruct } from '@gradientedge/cdk-utils'
31
+ *
32
+ * class CustomConstruct extends CommonAzureConstruct {
33
+ * constructor(name: string, props: CommonAzureStackProps) {
34
+ * super(name, props)
35
+ * // provision resources using this.resourceGroupManager, etc.
36
+ * }
37
+ * }
38
+ * ```
39
+ */
40
+ export class CommonAzureConstruct extends ComponentResource {
29
41
  declare props: CommonAzureStackProps
42
+ declare options?: ComponentResourceOptions
43
+ id: string
44
+ fullyQualifiedDomainName: string
30
45
  apiManagementManager: AzureApiManagementManager
31
46
  appConfigurationManager: AzureAppConfigurationManager
32
47
  appServiceManager: AzureAppServiceManager
@@ -34,23 +49,21 @@ export class CommonAzureConstruct extends TerraformStack {
34
49
  cosmosDbManager: AzureCosmosDbManager
35
50
  dnsManager: AzureDnsManager
36
51
  eventgridManager: AzureEventgridManager
37
- fullyQualifiedDomainName: string
38
- functiontManager: AzureFunctionManager
39
- id: string
52
+ functionManager: AzureFunctionManager
40
53
  keyVaultManager: AzureKeyVaultManager
41
- logAnalyticsWorkspaceManager: AzureLogAnalyticsWorkspaceManager
54
+ operationalInsightsManager: AzureOperationalInsightsManager
42
55
  monitorManager: AzureMonitorManager
43
56
  redisManager: AzureRedisManager
44
57
  resourceGroupManager: AzureResourceGroupManager
45
58
  resourceNameFormatter: AzureResourceNameFormatter
46
59
  servicebusManager: AzureServicebusManager
47
60
  storageManager: AzureStorageManager
48
- tenantId: string
49
61
 
50
- constructor(scope: Construct, id: string, props: CommonAzureStackProps) {
51
- super(scope, id)
62
+ constructor(name: string, props: CommonAzureStackProps, options?: ComponentResourceOptions) {
63
+ super(`custom:azure:Construct:${name}`, name, props, options)
52
64
  this.props = props
53
- this.id = id
65
+ this.options = options
66
+ this.id = name
54
67
 
55
68
  this.apiManagementManager = new AzureApiManagementManager()
56
69
  this.appConfigurationManager = new AzureAppConfigurationManager()
@@ -59,22 +72,17 @@ export class CommonAzureConstruct extends TerraformStack {
59
72
  this.cosmosDbManager = new AzureCosmosDbManager()
60
73
  this.dnsManager = new AzureDnsManager()
61
74
  this.eventgridManager = new AzureEventgridManager()
62
- this.functiontManager = new AzureFunctionManager()
75
+ this.functionManager = new AzureFunctionManager()
63
76
  this.keyVaultManager = new AzureKeyVaultManager()
64
- this.logAnalyticsWorkspaceManager = new AzureLogAnalyticsWorkspaceManager()
77
+ this.operationalInsightsManager = new AzureOperationalInsightsManager()
65
78
  this.monitorManager = new AzureMonitorManager()
66
79
  this.redisManager = new AzureRedisManager()
67
80
  this.resourceGroupManager = new AzureResourceGroupManager()
68
- this.resourceNameFormatter = new AzureResourceNameFormatter(this, `${id}-rnf`, props)
81
+ this.resourceNameFormatter = new AzureResourceNameFormatter(props)
69
82
  this.servicebusManager = new AzureServicebusManager()
70
83
  this.storageManager = new AzureStorageManager()
71
84
 
72
85
  this.determineFullyQualifiedDomain()
73
- this.determineRemoteBackend()
74
- this.determineTenantId()
75
-
76
- new AzurermProvider(this, `${this.id}-provider`, this.props)
77
- new Provider(this, `${this.id}-local-exec-provider`)
78
86
  }
79
87
 
80
88
  /**
@@ -86,30 +94,6 @@ export class CommonAzureConstruct extends TerraformStack {
86
94
  : this.props.domainName
87
95
  }
88
96
 
89
- protected determineRemoteBackend() {
90
- const debug = this.node.tryGetContext('debug')
91
- switch (this.props.remoteBackend?.type) {
92
- case AzureRemoteBackend.azurerm:
93
- new AzurermBackend(this, {
94
- storageAccountName: this.props.remoteBackend.storageAccountName,
95
- containerName: this.props.remoteBackend.containerName,
96
- key: `${this.id}`,
97
- subscriptionId: this.props.subscriptionId,
98
- resourceGroupName: this.props.remoteBackend.resourceGroupName,
99
- })
100
- break
101
- case AzureRemoteBackend.local:
102
- if (debug) console.debug(`Using local backend for ${this.id}`)
103
- break
104
- default:
105
- break
106
- }
107
- }
108
-
109
- protected determineTenantId() {
110
- this.tenantId = new DataAzurermClientConfig(this, 'current', {}).tenantId
111
- }
112
-
113
97
  /**
114
98
  * @summary Utility method to determine if the initialisation is in development (dev) stage
115
99
  * This is determined by the stage property injected via cdk context
@@ -1,11 +1,15 @@
1
- import { Construct } from 'constructs'
2
1
  import { AzureResourceNameFormatterProps, CommonAzureStackProps } from '../index.js'
3
2
 
4
- export class AzureResourceNameFormatter extends Construct {
3
+ /**
4
+ * @classdesc Formats Azure resource names according to naming conventions
5
+ * - Applies global/resource prefixes and suffixes
6
+ * - Automatically appends stage to resource names
7
+ * - Supports per-resource customization via options
8
+ */
9
+ export class AzureResourceNameFormatter {
5
10
  props: CommonAzureStackProps
6
11
 
7
- constructor(parent: Construct, id: string, props: CommonAzureStackProps) {
8
- super(parent, id)
12
+ constructor(props: CommonAzureStackProps) {
9
13
  this.props = props
10
14
  }
11
15
 
@@ -15,7 +19,7 @@ export class AzureResourceNameFormatter extends Construct {
15
19
  * @param options Options to control the formatting of the resource name
16
20
  * @returns The formatted Azure-compliant resource name
17
21
  */
18
- public format(resourceName: string, options?: AzureResourceNameFormatterProps) {
22
+ public format(resourceName: string | undefined, options?: AzureResourceNameFormatterProps): string {
19
23
  const azureResourceNameElements = []
20
24
 
21
25
  if (!options?.exclude) {
@@ -23,7 +27,7 @@ export class AzureResourceNameFormatter extends Construct {
23
27
  azureResourceNameElements.push(options?.prefix ?? this.props.resourcePrefix)
24
28
  }
25
29
 
26
- azureResourceNameElements.push(resourceName)
30
+ azureResourceNameElements.push(resourceName || '')
27
31
 
28
32
  if (!options?.exclude) {
29
33
  azureResourceNameElements.push(options?.suffix ?? this.props.resourceSuffix)
@@ -1,150 +1,150 @@
1
+ import { ComponentResource, ComponentResourceOptions, Config } from '@pulumi/pulumi'
1
2
  import appRoot from 'app-root-path'
2
- import { Aspects, TerraformStack } from 'cdktf'
3
- import { Construct } from 'constructs'
4
3
  import fs from 'fs'
5
4
  import _ from 'lodash'
6
5
  import path from 'path'
7
6
  import { isDevStage } from '../../common/index.js'
8
7
  import { CommonAzureConstruct } from './construct.js'
9
- import { TagsAddingAspect } from './tagging.js'
8
+ import { registerTagTransformation } from './tagging.js'
10
9
  import { CommonAzureStackProps } from './types.js'
11
10
 
12
11
  /**
13
- * @classdesc Common stack to use as a base for all higher level constructs.
12
+ * @classdesc Common stack to use as a base for all higher level constructs using Pulumi
14
13
  * @example
14
+ * ```typescript
15
15
  * import { CommonAzureStack } from '@gradientedge/cdk-utils'
16
16
  *
17
17
  * class CustomStack extends CommonAzureStack {
18
- * constructor(parent: App, name: string, props: StackProps) {
19
- * super(parent, name, props)
18
+ * constructor(name: string, props: CommonAzureStackProps) {
19
+ * super(name, props)
20
20
  * // provision resources
21
21
  * }
22
22
  * }
23
+ * ```
23
24
  */
24
- export class CommonAzureStack extends TerraformStack {
25
+ export class CommonAzureStack extends ComponentResource {
25
26
  construct: CommonAzureConstruct
26
27
  props: CommonAzureStackProps
28
+ config: Config
27
29
 
28
- constructor(parent: Construct, name: string, props: CommonAzureStackProps) {
29
- super(parent, name)
30
-
31
- /* determine extra cdk contexts */
32
- this.determineExtraContexts()
33
-
34
- /* determine extra cdk stage contexts */
35
- this.determineStageContexts()
30
+ constructor(name: string, props: CommonAzureStackProps, options?: ComponentResourceOptions) {
31
+ super(`custom:azure:Stack:${name}`, name, props, options)
36
32
 
33
+ /* initialise config */
34
+ this.config = new Config()
37
35
  this.props = this.determineConstructProps(props)
38
36
 
39
- Aspects.of(this).add(new TagsAddingAspect(this.props.defaultTags || {}))
37
+ /* register tag transformation for automatic tag application */
38
+ if (this.props.defaultTags) {
39
+ registerTagTransformation(this.props.defaultTags)
40
+ }
40
41
  }
41
42
 
42
43
  /**
43
- * @summary Method to determine the core CDK construct properties injected via context cdktf.json
44
+ * @summary Method to determine the core construct properties injected via context
44
45
  * @param props The stack properties
45
46
  * @returns The stack properties
46
47
  */
47
48
  protected determineConstructProps(props: CommonAzureStackProps) {
49
+ let projectProps: CommonAzureStackProps = props
50
+ if (!projectProps) {
51
+ const projectPropsPath = path.join(appRoot.path, 'pulumi.json')
52
+ if (!fs.existsSync(projectPropsPath)) throw `Context properties unavailable in path:${projectPropsPath}`
53
+
54
+ const projectPropsBuffer = fs.readFileSync(projectPropsPath)
55
+ projectProps = JSON.parse(projectPropsBuffer.toString('utf-8'))
56
+ }
57
+
48
58
  return {
49
- domainName: this.node.tryGetContext('domainName'),
50
- extraContexts: this.node.tryGetContext('extraContexts'),
51
- features: this.node.tryGetContext('features'),
52
- location: this.node.tryGetContext('location'),
53
- name: this.node.tryGetContext('resourceGroupName'),
54
- resourceGroupName: this.node.tryGetContext('resourceGroupName'),
55
- globalPrefix: this.node.tryGetContext('globalPrefix'),
56
- globalSuffix: this.node.tryGetContext('globalSuffix'),
57
- resourceNameOptions: this.node.tryGetContext('resourceNameOptions'),
58
- resourcePrefix: this.node.tryGetContext('resourcePrefix'),
59
- resourceSuffix: this.node.tryGetContext('resourceSuffix'),
60
- skipStageForARecords: this.node.tryGetContext('skipStageForARecords'),
61
- stage: this.node.tryGetContext('stage'),
62
- subDomain: this.node.tryGetContext('subDomain'),
63
- subscriptionId: this.node.tryGetContext('subscriptionId'),
59
+ domainName: projectProps.domainName,
60
+ extraContexts: projectProps.extraContexts,
61
+ location: projectProps.location,
62
+ name: projectProps.resourceGroupName ?? projectProps.name,
63
+ resourceGroupName: projectProps.resourceGroupName,
64
+ globalPrefix: projectProps.globalPrefix,
65
+ globalSuffix: projectProps.globalSuffix,
66
+ resourceNameOptions: projectProps.resourceNameOptions,
67
+ resourcePrefix: projectProps.resourcePrefix,
68
+ resourceSuffix: projectProps.resourceSuffix,
69
+ skipStageForARecords: projectProps.skipStageForARecords,
70
+ stage: projectProps.stage,
71
+ stageContextPath: projectProps.stageContextPath,
72
+ subDomain: projectProps.subDomain,
73
+ subscriptionId: projectProps.subscriptionId,
74
+ tenantId: projectProps.tenantId,
75
+ clientId: projectProps.clientId,
76
+ clientSecret: projectProps.clientSecret,
77
+ defaultTags: projectProps.defaultTags,
78
+ ...this.determineExtraContexts(props),
79
+ ...this.determineStageContexts(props),
64
80
  }
65
81
  }
66
82
 
67
83
  /**
68
- * @summary Method to determine extra cdk contexts apart from the main cdktf.json
69
- * - Sets the properties from the extra contexts into cdk node context
84
+ * @summary Method to determine extra contexts apart from the main context
85
+ * - Sets the properties from the extra contexts
70
86
  * - Primary use is to have layered config in separate files to enable easier maintenance and readability
71
87
  */
72
- protected determineExtraContexts() {
73
- const extraContexts = this.node.tryGetContext('extraContexts')
74
- const debug = this.node.tryGetContext('debug')
75
-
76
- if (!extraContexts) {
77
- if (debug) console.debug(`No additional contexts provided. Using default context properties from cdktf.json`)
78
- return
88
+ protected determineExtraContexts(props: CommonAzureStackProps) {
89
+ if (!props.extraContexts) {
90
+ if (props.debug) console.debug(`No additional contexts provided. Using default context properties`)
91
+ return {}
79
92
  }
80
93
 
81
- _.forEach(extraContexts, (context: string) => {
94
+ let extraContextProps: Record<string, any> = {}
95
+ _.forEach(props.extraContexts, (context: string) => {
82
96
  const extraContextPath = path.join(appRoot.path, context)
83
97
 
84
- /* scenario where extra context is configured in cdk.json but absent in file system */
98
+ /* scenario where extra context is configured but absent in file system */
85
99
  if (!fs.existsSync(extraContextPath)) throw `Extra context properties unavailable in path:${extraContextPath}`
86
100
 
87
101
  /* read the extra properties */
88
102
  const extraContextPropsBuffer = fs.readFileSync(extraContextPath)
89
- if (debug) console.debug(`Adding additional contexts provided in ${extraContextPath}`)
103
+ if (props.debug) console.debug(`Adding additional contexts provided in ${extraContextPath}`)
90
104
 
91
105
  /* parse as JSON properties */
92
- const extraContextProps = JSON.parse(extraContextPropsBuffer.toString('utf-8'))
93
-
94
- /* set each of the property into the cdk node context */
95
- _.keys(extraContextProps).forEach((propKey: any) => {
96
- this.node.setContext(propKey, extraContextProps[propKey])
97
- })
106
+ extraContextProps = {
107
+ ...extraContextProps,
108
+ ...JSON.parse(extraContextPropsBuffer.toString('utf-8')),
109
+ }
98
110
  })
111
+ return extraContextProps
99
112
  }
100
113
 
101
114
  /**
102
- * @summary Method to determine extra cdk stage contexts apart from the main cdktf.json
103
- * - Sets the properties from the extra stage contexts into cdk node context
115
+ * @summary Method to determine extra stage contexts apart from the main context
116
+ * - Sets the properties from the extra stage contexts
104
117
  * - Primary use is to have layered config for each environment which is injected into the context
105
118
  */
106
- protected determineStageContexts() {
107
- const stage = process.env.STAGE ?? this.node.tryGetContext('stage')
108
- const stageContextPath = this.node.tryGetContext('stageContextPath') || 'cdkEnv'
109
- const stageContextFilePath = path.join(appRoot.path, stageContextPath, `${stage}.json`)
110
- const debug = this.node.tryGetContext('debug')
111
-
112
- if (isDevStage(stage)) {
113
- if (debug) console.debug(`Development stage. Using default stage context properties`)
119
+ protected determineStageContexts(props: CommonAzureStackProps) {
120
+ const stageContextFilePath = path.join(appRoot.path, props.stageContextPath ?? 'env', `${props.stage}.json`)
121
+
122
+ if (isDevStage(props.stage)) {
123
+ if (props.debug) console.debug(`Development stage. Using default stage context properties`)
114
124
  }
115
125
 
116
126
  /* alert default context usage when extra stage config is missing */
117
127
  if (!fs.existsSync(stageContextFilePath)) {
118
- if (debug) console.debug(`Stage specific context properties unavailable in path:${stageContextFilePath}`)
119
- if (debug) console.debug(`Using default stage context properties for ${stage} stage`)
120
- return
128
+ if (props.debug) console.debug(`Stage specific context properties unavailable in path:${stageContextFilePath}`)
129
+ if (props.debug) console.debug(`Using default stage context properties for ${props.stage} stage`)
130
+ return {}
121
131
  }
122
132
 
123
133
  /* read the extra properties */
124
134
  const stageContextPropsBuffer = fs.readFileSync(stageContextFilePath)
125
- if (debug) console.debug(`Adding additional stage contexts provided in ${stageContextFilePath}`)
135
+ if (props.debug) console.debug(`Adding additional stage contexts provided in ${stageContextFilePath}`)
126
136
 
127
137
  /* parse as JSON properties */
128
- const stageContextProps = JSON.parse(stageContextPropsBuffer.toString('utf-8'))
129
-
130
- /* set each of the property into the cdk node context */
131
- _.keys(stageContextProps).forEach((propKey: any) => {
132
- /* handle object, array properties */
133
- if (typeof stageContextProps[propKey] === 'object' && !Array.isArray(stageContextProps[propKey])) {
134
- this.node.setContext(propKey, _.merge(this.node.tryGetContext(propKey), stageContextProps[propKey]))
135
- } else {
136
- /* handle all other primitive properties */
137
- this.node.setContext(propKey, stageContextProps[propKey])
138
- }
139
- })
138
+ return JSON.parse(stageContextPropsBuffer.toString('utf-8'))
140
139
  }
141
140
 
142
141
  /**
143
142
  * @summary Determine the fully qualified domain name based on domainName & subDomain
144
143
  */
145
144
  protected fullyQualifiedDomain() {
146
- const domainName = this.node.tryGetContext('domainName')
147
- const subDomain = this.node.tryGetContext('subDomain')
145
+ const domainName = this.props.domainName
146
+ const subDomain = this.props.subDomain
147
+
148
148
  return subDomain ? `${subDomain}.${domainName}` : domainName
149
149
  }
150
150
  }