@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,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 {
@@ -1,41 +1,39 @@
1
- import { ApiManagementApiOperationPolicy } from '@cdktf/provider-azurerm/lib/api-management-api-operation-policy/index.js'
2
- import { ApiManagementApiOperation } from '@cdktf/provider-azurerm/lib/api-management-api-operation/index.js'
3
- import { ApiManagementApi } from '@cdktf/provider-azurerm/lib/api-management-api/index.js'
4
- import { ApiManagementBackend } from '@cdktf/provider-azurerm/lib/api-management-backend/index.js'
5
- import { ApiManagementCustomDomain } from '@cdktf/provider-azurerm/lib/api-management-custom-domain/index.js'
6
1
  import {
7
- ApiManagementLogger,
8
- ApiManagementLoggerApplicationInsights,
9
- } from '@cdktf/provider-azurerm/lib/api-management-logger/index.js'
10
- import { ApiManagementRedisCache } from '@cdktf/provider-azurerm/lib/api-management-redis-cache/index.js'
11
- import { ApiManagement } from '@cdktf/provider-azurerm/lib/api-management/index.js'
12
- import {
13
- DataAzurermApiManagement,
14
- DataAzurermApiManagementConfig,
15
- } from '@cdktf/provider-azurerm/lib/data-azurerm-api-management/index.js'
16
- import { DataAzurermResourceGroup } from '@cdktf/provider-azurerm/lib/data-azurerm-resource-group/index.js'
17
- import { ManagedRedis } from '@cdktf/provider-azurerm/lib/managed-redis/index.js'
2
+ Api,
3
+ ApiManagementService,
4
+ ApiOperation,
5
+ ApiOperationPolicy,
6
+ Backend,
7
+ BackendProtocol,
8
+ Cache,
9
+ getApiManagementServiceOutput,
10
+ Logger,
11
+ LoggerType,
12
+ PolicyContentFormat,
13
+ Protocol,
14
+ } from '@pulumi/azure-native/apimanagement/index.js'
15
+ import * as redis from '@pulumi/azure-native/redis/index.js'
18
16
  import _ from 'lodash'
19
17
  import { CommonAzureConstruct } from '../../common/index.js'
20
- import { createAzureTfOutput } from '../../utils/index.js'
21
18
  import {
22
19
  ApiManagementApiProps,
23
20
  ApiManagementBackendProps,
24
21
  ApiManagementCustomDomainProps,
25
22
  ApiManagementProps,
23
+ ResolveApiManagementProps,
26
24
  } from './types.js'
27
25
 
28
26
  /**
29
- * @classdesc Provides operations on Azure Api Management
27
+ * @classdesc Provides operations on Azure API Management using Pulumi
30
28
  * - A new instance of this class is injected into {@link CommonAzureConstruct} constructor.
31
29
  * - If a custom construct extends {@link CommonAzureConstruct}, an instance is available within the context.
32
30
  * @example
33
- * ```
31
+ * ```typescript
34
32
  * import { CommonAzureConstruct, CommonAzureStackProps } from '@gradientedge/cdk-utils'
35
33
  *
36
34
  * class CustomConstruct extends CommonAzureConstruct {
37
- * constructor(parent: Construct, id: string, props: CommonAzureStackProps) {
38
- * super(parent, id, props)
35
+ * constructor(name: string, props: CommonAzureStackProps) {
36
+ * super(name, props)
39
37
  * this.props = props
40
38
  * this.apiManagementManager.createApiManagement('MyApiManagement', this, props)
41
39
  * }
@@ -44,168 +42,185 @@ import {
44
42
  */
45
43
  export class AzureApiManagementManager {
46
44
  /**
47
- * @summary Method to create a new api management
45
+ * @summary Method to create a new API Management service
48
46
  * @param id scoped id of the resource
49
47
  * @param scope scope in which this resource is defined
50
- * @param props api management properties
51
- * @see [CDKTF Api management Module]{@link https://github.com/cdktf/cdktf-provider-azurerm/blob/main/docs/apiManagement.typescript.md}
48
+ * @param props API Management properties
49
+ * @param applicationInsightsKey Optional Application Insights instrumentation key for logging
50
+ * @param externalRedisCache Optional external Redis cache for API Management caching
51
+ * @see [Pulumi Azure Native API Management]{@link https://www.pulumi.com/registry/packages/azure-native/api-docs/apimanagement/apimanagementservice/}
52
52
  */
53
- public createApiManagement(
53
+ public createApiManagementService(
54
54
  id: string,
55
55
  scope: CommonAzureConstruct,
56
56
  props: ApiManagementProps,
57
- applicationInsightsKey?: ApiManagementLoggerApplicationInsights['instrumentationKey'],
58
- externalRedisCache?: ManagedRedis
57
+ applicationInsightsKey?: string,
58
+ externalRedisCache?: redis.Redis
59
59
  ) {
60
60
  if (!props) throw `Props undefined for ${id}`
61
61
 
62
- const resourceGroup = new DataAzurermResourceGroup(scope, `${id}-am-rg`, {
63
- name: scope.props.resourceGroupName
64
- ? scope.resourceNameFormatter.format(scope.props.resourceGroupName)
65
- : `${props.resourceGroupName}`,
66
- })
67
-
68
- if (!resourceGroup) throw `Resource group undefined for ${id}`
69
-
70
- const apiManagement = new ApiManagement(scope, `${id}-am`, {
71
- ...props,
72
- name: scope.resourceNameFormatter.format(props.name, scope.props.resourceNameOptions?.apiManagement),
73
- resourceGroupName: resourceGroup.name,
74
- tags: props.tags ?? {
75
- environment: scope.props.stage,
62
+ // Get resource group name
63
+ const resourceGroupName = scope.props.resourceGroupName
64
+ ? scope.resourceNameFormatter.format(scope.props.resourceGroupName)
65
+ : props.resourceGroupName
66
+
67
+ if (!resourceGroupName) throw `Resource group name undefined for ${id}`
68
+
69
+ const apiManagementService = new ApiManagementService(
70
+ `${id}-am`,
71
+ {
72
+ ...props,
73
+ serviceName: scope.resourceNameFormatter.format(
74
+ props.serviceName?.toString(),
75
+ scope.props.resourceNameOptions?.apiManagement
76
+ ),
77
+ resourceGroupName: resourceGroupName,
78
+ location: props.location ?? scope.props.location,
79
+ publisherEmail: props.publisherEmail ?? 'noreply@example.com',
80
+ publisherName: props.publisherName ?? 'Default Publisher',
81
+ tags: props.tags ?? {
82
+ environment: scope.props.stage,
83
+ },
76
84
  },
77
- })
85
+ { parent: scope }
86
+ )
78
87
 
88
+ // Create logger if Application Insights key is provided
79
89
  if (applicationInsightsKey) {
80
- new ApiManagementLogger(scope, `${id}-am-logger`, {
81
- name: scope.resourceNameFormatter.format(props.name, scope.props.resourceNameOptions?.apiManagementLogger),
82
- resourceGroupName: resourceGroup.name,
83
- apiManagementName: apiManagement.name,
84
- applicationInsights: {
85
- instrumentationKey: applicationInsightsKey,
90
+ new Logger(
91
+ `${id}-am-logger`,
92
+ {
93
+ loggerId: scope.resourceNameFormatter.format(
94
+ props.serviceName?.toString(),
95
+ scope.props.resourceNameOptions?.apiManagementLogger
96
+ ),
97
+ resourceGroupName: resourceGroupName,
98
+ serviceName: apiManagementService.name,
99
+ loggerType: LoggerType.ApplicationInsights,
100
+ credentials: {
101
+ instrumentationKey: applicationInsightsKey,
102
+ },
86
103
  },
87
- })
104
+ { parent: scope }
105
+ )
88
106
  }
89
107
 
108
+ // Create Redis cache connection if external Redis is provided
90
109
  if (externalRedisCache) {
91
- new ApiManagementRedisCache(scope, `${id}-am-redis-cache`, {
92
- name: scope.resourceNameFormatter.format(props.name, scope.props.resourceNameOptions?.apiManagementRedisCache),
93
- apiManagementId: apiManagement.id,
94
- connectionString: `${externalRedisCache.name}:10000,password=${externalRedisCache.defaultDatabase.primaryAccessKey},ssl=True,abortConnect=False`,
95
- cacheLocation: externalRedisCache.location,
96
- redisCacheId: externalRedisCache.id,
97
- })
110
+ new Cache(
111
+ `${id}-am-redis-cache`,
112
+ {
113
+ cacheId: scope.resourceNameFormatter.format(
114
+ props.serviceName?.toString(),
115
+ scope.props.resourceNameOptions?.apiManagementRedisCache
116
+ ),
117
+ serviceName: apiManagementService.name,
118
+ resourceGroupName: resourceGroupName,
119
+ connectionString: externalRedisCache.hostName.apply(
120
+ hostName =>
121
+ `${hostName}:10000,password=${externalRedisCache.accessKeys.apply(k => k?.primaryKey)},ssl=True,abortConnect=False`
122
+ ),
123
+ useFromLocation: externalRedisCache.location,
124
+ resourceId: externalRedisCache.id,
125
+ },
126
+ { parent: scope }
127
+ )
98
128
  }
99
129
 
100
- createAzureTfOutput(`${id}-apiManagementName`, scope, apiManagement.name)
101
- createAzureTfOutput(`${id}-apiManagementFriendlyUniqueId`, scope, apiManagement.friendlyUniqueId)
102
- createAzureTfOutput(`${id}-apiManagementId`, scope, apiManagement.id)
103
-
104
- return apiManagement
130
+ return apiManagementService
105
131
  }
106
132
 
107
133
  /**
108
- * @summary Method to resolve an api management
134
+ * @summary Method to resolve an existing API Management service
109
135
  * @param id scoped id of the resource
110
136
  * @param scope scope in which this resource is defined
111
- * @param props api management properties
112
- * @see [CDKTF Api management Module]{@link https://github.com/cdktf/cdktf-provider-azurerm/blob/main/docs/apiManagement.typescript.md}
137
+ * @param props API Management lookup properties
138
+ * @see [Pulumi Azure Native API Management Lookup]{@link https://www.pulumi.com/registry/packages/azure-native/api-docs/apimanagement/apimanagementservice/}
113
139
  */
114
- public resolveApiManagement(id: string, scope: CommonAzureConstruct, props: DataAzurermApiManagementConfig) {
140
+ public resolveApiManagementService(id: string, scope: CommonAzureConstruct, props: ResolveApiManagementProps) {
115
141
  if (!props) throw `Props undefined for ${id}`
116
142
 
117
- const resourceGroup = new DataAzurermResourceGroup(scope, `${id}-am-rg`, {
118
- name: scope.props.resourceGroupName
119
- ? scope.resourceNameFormatter.format(scope.props.resourceGroupName)
120
- : `${props.resourceGroupName}`,
121
- })
122
-
123
- if (!resourceGroup) throw `Resource group undefined for ${id}`
124
-
125
- const apiManagement = new DataAzurermApiManagement(scope, `${id}-am`, {
126
- ...props,
127
- name: scope.resourceNameFormatter.format(props.name, scope.props.resourceNameOptions?.dataAzurermApiManagement),
128
- resourceGroupName: scope.props.resourceGroupName
129
- ? `${scope.props.resourceGroupName}-${scope.props.stage}`
130
- : `${props.resourceGroupName}`,
131
- })
132
-
133
- return apiManagement
143
+ return getApiManagementServiceOutput(
144
+ {
145
+ serviceName: scope.resourceNameFormatter.format(
146
+ props.serviceName?.toString(),
147
+ scope.props.resourceNameOptions?.dataAzurermApiManagement
148
+ ),
149
+ resourceGroupName: scope.props.resourceGroupName
150
+ ? `${scope.props.resourceGroupName}-${scope.props.stage}`
151
+ : props.resourceGroupName,
152
+ },
153
+ { parent: scope }
154
+ )
134
155
  }
135
156
 
136
157
  /**
137
- * @summary Method to create a new api management backend
158
+ * @summary Method to create a new API Management backend
138
159
  * @param id scoped id of the resource
139
160
  * @param scope scope in which this resource is defined
140
- * @param props api management backend properties
141
- * @see [CDKTF Api management Backend Module]{@link https://github.com/cdktf/cdktf-provider-azurerm/blob/main/docs/ApiManagementBackend.typescript.md}
161
+ * @param props API Management backend properties
162
+ * @see [Pulumi Azure Native API Management Backend]{@link https://www.pulumi.com/registry/packages/azure-native/api-docs/apimanagement/backend/}
142
163
  */
143
- public createApiManagementBackend(id: string, scope: CommonAzureConstruct, props: ApiManagementBackendProps) {
164
+ public createBackend(id: string, scope: CommonAzureConstruct, props: ApiManagementBackendProps) {
144
165
  if (!props) throw `Props undefined for ${id}`
145
166
 
146
- const apiManagementBackend = new ApiManagementBackend(scope, `${id}-am-be`, {
147
- ...props,
148
- name: scope.resourceNameFormatter.format(props.name, scope.props.resourceNameOptions?.apiManagementBackend),
149
- description: props.description ?? `Backend for ${props.name}-${scope.props.stage}`,
150
- protocol: props.protocol ?? 'http',
151
- })
152
-
153
- createAzureTfOutput(`${id}-apiManagementBackendName`, scope, apiManagementBackend.name)
154
- createAzureTfOutput(`${id}-apiManagementBackendFriendlyUniqueId`, scope, apiManagementBackend.friendlyUniqueId)
155
- createAzureTfOutput(`${id}-apiManagementBackendId`, scope, apiManagementBackend.id)
156
-
157
- return apiManagementBackend
167
+ return new Backend(
168
+ `${id}-am-be`,
169
+ {
170
+ ...props,
171
+ backendId: scope.resourceNameFormatter.format(
172
+ props.backendId?.toString(),
173
+ scope.props.resourceNameOptions?.apiManagementBackend
174
+ ),
175
+ description: props.description ?? `Backend for ${(props as any).name || id}-${scope.props.stage}`,
176
+ protocol: props.protocol ?? BackendProtocol.Http,
177
+ },
178
+ { parent: scope }
179
+ )
158
180
  }
159
181
 
160
182
  /**
161
- * @summary Method to create a new api management api
183
+ * @summary Method to create a new API Management API with operations and policies
162
184
  * @param id scoped id of the resource
163
185
  * @param scope scope in which this resource is defined
164
- * @param props api management api properties
165
- * @see [CDKTF Api management Api Module]{@link https://github.com/cdktf/cdktf-provider-azurerm/blob/main/docs/ApiManagementApi.typescript.md}
186
+ * @param props API Management API properties
187
+ * @see [Pulumi Azure Native API Management API]{@link https://www.pulumi.com/registry/packages/azure-native/api-docs/apimanagement/api/}
166
188
  */
167
- public createApiManagementApi(id: string, scope: CommonAzureConstruct, props: ApiManagementApiProps) {
189
+ public createApi(id: string, scope: CommonAzureConstruct, props: ApiManagementApiProps) {
168
190
  if (!props) throw `Props undefined for ${id}`
169
191
 
170
- const apiManagementApi = new ApiManagementApi(scope, `${id}-am-api`, {
171
- ...props,
172
- name: scope.resourceNameFormatter.format(props.name, scope.props.resourceNameOptions?.apiManagementApi),
173
- displayName: props.displayName ?? props.name,
174
- revision: props.revision ?? '1',
175
- protocols: props.protocols ?? ['https'],
176
- })
177
-
178
- createAzureTfOutput(`${id}-apiManagementApiName`, scope, apiManagementApi.name)
179
- createAzureTfOutput(`${id}-apiManagementApiFriendlyUniqueId`, scope, apiManagementApi.friendlyUniqueId)
180
- createAzureTfOutput(`${id}-apiManagementApiId`, scope, apiManagementApi.id)
192
+ const api = new Api(
193
+ `${id}-am-api`,
194
+ {
195
+ ...props,
196
+ apiId: scope.resourceNameFormatter.format(
197
+ props.apiId?.toString(),
198
+ scope.props.resourceNameOptions?.apiManagementApi
199
+ ),
200
+ displayName: props.displayName ?? props.apiId,
201
+ apiRevision: props.apiRevision ?? '1',
202
+ protocols: props.protocols ?? [Protocol.Https],
203
+ },
204
+ { parent: scope }
205
+ )
181
206
 
207
+ // Create operations and policies
182
208
  _.forEach(props.operations, operation => {
183
- const apimOperation = new ApiManagementApiOperation(
184
- scope,
209
+ const operationId = `${operation.displayName}-${operation.method}`
210
+ const apimOperation = new ApiOperation(
185
211
  `${id}-apim-api-operation-${operation.displayName}-${operation.method}`,
186
212
  {
187
- operationId: `${operation.displayName}-${operation.method}`,
188
- method: operation.method.toUpperCase(),
189
- apiManagementName: apiManagementApi.apiManagementName,
190
- resourceGroupName: apiManagementApi.resourceGroupName,
191
- apiName: apiManagementApi.name,
213
+ operationId: operationId,
214
+ method: (operation.method as string)?.toUpperCase() || 'GET',
215
+ serviceName: props.serviceName!,
216
+ resourceGroupName: props.resourceGroupName!,
217
+ apiId: api.name,
192
218
  displayName: operation.displayName,
193
219
  urlTemplate: operation.urlTemplate,
194
- templateParameter: operation.templateParameter,
195
- }
196
- )
197
-
198
- createAzureTfOutput(
199
- `${id}-${operation.displayName}-${operation.method}-apimOperationOperationId`,
200
- scope,
201
- apimOperation.operationId
202
- )
203
- createAzureTfOutput(
204
- `${id}-${operation.displayName}-${operation.method}-apimOperationFriendlyUniqueId`,
205
- scope,
206
- apimOperation.friendlyUniqueId
220
+ templateParameters: operation.templateParameters,
221
+ },
222
+ { parent: scope }
207
223
  )
208
- createAzureTfOutput(`${id}-${operation.displayName}-${operation.method}-apimOperationId`, scope, apimOperation.id)
209
224
 
210
225
  // Define Caching Policy if enabled
211
226
  let cacheSetVariablePolicy = ''
@@ -217,11 +232,11 @@ export class AzureApiManagementManager {
217
232
  cacheSetVariablePolicy = `<!-- Generate a comprehensive custom cache key (without query params or Accept header) -->
218
233
  <set-variable name="customCacheKey" value="@{
219
234
  // Instance identification
220
-
235
+
221
236
  // API identification
222
237
  string apiName = context.Api.Name.Replace(" ", "").ToLower();
223
238
  string apiVersion = context.Api.Version ?? "v1";
224
-
239
+
225
240
  // Full path construction (without query parameters)
226
241
  string fullPath = context.Request.Url.Path.ToLower();
227
242
 
@@ -299,7 +314,7 @@ export class AzureApiManagementManager {
299
314
  // Inject rate limiting policy (if configured)
300
315
  let rateLimitPolicy = ''
301
316
  if (props.rateLimit && scope.props.subscriptionId) {
302
- rateLimitPolicy = `<rate-limit-by-key calls="${props.rateLimit.calls}" renewal-period="${props.rateLimit.renewalPeriodInSecs}" counter-key="${scope.props.subscriptionId}-${apimOperation.operationId}"/>`
317
+ rateLimitPolicy = `<rate-limit-by-key calls="${props.rateLimit.calls}" renewal-period="${props.rateLimit.renewalPeriodInSecs}" counter-key="${scope.props.subscriptionId}-${operationId}"/>`
303
318
  }
304
319
 
305
320
  const policyXmlContent = `<policies>
@@ -324,39 +339,31 @@ export class AzureApiManagementManager {
324
339
  </on-error>
325
340
  </policies>`
326
341
 
327
- const apimOperationPolicy = new ApiManagementApiOperationPolicy(
328
- scope,
342
+ new ApiOperationPolicy(
329
343
  `${id}-apim-api-operation-policy-${operation.displayName}-${operation.method}`,
330
344
  {
331
- apiManagementName: apiManagementApi.apiManagementName,
332
- resourceGroupName: apiManagementApi.resourceGroupName,
333
- apiName: apiManagementApi.name,
334
- operationId: apimOperation.operationId,
335
- xmlContent: policyXmlContent,
336
- }
337
- )
338
-
339
- createAzureTfOutput(
340
- `${id}-${operation.displayName}-${operation.method}-apimOperationPolicyFriendlyUniqueId`,
341
- scope,
342
- apimOperationPolicy.friendlyUniqueId
343
- )
344
- createAzureTfOutput(
345
- `${id}-${operation.displayName}-${operation.method}-apimOperationPolicyId`,
346
- scope,
347
- apimOperationPolicy.id
345
+ serviceName: props.serviceName!,
346
+ resourceGroupName: props.resourceGroupName!,
347
+ apiId: api.name,
348
+ operationId: operationId,
349
+ policyId: 'policy',
350
+ value: policyXmlContent,
351
+ format: PolicyContentFormat.Xml,
352
+ },
353
+ { parent: scope }
348
354
  )
349
355
  })
350
356
 
351
- return apiManagementApi
357
+ return api
352
358
  }
353
359
 
354
360
  /**
355
- * @summary Method to create a new api management custom domain
361
+ * @summary Method to create a new API Management custom domain
356
362
  * @param id scoped id of the resource
357
363
  * @param scope scope in which this resource is defined
358
- * @param props api management custom domain properties
359
- * @see [CDKTF Api management Custom Domain Module]{@link https://github.com/cdktf/cdktf-provider-azurerm/blob/main/docs/createApiManagementCustomDomain.typescript.md}
364
+ * @param props API Management custom domain properties
365
+ * @note In Pulumi Azure Native, custom domains are configured as part of the API Management service resource,
366
+ * not as a separate resource. Use the hostnameConfigurations property when creating the service.
360
367
  */
361
368
  public createApiManagementCustomDomain(
362
369
  id: string,
@@ -365,15 +372,11 @@ export class AzureApiManagementManager {
365
372
  ) {
366
373
  if (!props) throw `Props undefined for ${id}`
367
374
 
368
- const apiManagementCustomDomain = new ApiManagementCustomDomain(scope, `${id}-am-cd`, props)
369
-
370
- createAzureTfOutput(
371
- `${id}-apiManagementCustomDomainFriendlyUniqueId`,
372
- scope,
373
- apiManagementCustomDomain.friendlyUniqueId
375
+ // Note: In Pulumi Azure Native, custom domains are part of the ApiManagementService
376
+ // This method is provided for API compatibility but should be configured
377
+ // via the hostnameConfigurations property of ApiManagementService instead
378
+ throw new Error(
379
+ 'Custom domains should be configured via the hostnameConfigurations property of ApiManagementService in Pulumi Azure Native'
374
380
  )
375
- createAzureTfOutput(`${id}-apiManagementCustomDomainId`, scope, apiManagementCustomDomain.id)
376
-
377
- return apiManagementCustomDomain
378
381
  }
379
382
  }