@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
@@ -1,6 +1,7 @@
1
1
  export declare enum AzureRemoteBackend {
2
- local = "local",
3
- azurerm = "azurerm"
2
+ azurerm = "azurerm",
3
+ pulumi = "pulumi",
4
+ local = "local"
4
5
  }
5
6
  /**
6
7
  * List of Azure resources that excludes tags
@@ -1,7 +1,8 @@
1
1
  export var AzureRemoteBackend;
2
2
  (function (AzureRemoteBackend) {
3
- AzureRemoteBackend["local"] = "local";
4
3
  AzureRemoteBackend["azurerm"] = "azurerm";
4
+ AzureRemoteBackend["pulumi"] = "pulumi";
5
+ AzureRemoteBackend["local"] = "local";
5
6
  })(AzureRemoteBackend || (AzureRemoteBackend = {}));
6
7
  /**
7
8
  * List of Azure resources that excludes tags
@@ -1,10 +1,29 @@
1
- import { TerraformStack } from 'cdktf';
2
- import { Construct } from 'constructs';
3
- import { AzureApiManagementManager, AzureAppConfigurationManager, AzureAppServiceManager, AzureApplicationInsightsManager, AzureCosmosDbManager, AzureDnsManager, AzureEventgridManager, AzureFunctionManager, AzureKeyVaultManager, AzureLogAnalyticsWorkspaceManager, AzureMonitorManager, AzureRedisManager, AzureResourceGroupManager, AzureServicebusManager, AzureStorageManager } from '../services/index.js';
1
+ import { ComponentResource, ComponentResourceOptions } from '@pulumi/pulumi';
2
+ import { AzureApiManagementManager, AzureAppConfigurationManager, AzureAppServiceManager, AzureApplicationInsightsManager, AzureCosmosDbManager, AzureDnsManager, AzureEventgridManager, AzureFunctionManager, AzureKeyVaultManager, AzureOperationalInsightsManager, AzureMonitorManager, AzureRedisManager, AzureResourceGroupManager, AzureServicebusManager, AzureStorageManager } from '../services/index.js';
4
3
  import { AzureResourceNameFormatter } from './resource-name-formatter.js';
5
4
  import { CommonAzureStackProps } from './types.js';
6
- export declare class CommonAzureConstruct extends TerraformStack {
5
+ /**
6
+ * @classdesc Common Azure construct to use as a base for all higher level constructs using Pulumi
7
+ * - Provides manager instances for all Azure services
8
+ * - Handles resource naming conventions
9
+ * - Manages common properties and utilities
10
+ * @example
11
+ * ```typescript
12
+ * import { CommonAzureConstruct } from '@gradientedge/cdk-utils'
13
+ *
14
+ * class CustomConstruct extends CommonAzureConstruct {
15
+ * constructor(name: string, props: CommonAzureStackProps) {
16
+ * super(name, props)
17
+ * // provision resources using this.resourceGroupManager, etc.
18
+ * }
19
+ * }
20
+ * ```
21
+ */
22
+ export declare class CommonAzureConstruct extends ComponentResource {
7
23
  props: CommonAzureStackProps;
24
+ options?: ComponentResourceOptions;
25
+ id: string;
26
+ fullyQualifiedDomainName: string;
8
27
  apiManagementManager: AzureApiManagementManager;
9
28
  appConfigurationManager: AzureAppConfigurationManager;
10
29
  appServiceManager: AzureAppServiceManager;
@@ -12,25 +31,20 @@ export declare class CommonAzureConstruct extends TerraformStack {
12
31
  cosmosDbManager: AzureCosmosDbManager;
13
32
  dnsManager: AzureDnsManager;
14
33
  eventgridManager: AzureEventgridManager;
15
- fullyQualifiedDomainName: string;
16
- functiontManager: AzureFunctionManager;
17
- id: string;
34
+ functionManager: AzureFunctionManager;
18
35
  keyVaultManager: AzureKeyVaultManager;
19
- logAnalyticsWorkspaceManager: AzureLogAnalyticsWorkspaceManager;
36
+ operationalInsightsManager: AzureOperationalInsightsManager;
20
37
  monitorManager: AzureMonitorManager;
21
38
  redisManager: AzureRedisManager;
22
39
  resourceGroupManager: AzureResourceGroupManager;
23
40
  resourceNameFormatter: AzureResourceNameFormatter;
24
41
  servicebusManager: AzureServicebusManager;
25
42
  storageManager: AzureStorageManager;
26
- tenantId: string;
27
- constructor(scope: Construct, id: string, props: CommonAzureStackProps);
43
+ constructor(name: string, props: CommonAzureStackProps, options?: ComponentResourceOptions);
28
44
  /**
29
45
  * @summary Determine the fully qualified domain name based on domainName & subDomain
30
46
  */
31
47
  protected determineFullyQualifiedDomain(): void;
32
- protected determineRemoteBackend(): void;
33
- protected determineTenantId(): void;
34
48
  /**
35
49
  * @summary Utility method to determine if the initialisation is in development (dev) stage
36
50
  * This is determined by the stage property injected via cdk context
@@ -1,12 +1,27 @@
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';
1
+ import { ComponentResource } from '@pulumi/pulumi';
5
2
  import { isDevStage, isPrdStage, isTestStage, isUatStage } from '../../common/index.js';
6
- import { AzureApiManagementManager, AzureAppConfigurationManager, AzureAppServiceManager, AzureApplicationInsightsManager, AzureCosmosDbManager, AzureDnsManager, AzureEventgridManager, AzureFunctionManager, AzureKeyVaultManager, AzureLogAnalyticsWorkspaceManager, AzureMonitorManager, AzureRedisManager, AzureResourceGroupManager, AzureServicebusManager, AzureStorageManager, } from '../services/index.js';
7
- import { AzureRemoteBackend } from './constants.js';
3
+ import { AzureApiManagementManager, AzureAppConfigurationManager, AzureAppServiceManager, AzureApplicationInsightsManager, AzureCosmosDbManager, AzureDnsManager, AzureEventgridManager, AzureFunctionManager, AzureKeyVaultManager, AzureOperationalInsightsManager, AzureMonitorManager, AzureRedisManager, AzureResourceGroupManager, AzureServicebusManager, AzureStorageManager, } from '../services/index.js';
8
4
  import { AzureResourceNameFormatter } from './resource-name-formatter.js';
9
- export class CommonAzureConstruct extends TerraformStack {
5
+ /**
6
+ * @classdesc Common Azure construct to use as a base for all higher level constructs using Pulumi
7
+ * - Provides manager instances for all Azure services
8
+ * - Handles resource naming conventions
9
+ * - Manages common properties and utilities
10
+ * @example
11
+ * ```typescript
12
+ * import { CommonAzureConstruct } from '@gradientedge/cdk-utils'
13
+ *
14
+ * class CustomConstruct extends CommonAzureConstruct {
15
+ * constructor(name: string, props: CommonAzureStackProps) {
16
+ * super(name, props)
17
+ * // provision resources using this.resourceGroupManager, etc.
18
+ * }
19
+ * }
20
+ * ```
21
+ */
22
+ export class CommonAzureConstruct extends ComponentResource {
23
+ id;
24
+ fullyQualifiedDomainName;
10
25
  apiManagementManager;
11
26
  appConfigurationManager;
12
27
  appServiceManager;
@@ -14,22 +29,20 @@ export class CommonAzureConstruct extends TerraformStack {
14
29
  cosmosDbManager;
15
30
  dnsManager;
16
31
  eventgridManager;
17
- fullyQualifiedDomainName;
18
- functiontManager;
19
- id;
32
+ functionManager;
20
33
  keyVaultManager;
21
- logAnalyticsWorkspaceManager;
34
+ operationalInsightsManager;
22
35
  monitorManager;
23
36
  redisManager;
24
37
  resourceGroupManager;
25
38
  resourceNameFormatter;
26
39
  servicebusManager;
27
40
  storageManager;
28
- tenantId;
29
- constructor(scope, id, props) {
30
- super(scope, id);
41
+ constructor(name, props, options) {
42
+ super(`custom:azure:Construct:${name}`, name, props, options);
31
43
  this.props = props;
32
- this.id = id;
44
+ this.options = options;
45
+ this.id = name;
33
46
  this.apiManagementManager = new AzureApiManagementManager();
34
47
  this.appConfigurationManager = new AzureAppConfigurationManager();
35
48
  this.appServiceManager = new AzureAppServiceManager();
@@ -37,20 +50,16 @@ export class CommonAzureConstruct extends TerraformStack {
37
50
  this.cosmosDbManager = new AzureCosmosDbManager();
38
51
  this.dnsManager = new AzureDnsManager();
39
52
  this.eventgridManager = new AzureEventgridManager();
40
- this.functiontManager = new AzureFunctionManager();
53
+ this.functionManager = new AzureFunctionManager();
41
54
  this.keyVaultManager = new AzureKeyVaultManager();
42
- this.logAnalyticsWorkspaceManager = new AzureLogAnalyticsWorkspaceManager();
55
+ this.operationalInsightsManager = new AzureOperationalInsightsManager();
43
56
  this.monitorManager = new AzureMonitorManager();
44
57
  this.redisManager = new AzureRedisManager();
45
58
  this.resourceGroupManager = new AzureResourceGroupManager();
46
- this.resourceNameFormatter = new AzureResourceNameFormatter(this, `${id}-rnf`, props);
59
+ this.resourceNameFormatter = new AzureResourceNameFormatter(props);
47
60
  this.servicebusManager = new AzureServicebusManager();
48
61
  this.storageManager = new AzureStorageManager();
49
62
  this.determineFullyQualifiedDomain();
50
- this.determineRemoteBackend();
51
- this.determineTenantId();
52
- new AzurermProvider(this, `${this.id}-provider`, this.props);
53
- new Provider(this, `${this.id}-local-exec-provider`);
54
63
  }
55
64
  /**
56
65
  * @summary Determine the fully qualified domain name based on domainName & subDomain
@@ -60,29 +69,6 @@ export class CommonAzureConstruct extends TerraformStack {
60
69
  ? `${this.props.subDomain}.${this.props.domainName}`
61
70
  : this.props.domainName;
62
71
  }
63
- determineRemoteBackend() {
64
- const debug = this.node.tryGetContext('debug');
65
- switch (this.props.remoteBackend?.type) {
66
- case AzureRemoteBackend.azurerm:
67
- new AzurermBackend(this, {
68
- storageAccountName: this.props.remoteBackend.storageAccountName,
69
- containerName: this.props.remoteBackend.containerName,
70
- key: `${this.id}`,
71
- subscriptionId: this.props.subscriptionId,
72
- resourceGroupName: this.props.remoteBackend.resourceGroupName,
73
- });
74
- break;
75
- case AzureRemoteBackend.local:
76
- if (debug)
77
- console.debug(`Using local backend for ${this.id}`);
78
- break;
79
- default:
80
- break;
81
- }
82
- }
83
- determineTenantId() {
84
- this.tenantId = new DataAzurermClientConfig(this, 'current', {}).tenantId;
85
- }
86
72
  /**
87
73
  * @summary Utility method to determine if the initialisation is in development (dev) stage
88
74
  * This is determined by the stage property injected via cdk context
@@ -1,13 +1,18 @@
1
- import { Construct } from 'constructs';
2
1
  import { AzureResourceNameFormatterProps, CommonAzureStackProps } from '../index.js';
3
- export declare class AzureResourceNameFormatter extends Construct {
2
+ /**
3
+ * @classdesc Formats Azure resource names according to naming conventions
4
+ * - Applies global/resource prefixes and suffixes
5
+ * - Automatically appends stage to resource names
6
+ * - Supports per-resource customization via options
7
+ */
8
+ export declare class AzureResourceNameFormatter {
4
9
  props: CommonAzureStackProps;
5
- constructor(parent: Construct, id: string, props: CommonAzureStackProps);
10
+ constructor(props: CommonAzureStackProps);
6
11
  /**
7
12
  * @summary Helper method to format azure resource name based on the provided options
8
13
  * @param resourceName The azure resource name to format
9
14
  * @param options Options to control the formatting of the resource name
10
15
  * @returns The formatted Azure-compliant resource name
11
16
  */
12
- format(resourceName: string, options?: AzureResourceNameFormatterProps): string;
17
+ format(resourceName: string | undefined, options?: AzureResourceNameFormatterProps): string;
13
18
  }
@@ -1,8 +1,12 @@
1
- import { Construct } from 'constructs';
2
- export class AzureResourceNameFormatter extends Construct {
1
+ /**
2
+ * @classdesc Formats Azure resource names according to naming conventions
3
+ * - Applies global/resource prefixes and suffixes
4
+ * - Automatically appends stage to resource names
5
+ * - Supports per-resource customization via options
6
+ */
7
+ export class AzureResourceNameFormatter {
3
8
  props;
4
- constructor(parent, id, props) {
5
- super(parent, id);
9
+ constructor(props) {
6
10
  this.props = props;
7
11
  }
8
12
  /**
@@ -17,7 +21,7 @@ export class AzureResourceNameFormatter extends Construct {
17
21
  azureResourceNameElements.push(options?.globalPrefix ? this.props.globalPrefix : undefined);
18
22
  azureResourceNameElements.push(options?.prefix ?? this.props.resourcePrefix);
19
23
  }
20
- azureResourceNameElements.push(resourceName);
24
+ azureResourceNameElements.push(resourceName || '');
21
25
  if (!options?.exclude) {
22
26
  azureResourceNameElements.push(options?.suffix ?? this.props.resourceSuffix);
23
27
  azureResourceNameElements.push(options?.globalSuffix ? this.props.globalSuffix : undefined);
@@ -1,59 +1,45 @@
1
- import { TerraformStack } from 'cdktf';
2
- import { Construct } from 'constructs';
1
+ import { ComponentResource, ComponentResourceOptions, Config } from '@pulumi/pulumi';
3
2
  import { CommonAzureConstruct } from './construct.js';
4
3
  import { CommonAzureStackProps } from './types.js';
5
4
  /**
6
- * @classdesc Common stack to use as a base for all higher level constructs.
5
+ * @classdesc Common stack to use as a base for all higher level constructs using Pulumi
7
6
  * @example
7
+ * ```typescript
8
8
  * import { CommonAzureStack } from '@gradientedge/cdk-utils'
9
9
  *
10
10
  * class CustomStack extends CommonAzureStack {
11
- * constructor(parent: App, name: string, props: StackProps) {
12
- * super(parent, name, props)
11
+ * constructor(name: string, props: CommonAzureStackProps) {
12
+ * super(name, props)
13
13
  * // provision resources
14
14
  * }
15
15
  * }
16
+ * ```
16
17
  */
17
- export declare class CommonAzureStack extends TerraformStack {
18
+ export declare class CommonAzureStack extends ComponentResource {
18
19
  construct: CommonAzureConstruct;
19
20
  props: CommonAzureStackProps;
20
- constructor(parent: Construct, name: string, props: CommonAzureStackProps);
21
+ config: Config;
22
+ constructor(name: string, props: CommonAzureStackProps, options?: ComponentResourceOptions);
21
23
  /**
22
- * @summary Method to determine the core CDK construct properties injected via context cdktf.json
24
+ * @summary Method to determine the core construct properties injected via context
23
25
  * @param props The stack properties
24
26
  * @returns The stack properties
25
27
  */
26
- protected determineConstructProps(props: CommonAzureStackProps): {
27
- domainName: any;
28
- extraContexts: any;
29
- features: any;
30
- location: any;
31
- name: any;
32
- resourceGroupName: any;
33
- globalPrefix: any;
34
- globalSuffix: any;
35
- resourceNameOptions: any;
36
- resourcePrefix: any;
37
- resourceSuffix: any;
38
- skipStageForARecords: any;
39
- stage: any;
40
- subDomain: any;
41
- subscriptionId: any;
42
- };
28
+ protected determineConstructProps(props: CommonAzureStackProps): any;
43
29
  /**
44
- * @summary Method to determine extra cdk contexts apart from the main cdktf.json
45
- * - Sets the properties from the extra contexts into cdk node context
30
+ * @summary Method to determine extra contexts apart from the main context
31
+ * - Sets the properties from the extra contexts
46
32
  * - Primary use is to have layered config in separate files to enable easier maintenance and readability
47
33
  */
48
- protected determineExtraContexts(): void;
34
+ protected determineExtraContexts(props: CommonAzureStackProps): Record<string, any>;
49
35
  /**
50
- * @summary Method to determine extra cdk stage contexts apart from the main cdktf.json
51
- * - Sets the properties from the extra stage contexts into cdk node context
36
+ * @summary Method to determine extra stage contexts apart from the main context
37
+ * - Sets the properties from the extra stage contexts
52
38
  * - Primary use is to have layered config for each environment which is injected into the context
53
39
  */
54
- protected determineStageContexts(): void;
40
+ protected determineStageContexts(props: CommonAzureStackProps): any;
55
41
  /**
56
42
  * @summary Determine the fully qualified domain name based on domainName & subDomain
57
43
  */
58
- protected fullyQualifiedDomain(): any;
44
+ protected fullyQualifiedDomain(): string;
59
45
  }
@@ -1,134 +1,137 @@
1
+ import { ComponentResource, Config } from '@pulumi/pulumi';
1
2
  import appRoot from 'app-root-path';
2
- import { Aspects, TerraformStack } from 'cdktf';
3
3
  import fs from 'fs';
4
4
  import _ from 'lodash';
5
5
  import path from 'path';
6
6
  import { isDevStage } from '../../common/index.js';
7
- import { TagsAddingAspect } from './tagging.js';
7
+ import { registerTagTransformation } from './tagging.js';
8
8
  /**
9
- * @classdesc Common stack to use as a base for all higher level constructs.
9
+ * @classdesc Common stack to use as a base for all higher level constructs using Pulumi
10
10
  * @example
11
+ * ```typescript
11
12
  * import { CommonAzureStack } from '@gradientedge/cdk-utils'
12
13
  *
13
14
  * class CustomStack extends CommonAzureStack {
14
- * constructor(parent: App, name: string, props: StackProps) {
15
- * super(parent, name, props)
15
+ * constructor(name: string, props: CommonAzureStackProps) {
16
+ * super(name, props)
16
17
  * // provision resources
17
18
  * }
18
19
  * }
20
+ * ```
19
21
  */
20
- export class CommonAzureStack extends TerraformStack {
22
+ export class CommonAzureStack extends ComponentResource {
21
23
  construct;
22
24
  props;
23
- constructor(parent, name, props) {
24
- super(parent, name);
25
- /* determine extra cdk contexts */
26
- this.determineExtraContexts();
27
- /* determine extra cdk stage contexts */
28
- this.determineStageContexts();
25
+ config;
26
+ constructor(name, props, options) {
27
+ super(`custom:azure:Stack:${name}`, name, props, options);
28
+ /* initialise config */
29
+ this.config = new Config();
29
30
  this.props = this.determineConstructProps(props);
30
- Aspects.of(this).add(new TagsAddingAspect(this.props.defaultTags || {}));
31
+ /* register tag transformation for automatic tag application */
32
+ if (this.props.defaultTags) {
33
+ registerTagTransformation(this.props.defaultTags);
34
+ }
31
35
  }
32
36
  /**
33
- * @summary Method to determine the core CDK construct properties injected via context cdktf.json
37
+ * @summary Method to determine the core construct properties injected via context
34
38
  * @param props The stack properties
35
39
  * @returns The stack properties
36
40
  */
37
41
  determineConstructProps(props) {
42
+ let projectProps = props;
43
+ if (!projectProps) {
44
+ const projectPropsPath = path.join(appRoot.path, 'pulumi.json');
45
+ if (!fs.existsSync(projectPropsPath))
46
+ throw `Context properties unavailable in path:${projectPropsPath}`;
47
+ const projectPropsBuffer = fs.readFileSync(projectPropsPath);
48
+ projectProps = JSON.parse(projectPropsBuffer.toString('utf-8'));
49
+ }
38
50
  return {
39
- domainName: this.node.tryGetContext('domainName'),
40
- extraContexts: this.node.tryGetContext('extraContexts'),
41
- features: this.node.tryGetContext('features'),
42
- location: this.node.tryGetContext('location'),
43
- name: this.node.tryGetContext('resourceGroupName'),
44
- resourceGroupName: this.node.tryGetContext('resourceGroupName'),
45
- globalPrefix: this.node.tryGetContext('globalPrefix'),
46
- globalSuffix: this.node.tryGetContext('globalSuffix'),
47
- resourceNameOptions: this.node.tryGetContext('resourceNameOptions'),
48
- resourcePrefix: this.node.tryGetContext('resourcePrefix'),
49
- resourceSuffix: this.node.tryGetContext('resourceSuffix'),
50
- skipStageForARecords: this.node.tryGetContext('skipStageForARecords'),
51
- stage: this.node.tryGetContext('stage'),
52
- subDomain: this.node.tryGetContext('subDomain'),
53
- subscriptionId: this.node.tryGetContext('subscriptionId'),
51
+ domainName: projectProps.domainName,
52
+ extraContexts: projectProps.extraContexts,
53
+ location: projectProps.location,
54
+ name: projectProps.resourceGroupName ?? projectProps.name,
55
+ resourceGroupName: projectProps.resourceGroupName,
56
+ globalPrefix: projectProps.globalPrefix,
57
+ globalSuffix: projectProps.globalSuffix,
58
+ resourceNameOptions: projectProps.resourceNameOptions,
59
+ resourcePrefix: projectProps.resourcePrefix,
60
+ resourceSuffix: projectProps.resourceSuffix,
61
+ skipStageForARecords: projectProps.skipStageForARecords,
62
+ stage: projectProps.stage,
63
+ stageContextPath: projectProps.stageContextPath,
64
+ subDomain: projectProps.subDomain,
65
+ subscriptionId: projectProps.subscriptionId,
66
+ tenantId: projectProps.tenantId,
67
+ clientId: projectProps.clientId,
68
+ clientSecret: projectProps.clientSecret,
69
+ defaultTags: projectProps.defaultTags,
70
+ ...this.determineExtraContexts(props),
71
+ ...this.determineStageContexts(props),
54
72
  };
55
73
  }
56
74
  /**
57
- * @summary Method to determine extra cdk contexts apart from the main cdktf.json
58
- * - Sets the properties from the extra contexts into cdk node context
75
+ * @summary Method to determine extra contexts apart from the main context
76
+ * - Sets the properties from the extra contexts
59
77
  * - Primary use is to have layered config in separate files to enable easier maintenance and readability
60
78
  */
61
- determineExtraContexts() {
62
- const extraContexts = this.node.tryGetContext('extraContexts');
63
- const debug = this.node.tryGetContext('debug');
64
- if (!extraContexts) {
65
- if (debug)
66
- console.debug(`No additional contexts provided. Using default context properties from cdktf.json`);
67
- return;
79
+ determineExtraContexts(props) {
80
+ if (!props.extraContexts) {
81
+ if (props.debug)
82
+ console.debug(`No additional contexts provided. Using default context properties`);
83
+ return {};
68
84
  }
69
- _.forEach(extraContexts, (context) => {
85
+ let extraContextProps = {};
86
+ _.forEach(props.extraContexts, (context) => {
70
87
  const extraContextPath = path.join(appRoot.path, context);
71
- /* scenario where extra context is configured in cdk.json but absent in file system */
88
+ /* scenario where extra context is configured but absent in file system */
72
89
  if (!fs.existsSync(extraContextPath))
73
90
  throw `Extra context properties unavailable in path:${extraContextPath}`;
74
91
  /* read the extra properties */
75
92
  const extraContextPropsBuffer = fs.readFileSync(extraContextPath);
76
- if (debug)
93
+ if (props.debug)
77
94
  console.debug(`Adding additional contexts provided in ${extraContextPath}`);
78
95
  /* parse as JSON properties */
79
- const extraContextProps = JSON.parse(extraContextPropsBuffer.toString('utf-8'));
80
- /* set each of the property into the cdk node context */
81
- _.keys(extraContextProps).forEach((propKey) => {
82
- this.node.setContext(propKey, extraContextProps[propKey]);
83
- });
96
+ extraContextProps = {
97
+ ...extraContextProps,
98
+ ...JSON.parse(extraContextPropsBuffer.toString('utf-8')),
99
+ };
84
100
  });
101
+ return extraContextProps;
85
102
  }
86
103
  /**
87
- * @summary Method to determine extra cdk stage contexts apart from the main cdktf.json
88
- * - Sets the properties from the extra stage contexts into cdk node context
104
+ * @summary Method to determine extra stage contexts apart from the main context
105
+ * - Sets the properties from the extra stage contexts
89
106
  * - Primary use is to have layered config for each environment which is injected into the context
90
107
  */
91
- determineStageContexts() {
92
- const stage = process.env.STAGE ?? this.node.tryGetContext('stage');
93
- const stageContextPath = this.node.tryGetContext('stageContextPath') || 'cdkEnv';
94
- const stageContextFilePath = path.join(appRoot.path, stageContextPath, `${stage}.json`);
95
- const debug = this.node.tryGetContext('debug');
96
- if (isDevStage(stage)) {
97
- if (debug)
108
+ determineStageContexts(props) {
109
+ const stageContextFilePath = path.join(appRoot.path, props.stageContextPath ?? 'env', `${props.stage}.json`);
110
+ if (isDevStage(props.stage)) {
111
+ if (props.debug)
98
112
  console.debug(`Development stage. Using default stage context properties`);
99
113
  }
100
114
  /* alert default context usage when extra stage config is missing */
101
115
  if (!fs.existsSync(stageContextFilePath)) {
102
- if (debug)
116
+ if (props.debug)
103
117
  console.debug(`Stage specific context properties unavailable in path:${stageContextFilePath}`);
104
- if (debug)
105
- console.debug(`Using default stage context properties for ${stage} stage`);
106
- return;
118
+ if (props.debug)
119
+ console.debug(`Using default stage context properties for ${props.stage} stage`);
120
+ return {};
107
121
  }
108
122
  /* read the extra properties */
109
123
  const stageContextPropsBuffer = fs.readFileSync(stageContextFilePath);
110
- if (debug)
124
+ if (props.debug)
111
125
  console.debug(`Adding additional stage contexts provided in ${stageContextFilePath}`);
112
126
  /* parse as JSON properties */
113
- const stageContextProps = JSON.parse(stageContextPropsBuffer.toString('utf-8'));
114
- /* set each of the property into the cdk node context */
115
- _.keys(stageContextProps).forEach((propKey) => {
116
- /* handle object, array properties */
117
- if (typeof stageContextProps[propKey] === 'object' && !Array.isArray(stageContextProps[propKey])) {
118
- this.node.setContext(propKey, _.merge(this.node.tryGetContext(propKey), stageContextProps[propKey]));
119
- }
120
- else {
121
- /* handle all other primitive properties */
122
- this.node.setContext(propKey, stageContextProps[propKey]);
123
- }
124
- });
127
+ return JSON.parse(stageContextPropsBuffer.toString('utf-8'));
125
128
  }
126
129
  /**
127
130
  * @summary Determine the fully qualified domain name based on domainName & subDomain
128
131
  */
129
132
  fullyQualifiedDomain() {
130
- const domainName = this.node.tryGetContext('domainName');
131
- const subDomain = this.node.tryGetContext('subDomain');
133
+ const domainName = this.props.domainName;
134
+ const subDomain = this.props.subDomain;
132
135
  return subDomain ? `${subDomain}.${domainName}` : domainName;
133
136
  }
134
137
  }
@@ -1,8 +1,29 @@
1
- import { IAspect } from 'cdktf';
2
- import { IConstruct } from 'constructs';
3
- export declare class TagsAddingAspect implements IAspect {
4
- private tagsToAdd;
5
- private tagsToIgnore;
6
- constructor(tagsToAdd: Record<string, string>, tagsToIgnore?: string[]);
7
- visit(node: IConstruct): void;
8
- }
1
+ /**
2
+ * @summary Check if a resource type is taggable
3
+ * @param resourceType The Pulumi resource type (e.g., 'azure-native:resources:ResourceGroup')
4
+ * @returns True if the resource supports tags, false otherwise
5
+ */
6
+ export declare function isTaggableResource(resourceType: string): boolean;
7
+ /**
8
+ * @summary Register a stack transformation to automatically apply tags to Azure resources
9
+ * @param defaultTags The default tags to apply to all resources
10
+ * @param tagsToIgnore Optional list of tag keys to ignore in lifecycle management
11
+ * @example
12
+ * ```typescript
13
+ * registerTagTransformation({ environment: 'production', team: 'platform' })
14
+ * ```
15
+ */
16
+ export declare function registerTagTransformation(defaultTags: Record<string, string>, tagsToIgnore?: string[]): void;
17
+ /**
18
+ * @summary Helper function to apply tags to a specific resource's properties
19
+ * @param props The resource properties
20
+ * @param defaultTags The default tags to merge with existing tags
21
+ * @returns The properties with merged tags
22
+ * @example
23
+ * ```typescript
24
+ * const resourceGroupProps = applyTags(props, { environment: 'dev' })
25
+ * ```
26
+ */
27
+ export declare function applyTags<T extends {
28
+ tags?: Record<string, string>;
29
+ }>(props: T, defaultTags: Record<string, string>): T;