@gradientedge/cdk-utils 10.1.0 → 10.3.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 (133) 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/dist/src/lib/cloudflare/services/access/main.js +23 -23
  64. package/dist/src/lib/cloudflare/services/api-shield/main.js +11 -11
  65. package/dist/src/lib/cloudflare/services/argo/main.js +5 -5
  66. package/dist/src/lib/cloudflare/services/filter/main.js +3 -3
  67. package/dist/src/lib/cloudflare/services/firewall/main.js +3 -3
  68. package/dist/src/lib/cloudflare/services/page/main.js +7 -7
  69. package/dist/src/lib/cloudflare/services/record/main.js +3 -3
  70. package/dist/src/lib/cloudflare/services/rule-set/main.d.ts +1 -1
  71. package/dist/src/lib/cloudflare/services/rule-set/main.js +4 -5
  72. package/dist/src/lib/cloudflare/services/worker/main.js +13 -13
  73. package/dist/src/lib/cloudflare/services/zone/main.js +18 -18
  74. package/package.json +2 -1
  75. package/src/lib/azure/common/constants.ts +2 -1
  76. package/src/lib/azure/common/construct.ts +32 -48
  77. package/src/lib/azure/common/resource-name-formatter.ts +10 -6
  78. package/src/lib/azure/common/stack.ts +78 -78
  79. package/src/lib/azure/common/tagging.ts +78 -29
  80. package/src/lib/azure/common/types.ts +21 -4
  81. package/src/lib/azure/services/api-management/main.ts +172 -169
  82. package/src/lib/azure/services/api-management/types.ts +39 -16
  83. package/src/lib/azure/services/app-configuration/main.ts +33 -31
  84. package/src/lib/azure/services/app-configuration/types.ts +2 -2
  85. package/src/lib/azure/services/app-service/main.ts +61 -62
  86. package/src/lib/azure/services/app-service/types.ts +4 -4
  87. package/src/lib/azure/services/application-insights/main.ts +29 -30
  88. package/src/lib/azure/services/application-insights/types.ts +2 -5
  89. package/src/lib/azure/services/cosmosdb/main.ts +78 -77
  90. package/src/lib/azure/services/cosmosdb/types.ts +10 -6
  91. package/src/lib/azure/services/dns/main.ts +65 -72
  92. package/src/lib/azure/services/dns/types.ts +9 -9
  93. package/src/lib/azure/services/eventgrid/main.ts +120 -122
  94. package/src/lib/azure/services/eventgrid/types.ts +13 -8
  95. package/src/lib/azure/services/function/main.ts +75 -72
  96. package/src/lib/azure/services/function/types.ts +21 -6
  97. package/src/lib/azure/services/index.ts +1 -1
  98. package/src/lib/azure/services/key-vault/main.ts +38 -32
  99. package/src/lib/azure/services/key-vault/types.ts +4 -2
  100. package/src/lib/azure/services/monitor/main.ts +17 -21
  101. package/src/lib/azure/services/monitor/types.ts +2 -2
  102. package/src/lib/azure/services/operational-insights/main.ts +61 -0
  103. package/src/lib/azure/services/operational-insights/types.ts +3 -0
  104. package/src/lib/azure/services/redis/main.ts +30 -30
  105. package/src/lib/azure/services/redis/types.ts +2 -2
  106. package/src/lib/azure/services/resource-group/main.ts +20 -20
  107. package/src/lib/azure/services/resource-group/types.ts +2 -2
  108. package/src/lib/azure/services/servicebus/main.ts +103 -94
  109. package/src/lib/azure/services/servicebus/types.ts +17 -11
  110. package/src/lib/azure/services/storage/main.ts +113 -114
  111. package/src/lib/azure/services/storage/types.ts +16 -8
  112. package/src/lib/azure/types/index.ts +2 -1
  113. package/src/lib/azure/utils/index.ts +20 -22
  114. package/src/lib/cloudflare/common/stack.ts +1 -1
  115. package/src/lib/cloudflare/services/access/main.ts +114 -58
  116. package/src/lib/cloudflare/services/api-shield/main.ts +48 -22
  117. package/src/lib/cloudflare/services/argo/main.ts +17 -9
  118. package/src/lib/cloudflare/services/filter/main.ts +9 -5
  119. package/src/lib/cloudflare/services/firewall/main.ts +9 -5
  120. package/src/lib/cloudflare/services/page/main.ts +27 -15
  121. package/src/lib/cloudflare/services/record/main.ts +9 -5
  122. package/src/lib/cloudflare/services/rule-set/main.ts +10 -8
  123. package/src/lib/cloudflare/services/worker/main.ts +60 -29
  124. package/src/lib/cloudflare/services/zone/main.ts +75 -35
  125. package/dist/src/lib/azure/services/log-analytics-workspace/main.d.ts +0 -30
  126. package/dist/src/lib/azure/services/log-analytics-workspace/main.js +0 -55
  127. package/dist/src/lib/azure/services/log-analytics-workspace/types.d.ts +0 -3
  128. package/src/lib/azure/services/log-analytics-workspace/main.ts +0 -61
  129. package/src/lib/azure/services/log-analytics-workspace/types.ts +0 -3
  130. /package/dist/src/lib/azure/services/{log-analytics-workspace → operational-insights}/index.d.ts +0 -0
  131. /package/dist/src/lib/azure/services/{log-analytics-workspace → operational-insights}/index.js +0 -0
  132. /package/dist/src/lib/azure/services/{log-analytics-workspace → operational-insights}/types.js +0 -0
  133. /package/src/lib/azure/services/{log-analytics-workspace → operational-insights}/index.ts +0 -0
@@ -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
  }
@@ -1,42 +1,91 @@
1
- import { IAspect, TerraformResource } from 'cdktf'
2
- import { IConstruct } from 'constructs'
1
+ import * as pulumi from '@pulumi/pulumi'
3
2
  import { RESOURCES_TO_EXCLUDE_TAGS } from './constants.js'
4
3
 
5
- type TaggableConstruct = IConstruct & {
6
- tags?: { [key: string]: string } | string[]
7
- tagsInput?: { [key: string]: string } | string[]
8
- }
4
+ /**
5
+ * @summary Check if a resource type is taggable
6
+ * @param resourceType The Pulumi resource type (e.g., 'azure-native:resources:ResourceGroup')
7
+ * @returns True if the resource supports tags, false otherwise
8
+ */
9
+ export function isTaggableResource(resourceType: string): boolean {
10
+ // Extract the resource name from the type (e.g., 'ResourceGroup' from 'azure-native:resources:ResourceGroup')
11
+ const resourceName = resourceType.split(':').pop() || ''
12
+
13
+ // Check if this resource is in the exclusion list
14
+ if (RESOURCES_TO_EXCLUDE_TAGS.has(resourceName)) {
15
+ return false
16
+ }
9
17
 
10
- function isTaggableConstruct(node: IConstruct): node is TaggableConstruct {
11
- return 'tags' in node && 'tagsInput' in node
18
+ // Most Azure resources support tags, but we can add more specific checks here if needed
19
+ return true
12
20
  }
13
21
 
14
- export class TagsAddingAspect implements IAspect {
15
- constructor(
16
- private tagsToAdd: Record<string, string>,
17
- private tagsToIgnore: string[] = []
18
- ) {}
19
-
20
- // This method is called on every Construct within the specified scope (resources, data sources, etc.).
21
- visit(node: IConstruct) {
22
- // We need to take the input value to not create a circular reference
23
- if (!isTaggableConstruct(node)) {
24
- return
22
+ /**
23
+ * @summary Register a stack transformation to automatically apply tags to Azure resources
24
+ * @param defaultTags The default tags to apply to all resources
25
+ * @param tagsToIgnore Optional list of tag keys to ignore in lifecycle management
26
+ * @example
27
+ * ```typescript
28
+ * registerTagTransformation({ environment: 'production', team: 'platform' })
29
+ * ```
30
+ */
31
+ export function registerTagTransformation(defaultTags: Record<string, string>, tagsToIgnore: string[] = []): void {
32
+ pulumi.runtime.registerStackTransformation((args: pulumi.ResourceTransformationArgs) => {
33
+ // Only process taggable resources
34
+ if (!isTaggableResource(args.type)) {
35
+ return undefined
25
36
  }
26
37
 
27
- // Determine if the resource excludes `tags`
28
- if (RESOURCES_TO_EXCLUDE_TAGS.has(node.constructor.name)) {
29
- node.tags = undefined // Completely remove tags for this resource
30
- return
38
+ // Check if the resource has a tags property
39
+ if (!args.props || typeof args.props !== 'object') {
40
+ return undefined
31
41
  }
32
42
 
33
- const currentTags = node.tagsInput || {}
34
- node.tags = { ...this.tagsToAdd, ...currentTags }
43
+ // Merge default tags with resource-specific tags (resource tags take precedence)
44
+ const currentTags = (args.props as any).tags || {}
45
+ const mergedTags = { ...defaultTags, ...currentTags }
46
+
47
+ // Apply the merged tags
48
+ const newProps = {
49
+ ...args.props,
50
+ tags: mergedTags,
51
+ }
35
52
 
36
- // Add ignore_changes overrides for selected tags
37
- if (node instanceof TerraformResource && this.tagsToIgnore.length > 0) {
38
- const ignoreList = this.tagsToIgnore.map(tag => `tags["${tag}"]`)
39
- node.addOverride('lifecycle.ignore_changes', ignoreList)
53
+ // Handle tag ignores via Pulumi's ignoreChanges option
54
+ let newOpts = args.opts
55
+ if (tagsToIgnore.length > 0) {
56
+ const ignoreChanges = tagsToIgnore.map(tag => `tags.${tag}`)
57
+ newOpts = {
58
+ ...args.opts,
59
+ ignoreChanges: [...(args.opts?.ignoreChanges || []), ...ignoreChanges],
60
+ }
40
61
  }
62
+
63
+ return {
64
+ props: newProps,
65
+ opts: newOpts,
66
+ }
67
+ })
68
+ }
69
+
70
+ /**
71
+ * @summary Helper function to apply tags to a specific resource's properties
72
+ * @param props The resource properties
73
+ * @param defaultTags The default tags to merge with existing tags
74
+ * @returns The properties with merged tags
75
+ * @example
76
+ * ```typescript
77
+ * const resourceGroupProps = applyTags(props, { environment: 'dev' })
78
+ * ```
79
+ */
80
+ export function applyTags<T extends { tags?: Record<string, string> }>(
81
+ props: T,
82
+ defaultTags: Record<string, string>
83
+ ): T {
84
+ return {
85
+ ...props,
86
+ tags: {
87
+ ...defaultTags,
88
+ ...(props.tags || {}),
89
+ },
41
90
  }
42
91
  }
@@ -1,11 +1,11 @@
1
- import { AzurermProviderConfig } from '@cdktf/provider-azurerm/lib/provider/index.js'
2
- import { AzurermBackendConfig } from 'cdktf'
3
1
  import { BaseProps } from '../../common/index.js'
4
2
  import { AzureRemoteBackend } from './constants.js'
5
3
 
6
4
  /**
5
+ * @interface CommonAzureStackProps
6
+ * @description Common properties for Azure stack configuration using Pulumi
7
7
  */
8
- export interface CommonAzureStackProps extends BaseProps, AzurermProviderConfig {
8
+ export interface CommonAzureStackProps extends BaseProps {
9
9
  resourceGroupName?: string
10
10
  remoteBackend?: AzureRemoteBackendProps
11
11
  globalPrefix?: string
@@ -15,10 +15,27 @@ export interface CommonAzureStackProps extends BaseProps, AzurermProviderConfig
15
15
  resourceNameOptions?: { [key: string]: AzureResourceNameFormatterProps }
16
16
  location?: string
17
17
  defaultTags?: { [key: string]: string }
18
+
19
+ // Azure Provider properties for Pulumi
20
+ subscriptionId?: string
21
+ tenantId?: string
22
+ clientId?: string
23
+ clientSecret?: string
24
+ environment?: string
25
+ useOidc?: boolean
26
+ oidcRequestToken?: string
27
+ oidcRequestUrl?: string
28
+ useMsi?: boolean
29
+ msiEndpoint?: string
18
30
  }
19
31
 
20
- export interface AzureRemoteBackendProps extends AzurermBackendConfig {
32
+ export interface AzureRemoteBackendProps {
21
33
  type: AzureRemoteBackend
34
+ storageAccountName?: string
35
+ containerName?: string
36
+ resourceGroupName?: string
37
+ subscriptionId?: string
38
+ key?: string
22
39
  }
23
40
 
24
41
  export interface AzureResourceNameFormatterProps {