@gradientedge/cdk-utils 9.39.2 → 9.41.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 (55) hide show
  1. package/dist/src/lib/azure/common/construct.d.ts +11 -7
  2. package/dist/src/lib/azure/common/construct.js +17 -10
  3. package/dist/src/lib/azure/common/resource-name-formatter.d.ts +14 -0
  4. package/dist/src/lib/azure/common/resource-name-formatter.js +32 -0
  5. package/dist/src/lib/azure/common/types.d.ts +14 -0
  6. package/dist/src/lib/azure/services/api-management/main.js +1 -3
  7. package/dist/src/lib/azure/services/api-management/types.d.ts +2 -1
  8. package/dist/src/lib/azure/services/app-configuration/main.js +1 -3
  9. package/dist/src/lib/azure/services/app-service/main.js +2 -4
  10. package/dist/src/lib/azure/services/application-insights/main.js +1 -3
  11. package/dist/src/lib/azure/services/cosmosdb/main.js +5 -9
  12. package/dist/src/lib/azure/services/dns/index.d.ts +2 -0
  13. package/dist/src/lib/azure/services/dns/index.js +18 -0
  14. package/dist/src/lib/azure/services/dns/main.d.ts +48 -0
  15. package/dist/src/lib/azure/services/dns/main.js +113 -0
  16. package/dist/src/lib/azure/services/dns/types.d.ts +9 -0
  17. package/dist/src/lib/azure/services/dns/types.js +2 -0
  18. package/dist/src/lib/azure/services/eventgrid/main.d.ts +9 -0
  19. package/dist/src/lib/azure/services/eventgrid/main.js +30 -4
  20. package/dist/src/lib/azure/services/eventgrid/types.d.ts +2 -1
  21. package/dist/src/lib/azure/services/function/main.js +5 -9
  22. package/dist/src/lib/azure/services/index.d.ts +2 -0
  23. package/dist/src/lib/azure/services/index.js +2 -0
  24. package/dist/src/lib/azure/services/key-vault/main.js +2 -4
  25. package/dist/src/lib/azure/services/log-analytics-workspace/index.d.ts +2 -0
  26. package/dist/src/lib/azure/services/log-analytics-workspace/index.js +18 -0
  27. package/dist/src/lib/azure/services/log-analytics-workspace/main.d.ts +30 -0
  28. package/dist/src/lib/azure/services/log-analytics-workspace/main.js +55 -0
  29. package/dist/src/lib/azure/services/log-analytics-workspace/types.d.ts +3 -0
  30. package/dist/src/lib/azure/services/log-analytics-workspace/types.js +2 -0
  31. package/dist/src/lib/azure/services/servicebus/main.js +5 -7
  32. package/dist/src/lib/azure/services/storage/main.js +4 -8
  33. package/package.json +1 -1
  34. package/src/lib/azure/common/construct.ts +20 -10
  35. package/src/lib/azure/common/resource-name-formatter.ts +38 -0
  36. package/src/lib/azure/common/types.ts +13 -0
  37. package/src/lib/azure/services/api-management/main.ts +4 -3
  38. package/src/lib/azure/services/api-management/types.ts +3 -1
  39. package/src/lib/azure/services/app-configuration/main.ts +4 -3
  40. package/src/lib/azure/services/app-service/main.ts +5 -4
  41. package/src/lib/azure/services/application-insights/main.ts +4 -3
  42. package/src/lib/azure/services/cosmosdb/main.ts +11 -9
  43. package/src/lib/azure/services/dns/index.ts +2 -0
  44. package/src/lib/azure/services/dns/main.ts +126 -0
  45. package/src/lib/azure/services/dns/types.ts +7 -0
  46. package/src/lib/azure/services/eventgrid/main.ts +43 -4
  47. package/src/lib/azure/services/eventgrid/types.ts +4 -1
  48. package/src/lib/azure/services/function/main.ts +11 -9
  49. package/src/lib/azure/services/index.ts +2 -0
  50. package/src/lib/azure/services/key-vault/main.ts +5 -4
  51. package/src/lib/azure/services/log-analytics-workspace/index.ts +2 -0
  52. package/src/lib/azure/services/log-analytics-workspace/main.ts +60 -0
  53. package/src/lib/azure/services/log-analytics-workspace/types.ts +3 -0
  54. package/src/lib/azure/services/servicebus/main.ts +8 -7
  55. package/src/lib/azure/services/storage/main.ts +10 -8
@@ -33,15 +33,13 @@ class AzureKeyVaultManager {
33
33
  if (!props)
34
34
  throw `Props undefined for ${id}`;
35
35
  const resourceGroup = new data_azurerm_resource_group_1.DataAzurermResourceGroup(scope, `${id}-kv-rg`, {
36
- name: scope.props.resourceGroupName
37
- ? `${scope.props.resourceGroupName}-${scope.props.stage}`
38
- : `${props.resourceGroupName}`,
36
+ name: scope.resourceNameFormatter.format(scope.props.resourceGroupName || props.resourceGroupName, scope.props.resourceNameOptions?.resourceGroup),
39
37
  });
40
38
  if (!resourceGroup)
41
39
  throw `Resource group undefined for ${id}`;
42
40
  const keyVault = new key_vault_1.KeyVault(scope, `${id}-kv`, {
43
41
  ...props,
44
- name: `${props.name}-${scope.props.stage}`,
42
+ name: scope.resourceNameFormatter.format(props.name),
45
43
  location: resourceGroup.location,
46
44
  resourceGroupName: resourceGroup.name,
47
45
  skuName: props.skuName ?? 'standard',
@@ -0,0 +1,2 @@
1
+ export * from './main';
2
+ export * from './types';
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./main"), exports);
18
+ __exportStar(require("./types"), exports);
@@ -0,0 +1,30 @@
1
+ import { LogAnalyticsWorkspace } from '@cdktf/provider-azurerm/lib/log-analytics-workspace';
2
+ import { CommonAzureConstruct } from '../../common';
3
+ import { LogAnalyticsWorkspaceProps } from './types';
4
+ /**
5
+ * @classdesc Provides operations on Azure Log Analytics Workspace
6
+ * - A new instance of this class is injected into {@link CommonAzureConstruct} constructor.
7
+ * - If a custom construct extends {@link CommonAzureConstruct}, an instance is available within the context.
8
+ * @example
9
+ * ```
10
+ * import { CommonAzureConstruct, CommonAzureStackProps } from '@gradientedge/cdk-utils'
11
+ *
12
+ * class CustomConstruct extends CommonAzureConstruct {
13
+ * constructor(parent: Construct, id: string, props: CommonAzureStackProps) {
14
+ * super(parent, id, props)
15
+ * this.props = props
16
+ * this.LogAnalyticWorkspaceManager.createLogAnalyticsWorkspace('MyLogAnalyticsWorkspace', this, props)
17
+ * }
18
+ * }
19
+ * ```
20
+ */
21
+ export declare class AzureLogAnalyticsWorkspaceManager {
22
+ /**
23
+ * @summary Method to create a new cosmosdb account
24
+ * @param id scoped id of the resource
25
+ * @param scope scope in which this resource is defined
26
+ * @param props cosmosdb account properties
27
+ * @see [CDKTF CosmosDb Account Module]{@link https://github.com/cdktf/cdktf-provider-azurerm/blob/main/docs/logAnalyticsWorkspace.typescript.md}
28
+ */
29
+ createLogAnalyticsWorkspace(id: string, scope: CommonAzureConstruct, props: LogAnalyticsWorkspaceProps): LogAnalyticsWorkspace;
30
+ }
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AzureLogAnalyticsWorkspaceManager = void 0;
4
+ const data_azurerm_resource_group_1 = require("@cdktf/provider-azurerm/lib/data-azurerm-resource-group");
5
+ const log_analytics_workspace_1 = require("@cdktf/provider-azurerm/lib/log-analytics-workspace");
6
+ const utils_1 = require("../../utils");
7
+ /**
8
+ * @classdesc Provides operations on Azure Log Analytics Workspace
9
+ * - A new instance of this class is injected into {@link CommonAzureConstruct} constructor.
10
+ * - If a custom construct extends {@link CommonAzureConstruct}, an instance is available within the context.
11
+ * @example
12
+ * ```
13
+ * import { CommonAzureConstruct, CommonAzureStackProps } from '@gradientedge/cdk-utils'
14
+ *
15
+ * class CustomConstruct extends CommonAzureConstruct {
16
+ * constructor(parent: Construct, id: string, props: CommonAzureStackProps) {
17
+ * super(parent, id, props)
18
+ * this.props = props
19
+ * this.LogAnalyticWorkspaceManager.createLogAnalyticsWorkspace('MyLogAnalyticsWorkspace', this, props)
20
+ * }
21
+ * }
22
+ * ```
23
+ */
24
+ class AzureLogAnalyticsWorkspaceManager {
25
+ /**
26
+ * @summary Method to create a new cosmosdb account
27
+ * @param id scoped id of the resource
28
+ * @param scope scope in which this resource is defined
29
+ * @param props cosmosdb account properties
30
+ * @see [CDKTF CosmosDb Account Module]{@link https://github.com/cdktf/cdktf-provider-azurerm/blob/main/docs/logAnalyticsWorkspace.typescript.md}
31
+ */
32
+ createLogAnalyticsWorkspace(id, scope, props) {
33
+ if (!props)
34
+ throw `Props undefined for ${id}`;
35
+ const resourceGroup = new data_azurerm_resource_group_1.DataAzurermResourceGroup(scope, `${id}-lw-rg`, {
36
+ name: scope.resourceNameFormatter.format(scope.props.resourceGroupName || props.resourceGroupName, scope.props.resourceNameOptions?.resourceGroup),
37
+ });
38
+ if (!resourceGroup)
39
+ throw `Resource group undefined for ${id}`;
40
+ const logAnalyticsWorkspace = new log_analytics_workspace_1.LogAnalyticsWorkspace(scope, `${id}-lw`, {
41
+ ...props,
42
+ name: scope.resourceNameFormatter.format(props.name),
43
+ location: resourceGroup.location,
44
+ resourceGroupName: resourceGroup.name,
45
+ tags: props.tags ?? {
46
+ environment: scope.props.stage,
47
+ },
48
+ });
49
+ (0, utils_1.createAzureTfOutput)(`${id}-logAnalyticsWorkspaceName`, scope, logAnalyticsWorkspace.name);
50
+ (0, utils_1.createAzureTfOutput)(`${id}-logAnalyticsWorkspaceFriendlyUniqueId`, scope, logAnalyticsWorkspace.friendlyUniqueId);
51
+ (0, utils_1.createAzureTfOutput)(`${id}-logAnalyticsWorkspaceId`, scope, logAnalyticsWorkspace.id);
52
+ return logAnalyticsWorkspace;
53
+ }
54
+ }
55
+ exports.AzureLogAnalyticsWorkspaceManager = AzureLogAnalyticsWorkspaceManager;
@@ -0,0 +1,3 @@
1
+ import { LogAnalyticsWorkspaceConfig } from '@cdktf/provider-azurerm/lib/log-analytics-workspace';
2
+ export interface LogAnalyticsWorkspaceProps extends LogAnalyticsWorkspaceConfig {
3
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -36,15 +36,13 @@ class AzureServicebusManager {
36
36
  if (!props)
37
37
  throw `Props undefined for ${id}`;
38
38
  const resourceGroup = new data_azurerm_resource_group_1.DataAzurermResourceGroup(scope, `${id}-sn-rg`, {
39
- name: scope.props.resourceGroupName
40
- ? `${scope.props.resourceGroupName}-${scope.props.stage}`
41
- : `${props.resourceGroupName}`,
39
+ name: scope.resourceNameFormatter.format(scope.props.resourceGroupName || props.resourceGroupName, scope.props.resourceNameOptions?.resourceGroup),
42
40
  });
43
41
  if (!resourceGroup)
44
42
  throw `Resource group undefined for ${id}`;
45
43
  const servicebusNamespace = new servicebus_namespace_1.ServicebusNamespace(scope, `${id}-sn`, {
46
44
  ...props,
47
- name: `${props.name}-${scope.props.stage}`,
45
+ name: scope.resourceNameFormatter.format(props.name),
48
46
  resourceGroupName: resourceGroup.name,
49
47
  location: resourceGroup.location,
50
48
  identity: {
@@ -72,7 +70,7 @@ class AzureServicebusManager {
72
70
  throw `Props undefined for ${id}`;
73
71
  const servicebusTopic = new servicebus_topic_1.ServicebusTopic(scope, `${id}-st`, {
74
72
  ...props,
75
- name: `${props.name}-${scope.props.stage}`,
73
+ name: scope.resourceNameFormatter.format(props.name),
76
74
  namespaceId: props.namespaceId,
77
75
  });
78
76
  (0, utils_1.createAzureTfOutput)(`${id}-servicebusTopicName`, scope, servicebusTopic.name);
@@ -92,7 +90,7 @@ class AzureServicebusManager {
92
90
  throw `Props undefined for ${id}`;
93
91
  const servicebusQueue = new servicebus_queue_1.ServicebusQueue(scope, `${id}-sq`, {
94
92
  ...props,
95
- name: `${props.name}-${scope.props.stage}`,
93
+ name: scope.resourceNameFormatter.format(props.name),
96
94
  namespaceId: props.namespaceId,
97
95
  });
98
96
  (0, utils_1.createAzureTfOutput)(`${id}-servicebusQueueName`, scope, servicebusQueue.name);
@@ -112,7 +110,7 @@ class AzureServicebusManager {
112
110
  throw `Props undefined for ${id}`;
113
111
  const servicebusSubscription = new servicebus_subscription_1.ServicebusSubscription(scope, `${id}-ss`, {
114
112
  ...props,
115
- name: `${props.name}-${scope.props.stage}`,
113
+ name: scope.resourceNameFormatter.format(props.name),
116
114
  maxDeliveryCount: props.maxDeliveryCount || 1,
117
115
  });
118
116
  (0, utils_1.createAzureTfOutput)(`${id}-servicebusSubscriptionName`, scope, servicebusSubscription.name);
@@ -37,9 +37,7 @@ class AzureStorageManager {
37
37
  if (!props)
38
38
  throw `Props undefined for ${id}`;
39
39
  const resourceGroup = new data_azurerm_resource_group_1.DataAzurermResourceGroup(scope, `${id}-sc-rg`, {
40
- name: scope.props.resourceGroupName
41
- ? `${scope.props.resourceGroupName}-${scope.props.stage}`
42
- : `${props.resourceGroupName}`,
40
+ name: scope.resourceNameFormatter.format(scope.props.resourceGroupName || props.resourceGroupName, scope.props.resourceNameOptions?.resourceGroup),
43
41
  });
44
42
  if (!resourceGroup)
45
43
  throw `Resource group undefined for ${id}`;
@@ -70,7 +68,7 @@ class AzureStorageManager {
70
68
  throw `Props undefined for ${id}`;
71
69
  const storageContainer = new storage_container_1.StorageContainer(scope, `${id}-sc`, {
72
70
  ...props,
73
- name: `${props.name}-${scope.props.stage}`,
71
+ name: scope.resourceNameFormatter.format(props.name),
74
72
  });
75
73
  (0, utils_1.createAzureTfOutput)(`${id}-storageContainerName`, scope, storageContainer.name);
76
74
  (0, utils_1.createAzureTfOutput)(`${id}-storageContainerFriendlyUniqueId`, scope, storageContainer.friendlyUniqueId);
@@ -88,9 +86,7 @@ class AzureStorageManager {
88
86
  if (!props)
89
87
  throw `Props undefined for ${id}`;
90
88
  const resourceGroup = new data_azurerm_resource_group_1.DataAzurermResourceGroup(scope, `${id}-sb-rg`, {
91
- name: scope.props.resourceGroupName
92
- ? `${scope.props.resourceGroupName}-${scope.props.stage}`
93
- : `${props.resourceGroupName}`,
89
+ name: scope.resourceNameFormatter.format(scope.props.resourceGroupName || props.resourceGroupName, scope.props.resourceNameOptions?.resourceGroup),
94
90
  });
95
91
  if (!resourceGroup)
96
92
  throw `Resource group undefined for ${id}`;
@@ -105,7 +101,7 @@ class AzureStorageManager {
105
101
  });
106
102
  const storageBlob = new storage_blob_1.StorageBlob(scope, `${id}-sb`, {
107
103
  ...props,
108
- name: `${props.name}-${scope.props.stage}`,
104
+ name: scope.resourceNameFormatter.format(props.name),
109
105
  storageAccountName: storageAccount.name,
110
106
  storageContainerName: storageContainer.name,
111
107
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gradientedge/cdk-utils",
3
- "version": "9.39.2",
3
+ "version": "9.41.0",
4
4
  "description": "Utilities for AWS CDK provisioning",
5
5
  "main": "dist/index.js",
6
6
  "engines": {
@@ -16,26 +16,32 @@ import {
16
16
  AzureCosmosDbManager,
17
17
  AzureServicebusManager,
18
18
  AzureEventgridManager,
19
+ AzureDnsManager,
20
+ AzureLogAnalyticsWorkspaceManager,
19
21
  } from '../services'
20
22
  import { CommonAzureStackProps } from './types'
21
23
  import { AzureRemoteBackend } from './constants'
24
+ import { AzureResourceNameFormatter } from './resource-name-formatter'
22
25
 
23
26
  export class CommonAzureConstruct extends TerraformStack {
24
27
  declare props: CommonAzureStackProps
25
- id: string
26
- fullyQualifiedDomainName: string
27
- tenantId: string
28
28
  apiManagementManager: AzureApiManagementManager
29
+ appConfigurationManager: AzureAppConfigurationManager
29
30
  appServiceManager: AzureAppServiceManager
30
31
  applicationInsightsManager: AzureApplicationInsightsManager
31
- appConfigurationManager: AzureAppConfigurationManager
32
32
  cosmosDbManager: AzureCosmosDbManager
33
+ dnsManager: AzureDnsManager
34
+ eventgridManager: AzureEventgridManager
35
+ fullyQualifiedDomainName: string
33
36
  functiontManager: AzureFunctionManager
37
+ id: string
34
38
  keyVaultManager: AzureKeyVaultManager
39
+ logAnalyticsWorkspaceManager: AzureLogAnalyticsWorkspaceManager
35
40
  resourceGroupManager: AzureResourceGroupManager
36
- storageManager: AzureStorageManager
41
+ resourceNameFormatter: AzureResourceNameFormatter
37
42
  servicebusManager: AzureServicebusManager
38
- eventgridManager: AzureEventgridManager
43
+ storageManager: AzureStorageManager
44
+ tenantId: string
39
45
 
40
46
  constructor(scope: Construct, id: string, props: CommonAzureStackProps) {
41
47
  super(scope, id)
@@ -43,22 +49,26 @@ export class CommonAzureConstruct extends TerraformStack {
43
49
  this.id = id
44
50
 
45
51
  this.apiManagementManager = new AzureApiManagementManager()
52
+ this.appConfigurationManager = new AzureAppConfigurationManager()
46
53
  this.appServiceManager = new AzureAppServiceManager()
47
54
  this.applicationInsightsManager = new AzureApplicationInsightsManager()
48
- this.appConfigurationManager = new AzureAppConfigurationManager()
49
55
  this.cosmosDbManager = new AzureCosmosDbManager()
56
+ this.dnsManager = new AzureDnsManager()
57
+ this.eventgridManager = new AzureEventgridManager()
50
58
  this.functiontManager = new AzureFunctionManager()
51
59
  this.keyVaultManager = new AzureKeyVaultManager()
60
+ this.logAnalyticsWorkspaceManager = new AzureLogAnalyticsWorkspaceManager()
52
61
  this.resourceGroupManager = new AzureResourceGroupManager()
53
- this.storageManager = new AzureStorageManager()
62
+ this.resourceNameFormatter = new AzureResourceNameFormatter(this, `${id}-rnf`, props)
54
63
  this.servicebusManager = new AzureServicebusManager()
55
- this.eventgridManager = new AzureEventgridManager()
64
+ this.storageManager = new AzureStorageManager()
56
65
 
57
66
  this.determineFullyQualifiedDomain()
58
67
  this.determineRemoteBackend()
59
68
  this.determineTenantId()
60
- new AzurermProvider(this, `${this.id}-provider`, this.props)
69
+
61
70
  new AzapiProvider(this, `${this.id}-azapi-provider`, this.props)
71
+ new AzurermProvider(this, `${this.id}-provider`, this.props)
62
72
  }
63
73
 
64
74
  /**
@@ -0,0 +1,38 @@
1
+ import { Construct } from 'constructs'
2
+ import { AzureResourceNameFormatterProps } from './types'
3
+ import { CommonAzureStackProps } from './types'
4
+
5
+ export class AzureResourceNameFormatter extends Construct {
6
+ props: CommonAzureStackProps
7
+
8
+ constructor(parent: Construct, id: string, props: CommonAzureStackProps) {
9
+ super(parent, id)
10
+ this.props = props
11
+ }
12
+
13
+ /**
14
+ * @summary Helper method to format azure resource name based on the provided options
15
+ * @param resourceName The azure resource name to format
16
+ * @param options Options to control the formatting of the resource name
17
+ * @returns The formatted Azure-compliant resource name
18
+ */
19
+ public format(resourceName: string, options?: AzureResourceNameFormatterProps) {
20
+ const azureResourceNameElements = []
21
+
22
+ if (!options?.exclude) {
23
+ azureResourceNameElements.push(options?.globalPrefix ? this.props.globalPrefix : undefined)
24
+ azureResourceNameElements.push(options?.prefix ?? this.props.resourcePrefix)
25
+ }
26
+
27
+ azureResourceNameElements.push(resourceName)
28
+
29
+ if (!options?.exclude) {
30
+ azureResourceNameElements.push(options?.suffix ?? this.props.resourceSuffix)
31
+ azureResourceNameElements.push(options?.globalSuffix ? this.props.globalSuffix : undefined)
32
+ }
33
+
34
+ azureResourceNameElements.push(this.props.stage)
35
+
36
+ return azureResourceNameElements.filter(Boolean).join('-')
37
+ }
38
+ }
@@ -8,8 +8,21 @@ import { AzurermBackendConfig } from 'cdktf'
8
8
  export interface CommonAzureStackProps extends BaseProps, AzurermProviderConfig {
9
9
  resourceGroupName?: string
10
10
  remoteBackend?: AzureRemoteBackendProps
11
+ globalPrefix?: string
12
+ globalSuffix?: string
13
+ resourcePrefix?: string
14
+ resourceSuffix?: string
15
+ resourceNameOptions?: { [key: string]: AzureResourceNameFormatterProps }
11
16
  }
12
17
 
13
18
  export interface AzureRemoteBackendProps extends AzurermBackendConfig {
14
19
  type: AzureRemoteBackend
15
20
  }
21
+
22
+ export interface AzureResourceNameFormatterProps {
23
+ exclude?: boolean
24
+ globalPrefix?: boolean
25
+ globalSuffix?: boolean
26
+ prefix?: string
27
+ suffix?: string
28
+ }
@@ -51,9 +51,10 @@ export class AzureApiManagementManager {
51
51
  if (!props) throw `Props undefined for ${id}`
52
52
 
53
53
  const resourceGroup = new DataAzurermResourceGroup(scope, `${id}-am-rg`, {
54
- name: scope.props.resourceGroupName
55
- ? `${scope.props.resourceGroupName}-${scope.props.stage}`
56
- : `${props.resourceGroupName}`,
54
+ name: scope.resourceNameFormatter.format(
55
+ scope.props.resourceGroupName || props.resourceGroupName,
56
+ scope.props.resourceNameOptions?.resourceGroup
57
+ ),
57
58
  })
58
59
 
59
60
  if (!resourceGroup) throw `Resource group undefined for ${id}`
@@ -4,7 +4,9 @@ import { ApiManagementApiConfig } from '@cdktf/provider-azurerm/lib/api-manageme
4
4
  import { ApiManagementApiOperationConfig } from '@cdktf/provider-azurerm/lib/api-management-api-operation'
5
5
  import { ApiManagementApiOperationPolicyConfig } from '@cdktf/provider-azurerm/lib/api-management-api-operation-policy'
6
6
 
7
- export interface ApiManagementProps extends ApiManagementConfig {}
7
+ export interface ApiManagementProps extends Omit<ApiManagementConfig, 'name'> {
8
+ name?: string | undefined
9
+ }
8
10
 
9
11
  export interface ApiManagementBackendProps extends ApiManagementBackendConfig {}
10
12
 
@@ -33,9 +33,10 @@ export class AzureAppConfigurationManager {
33
33
  if (!props) throw `Props undefined for ${id}`
34
34
 
35
35
  const resourceGroup = new DataAzurermResourceGroup(scope, `${id}-am-rg`, {
36
- name: scope.props.resourceGroupName
37
- ? `${scope.props.resourceGroupName}-${scope.props.stage}`
38
- : `${props.resourceGroupName}`,
36
+ name: scope.resourceNameFormatter.format(
37
+ scope.props.resourceGroupName || props.resourceGroupName,
38
+ scope.props.resourceNameOptions?.resourceGroup
39
+ ),
39
40
  })
40
41
 
41
42
  if (!resourceGroup) throw `Resource group undefined for ${id}`
@@ -33,16 +33,17 @@ export class AzureAppServiceManager {
33
33
  if (!props) throw `Props undefined for ${id}`
34
34
 
35
35
  const resourceGroup = new DataAzurermResourceGroup(scope, `${id}-am-rg`, {
36
- name: scope.props.resourceGroupName
37
- ? `${scope.props.resourceGroupName}-${scope.props.stage}`
38
- : `${props.resourceGroupName}`,
36
+ name: scope.resourceNameFormatter.format(
37
+ scope.props.resourceGroupName || props.resourceGroupName,
38
+ scope.props.resourceNameOptions?.resourceGroup
39
+ ),
39
40
  })
40
41
 
41
42
  if (!resourceGroup) throw `Resource group undefined for ${id}`
42
43
 
43
44
  const appServicePlan = new ServicePlan(scope, `${id}-am`, {
44
45
  ...props,
45
- name: `${props.name}-${scope.props.stage}`,
46
+ name: scope.resourceNameFormatter.format(props.name),
46
47
  resourceGroupName: resourceGroup.name,
47
48
  tags: props.tags ?? {
48
49
  environment: scope.props.stage,
@@ -33,9 +33,10 @@ export class AzureApplicationInsightsManager {
33
33
  if (!props) throw `Props undefined for ${id}`
34
34
 
35
35
  const resourceGroup = new DataAzurermResourceGroup(scope, `${id}-am-rg`, {
36
- name: scope.props.resourceGroupName
37
- ? `${scope.props.resourceGroupName}-${scope.props.stage}`
38
- : `${props.resourceGroupName}`,
36
+ name: scope.resourceNameFormatter.format(
37
+ scope.props.resourceGroupName || props.resourceGroupName,
38
+ scope.props.resourceNameOptions?.resourceGroup
39
+ ),
39
40
  })
40
41
 
41
42
  if (!resourceGroup) throw `Resource group undefined for ${id}`
@@ -35,16 +35,17 @@ export class AzureCosmosDbManager {
35
35
  if (!props) throw `Props undefined for ${id}`
36
36
 
37
37
  const resourceGroup = new DataAzurermResourceGroup(scope, `${id}-ca-rg`, {
38
- name: scope.props.resourceGroupName
39
- ? `${scope.props.resourceGroupName}-${scope.props.stage}`
40
- : `${props.resourceGroupName}`,
38
+ name: scope.resourceNameFormatter.format(
39
+ scope.props.resourceGroupName || props.resourceGroupName,
40
+ scope.props.resourceNameOptions?.resourceGroup
41
+ ),
41
42
  })
42
43
 
43
44
  if (!resourceGroup) throw `Resource group undefined for ${id}`
44
45
 
45
46
  const cosmosdbAccount = new CosmosdbAccount(scope, `${id}-ca`, {
46
47
  ...props,
47
- name: `${props.name}-${scope.props.stage}`,
48
+ name: scope.resourceNameFormatter.format(props.name),
48
49
  location: resourceGroup.location,
49
50
  resourceGroupName: resourceGroup.name,
50
51
  tags: props.tags ?? {
@@ -70,16 +71,17 @@ export class AzureCosmosDbManager {
70
71
  if (!props) throw `Props undefined for ${id}`
71
72
 
72
73
  const resourceGroup = new DataAzurermResourceGroup(scope, `${id}-cd-rg`, {
73
- name: scope.props.resourceGroupName
74
- ? `${scope.props.resourceGroupName}-${scope.props.stage}`
75
- : `${props.resourceGroupName}`,
74
+ name: scope.resourceNameFormatter.format(
75
+ scope.props.resourceGroupName || props.resourceGroupName,
76
+ scope.props.resourceNameOptions?.resourceGroup
77
+ ),
76
78
  })
77
79
 
78
80
  if (!resourceGroup) throw `Resource group undefined for ${id}`
79
81
 
80
82
  const cosmosdbDatatbase = new CosmosdbSqlDatabase(scope, `${id}-cd`, {
81
83
  ...props,
82
- name: `${props.name}-${scope.props.stage}`,
84
+ name: scope.resourceNameFormatter.format(props.name),
83
85
  resourceGroupName: resourceGroup.name,
84
86
  })
85
87
 
@@ -110,7 +112,7 @@ export class AzureCosmosDbManager {
110
112
 
111
113
  const cosmosdbContainer = new CosmosdbSqlContainer(scope, `${id}-cc`, {
112
114
  ...props,
113
- name: `${props.name}-${scope.props.stage}`,
115
+ name: scope.resourceNameFormatter.format(props.name),
114
116
  resourceGroupName: resourceGroup.name,
115
117
  })
116
118
 
@@ -0,0 +1,2 @@
1
+ export * from './main'
2
+ export * from './types'
@@ -0,0 +1,126 @@
1
+ import { DataAzurermResourceGroup } from '@cdktf/provider-azurerm/lib/data-azurerm-resource-group'
2
+ import { DataAzurermDnsZone } from '@cdktf/provider-azurerm/lib/data-azurerm-dns-zone'
3
+ import { DnsZone } from '@cdktf/provider-azurerm/lib/dns-zone'
4
+ import { DnsARecord } from '@cdktf/provider-azurerm/lib/dns-a-record'
5
+ import { DnsCnameRecord } from '@cdktf/provider-azurerm/lib/dns-cname-record'
6
+ import { CommonAzureConstruct } from '../../common'
7
+ import { createAzureTfOutput } from '../../utils'
8
+ import { DnsZoneProps, DnsARecordProps, DnsCnameRecordProps } from './types'
9
+
10
+ /**
11
+ * @classdesc Provides operations on Azure DNS
12
+ * - A new instance of this class is injected into {@link CommonAzureConstruct} constructor.
13
+ * - If a custom construct extends {@link CommonAzureConstruct}, an instance is available within the context.
14
+ * @example
15
+ * ```
16
+ * import { CommonAzureConstruct, CommonAzureStackProps } from '@gradientedge/cdk-utils'
17
+ *
18
+ * class CustomConstruct extends CommonAzureConstruct {
19
+ * constructor(parent: Construct, id: string, props: CommonAzureStackProps) {
20
+ * super(parent, id, props)
21
+ * this.props = props
22
+ * this.dnsManager.createAppService('MyDnsZone', this, props)
23
+ * }
24
+ * }
25
+ * ```
26
+ */
27
+ export class AzureDnsManager {
28
+ /**
29
+ * @summary Method to create a new DNS Zone
30
+ * @param id scoped id of the resource
31
+ * @param scope scope in which this resource is defined
32
+ * @param props dns zone properties
33
+ * @see [CDKTF DNS Zone Module]{@link https://github.com/cdktf/cdktf-provider-azurerm/blob/main/docs/DnsZone.typescript.md}
34
+ */
35
+ public createDnsZone(id: string, scope: CommonAzureConstruct, props: DnsZoneProps) {
36
+ if (!props) throw `Props undefined for ${id}`
37
+
38
+ const resourceGroup = new DataAzurermResourceGroup(scope, `${id}-am-rg`, {
39
+ name: scope.resourceNameFormatter.format(
40
+ scope.props.resourceGroupName || props.resourceGroupName,
41
+ scope.props.resourceNameOptions?.resourceGroup
42
+ ),
43
+ })
44
+
45
+ if (!resourceGroup) throw `Resource group undefined for ${id}`
46
+
47
+ const dnsZone = new DnsZone(scope, `${id}-dz`, {
48
+ ...props,
49
+ name: scope.resourceNameFormatter.format(props.name),
50
+ resourceGroupName: resourceGroup.name,
51
+ tags: props.tags ?? {
52
+ environment: scope.props.stage,
53
+ },
54
+ })
55
+
56
+ createAzureTfOutput(`${id}-dnsZoneName`, scope, dnsZone.name)
57
+ createAzureTfOutput(`${id}-dnsZoneFriendlyUniqueId`, scope, dnsZone.friendlyUniqueId)
58
+ createAzureTfOutput(`${id}-dnsZoneId`, scope, dnsZone.id)
59
+
60
+ return dnsZone
61
+ }
62
+
63
+ /**
64
+ * @summary Method to create a new DNS A Record
65
+ * @param id scoped id of the resource
66
+ * @param scope scope in which this resource is defined
67
+ * @param props dns a record properties
68
+ * @see [CDKTF DNS A Record Module]{@link https://github.com/cdktf/cdktf-provider-azurerm/blob/main/docs/DnsARecord.typescript.md}
69
+ */
70
+ public createDnsARecord(id: string, scope: CommonAzureConstruct, props: DnsARecordProps) {
71
+ if (!props) throw `Props undefined for ${id}`
72
+
73
+ const dnsZone = new DataAzurermDnsZone(scope, `${id}-da-dz`, {
74
+ name: props.zoneName,
75
+ resourceGroupName: props.resourceGroupName,
76
+ })
77
+
78
+ const dnsARecord = new DnsARecord(scope, `${id}-da`, {
79
+ ...props,
80
+ name: scope.resourceNameFormatter.format(props.name),
81
+ resourceGroupName: dnsZone.resourceGroupName,
82
+ zoneName: dnsZone.name,
83
+ tags: props.tags ?? {
84
+ environment: scope.props.stage,
85
+ },
86
+ })
87
+
88
+ createAzureTfOutput(`${id}-dnsARecordName`, scope, dnsARecord.name)
89
+ createAzureTfOutput(`${id}-dnsARecordFriendlyUniqueId`, scope, dnsARecord.friendlyUniqueId)
90
+ createAzureTfOutput(`${id}-dnsARecordId`, scope, dnsARecord.id)
91
+
92
+ return dnsARecord
93
+ }
94
+
95
+ /**
96
+ * @summary Method to create a new DNS CNAME Record
97
+ * @param id scoped id of the resource
98
+ * @param scope scope in which this resource is defined
99
+ * @param props dns cname record properties
100
+ * @see [CDKTF DNS CNAME Record Module]{@link https://github.com/cdktf/cdktf-provider-azurerm/blob/main/docs/DnsCnameRecord.typescript.md}
101
+ */
102
+ public createDnsCnameRecord(id: string, scope: CommonAzureConstruct, props: DnsCnameRecordProps) {
103
+ if (!props) throw `Props undefined for ${id}`
104
+
105
+ const dnsZone = new DataAzurermDnsZone(scope, `${id}-dc-dz`, {
106
+ name: props.zoneName,
107
+ resourceGroupName: props.resourceGroupName,
108
+ })
109
+
110
+ const dnsCnameRecord = new DnsCnameRecord(scope, `${id}-dc`, {
111
+ ...props,
112
+ name: scope.resourceNameFormatter.format(props.name),
113
+ resourceGroupName: dnsZone.resourceGroupName,
114
+ zoneName: dnsZone.name,
115
+ tags: props.tags ?? {
116
+ environment: scope.props.stage,
117
+ },
118
+ })
119
+
120
+ createAzureTfOutput(`${id}-dnsCnameRecordName`, scope, dnsCnameRecord.name)
121
+ createAzureTfOutput(`${id}-dnsCnameRecordFriendlyUniqueId`, scope, dnsCnameRecord.friendlyUniqueId)
122
+ createAzureTfOutput(`${id}-dnsCnameRecordId`, scope, dnsCnameRecord.id)
123
+
124
+ return dnsCnameRecord
125
+ }
126
+ }
@@ -0,0 +1,7 @@
1
+ import { DnsZoneConfig } from '@cdktf/provider-azurerm/lib/dns-zone'
2
+ import { DnsARecordConfig } from '@cdktf/provider-azurerm/lib/dns-a-record'
3
+ import { DnsCnameRecordConfig } from '@cdktf/provider-azurerm/lib/dns-cname-record'
4
+
5
+ export interface DnsZoneProps extends DnsZoneConfig {}
6
+ export interface DnsARecordProps extends DnsARecordConfig {}
7
+ export interface DnsCnameRecordProps extends DnsCnameRecordConfig {}