@gradientedge/cdk-utils 9.34.0 → 9.36.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.
- package/dist/src/lib/azure/common/construct.d.ts +2 -1
- package/dist/src/lib/azure/common/construct.js +2 -0
- package/dist/src/lib/azure/services/api-management/main.d.ts +30 -2
- package/dist/src/lib/azure/services/api-management/main.js +115 -1
- package/dist/src/lib/azure/services/api-management/types.d.ts +14 -0
- package/dist/src/lib/azure/services/cosmosdb/index.d.ts +2 -0
- package/dist/src/lib/azure/services/cosmosdb/index.js +18 -0
- package/dist/src/lib/azure/services/cosmosdb/main.d.ts +48 -0
- package/dist/src/lib/azure/services/cosmosdb/main.js +113 -0
- package/dist/src/lib/azure/services/cosmosdb/types.d.ts +12 -0
- package/dist/src/lib/azure/services/cosmosdb/types.js +2 -0
- package/dist/src/lib/azure/services/index.d.ts +1 -0
- package/dist/src/lib/azure/services/index.js +1 -0
- package/package.json +1 -1
- package/src/lib/azure/common/construct.ts +3 -0
- package/src/lib/azure/services/api-management/main.ts +162 -2
- package/src/lib/azure/services/api-management/types.ts +16 -0
- package/src/lib/azure/services/cosmosdb/index.ts +2 -0
- package/src/lib/azure/services/cosmosdb/main.ts +124 -0
- package/src/lib/azure/services/cosmosdb/types.ts +9 -0
- package/src/lib/azure/services/index.ts +1 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { TerraformStack } from 'cdktf';
|
|
2
2
|
import { Construct } from 'constructs';
|
|
3
|
-
import { AzureStorageManager, AzureKeyVaultManager, AzureApiManagementManager, AzureFunctionManager, AzureResourceGroupManager, AzureAppServiceManager, AzureApplicationInsightsManager, AzureAppConfigurationManager } from '../services';
|
|
3
|
+
import { AzureStorageManager, AzureKeyVaultManager, AzureApiManagementManager, AzureFunctionManager, AzureResourceGroupManager, AzureAppServiceManager, AzureApplicationInsightsManager, AzureAppConfigurationManager, AzureCosmosDbManager } from '../services';
|
|
4
4
|
import { CommonAzureStackProps } from './types';
|
|
5
5
|
export declare class CommonAzureConstruct extends TerraformStack {
|
|
6
6
|
props: CommonAzureStackProps;
|
|
@@ -11,6 +11,7 @@ export declare class CommonAzureConstruct extends TerraformStack {
|
|
|
11
11
|
appServiceManager: AzureAppServiceManager;
|
|
12
12
|
applicationInsightsManager: AzureApplicationInsightsManager;
|
|
13
13
|
appConfigurationManager: AzureAppConfigurationManager;
|
|
14
|
+
cosmosDbManager: AzureCosmosDbManager;
|
|
14
15
|
functiontManager: AzureFunctionManager;
|
|
15
16
|
keyVaultManager: AzureKeyVaultManager;
|
|
16
17
|
resourceGroupManager: AzureResourceGroupManager;
|
|
@@ -15,6 +15,7 @@ class CommonAzureConstruct extends cdktf_1.TerraformStack {
|
|
|
15
15
|
appServiceManager;
|
|
16
16
|
applicationInsightsManager;
|
|
17
17
|
appConfigurationManager;
|
|
18
|
+
cosmosDbManager;
|
|
18
19
|
functiontManager;
|
|
19
20
|
keyVaultManager;
|
|
20
21
|
resourceGroupManager;
|
|
@@ -27,6 +28,7 @@ class CommonAzureConstruct extends cdktf_1.TerraformStack {
|
|
|
27
28
|
this.appServiceManager = new services_1.AzureAppServiceManager();
|
|
28
29
|
this.applicationInsightsManager = new services_1.AzureApplicationInsightsManager();
|
|
29
30
|
this.appConfigurationManager = new services_1.AzureAppConfigurationManager();
|
|
31
|
+
this.cosmosDbManager = new services_1.AzureCosmosDbManager();
|
|
30
32
|
this.functiontManager = new services_1.AzureFunctionManager();
|
|
31
33
|
this.keyVaultManager = new services_1.AzureKeyVaultManager();
|
|
32
34
|
this.resourceGroupManager = new services_1.AzureResourceGroupManager();
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
import { DataAzurermApiManagement, DataAzurermApiManagementConfig } from '@cdktf/provider-azurerm/lib/data-azurerm-api-management';
|
|
2
|
+
import { ApiManagementBackend } from '@cdktf/provider-azurerm/lib/api-management-backend';
|
|
1
3
|
import { ApiManagement } from '@cdktf/provider-azurerm/lib/api-management';
|
|
4
|
+
import { ApiManagementApi } from '@cdktf/provider-azurerm/lib/api-management-api';
|
|
5
|
+
import { ApiManagementLoggerApplicationInsights } from '@cdktf/provider-azurerm/lib/api-management-logger';
|
|
2
6
|
import { CommonAzureConstruct } from '../../common';
|
|
3
|
-
import { ApiManagementProps } from './types';
|
|
7
|
+
import { ApiManagementProps, ApiManagementBackendProps, ApiManagementApiProps } from './types';
|
|
4
8
|
/**
|
|
5
9
|
* @classdesc Provides operations on Azure Api Management
|
|
6
10
|
* - A new instance of this class is injected into {@link CommonAzureConstruct} constructor.
|
|
@@ -26,5 +30,29 @@ export declare class AzureApiManagementManager {
|
|
|
26
30
|
* @param props api management properties
|
|
27
31
|
* @see [CDKTF Api management Module]{@link https://github.com/cdktf/cdktf-provider-azurerm/blob/main/docs/apiManagement.typescript.md}
|
|
28
32
|
*/
|
|
29
|
-
createApiManagement(id: string, scope: CommonAzureConstruct, props: ApiManagementProps): ApiManagement;
|
|
33
|
+
createApiManagement(id: string, scope: CommonAzureConstruct, props: ApiManagementProps, applicationInsightsKey?: ApiManagementLoggerApplicationInsights['instrumentationKey']): ApiManagement;
|
|
34
|
+
/**
|
|
35
|
+
* @summary Method to resolve an api management
|
|
36
|
+
* @param id scoped id of the resource
|
|
37
|
+
* @param scope scope in which this resource is defined
|
|
38
|
+
* @param props api management properties
|
|
39
|
+
* @see [CDKTF Api management Module]{@link https://github.com/cdktf/cdktf-provider-azurerm/blob/main/docs/apiManagement.typescript.md}
|
|
40
|
+
*/
|
|
41
|
+
resolveApiManagement(id: string, scope: CommonAzureConstruct, props: DataAzurermApiManagementConfig): DataAzurermApiManagement;
|
|
42
|
+
/**
|
|
43
|
+
* @summary Method to create a new api management backend
|
|
44
|
+
* @param id scoped id of the resource
|
|
45
|
+
* @param scope scope in which this resource is defined
|
|
46
|
+
* @param props api management backend properties
|
|
47
|
+
* @see [CDKTF Api management Backend Module]{@link https://github.com/cdktf/cdktf-provider-azurerm/blob/main/docs/ApiManagementBackend.typescript.md}
|
|
48
|
+
*/
|
|
49
|
+
createApiManagementBackend(id: string, scope: CommonAzureConstruct, props: ApiManagementBackendProps): ApiManagementBackend;
|
|
50
|
+
/**
|
|
51
|
+
* @summary Method to create a new api management api
|
|
52
|
+
* @param id scoped id of the resource
|
|
53
|
+
* @param scope scope in which this resource is defined
|
|
54
|
+
* @param props api management api properties
|
|
55
|
+
* @see [CDKTF Api management Api Module]{@link https://github.com/cdktf/cdktf-provider-azurerm/blob/main/docs/ApiManagementApi.typescript.md}
|
|
56
|
+
*/
|
|
57
|
+
createApiManagementApi(id: string, scope: CommonAzureConstruct, props: ApiManagementApiProps): ApiManagementApi;
|
|
30
58
|
}
|
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.AzureApiManagementManager = void 0;
|
|
4
7
|
const data_azurerm_resource_group_1 = require("@cdktf/provider-azurerm/lib/data-azurerm-resource-group");
|
|
8
|
+
const data_azurerm_api_management_1 = require("@cdktf/provider-azurerm/lib/data-azurerm-api-management");
|
|
9
|
+
const api_management_backend_1 = require("@cdktf/provider-azurerm/lib/api-management-backend");
|
|
5
10
|
const api_management_1 = require("@cdktf/provider-azurerm/lib/api-management");
|
|
11
|
+
const api_management_api_1 = require("@cdktf/provider-azurerm/lib/api-management-api");
|
|
12
|
+
const api_management_api_operation_1 = require("@cdktf/provider-azurerm/lib/api-management-api-operation");
|
|
13
|
+
const api_management_api_operation_policy_1 = require("@cdktf/provider-azurerm/lib/api-management-api-operation-policy");
|
|
14
|
+
const api_management_logger_1 = require("@cdktf/provider-azurerm/lib/api-management-logger");
|
|
6
15
|
const utils_1 = require("../../utils");
|
|
16
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
7
17
|
/**
|
|
8
18
|
* @classdesc Provides operations on Azure Api Management
|
|
9
19
|
* - A new instance of this class is injected into {@link CommonAzureConstruct} constructor.
|
|
@@ -29,7 +39,7 @@ class AzureApiManagementManager {
|
|
|
29
39
|
* @param props api management properties
|
|
30
40
|
* @see [CDKTF Api management Module]{@link https://github.com/cdktf/cdktf-provider-azurerm/blob/main/docs/apiManagement.typescript.md}
|
|
31
41
|
*/
|
|
32
|
-
createApiManagement(id, scope, props) {
|
|
42
|
+
createApiManagement(id, scope, props, applicationInsightsKey) {
|
|
33
43
|
if (!props)
|
|
34
44
|
throw `Props undefined for ${id}`;
|
|
35
45
|
const resourceGroup = new data_azurerm_resource_group_1.DataAzurermResourceGroup(scope, `${id}-am-rg`, {
|
|
@@ -47,10 +57,114 @@ class AzureApiManagementManager {
|
|
|
47
57
|
environment: scope.props.stage,
|
|
48
58
|
},
|
|
49
59
|
});
|
|
60
|
+
if (applicationInsightsKey) {
|
|
61
|
+
new api_management_logger_1.ApiManagementLogger(scope, `${id}-am-logger`, {
|
|
62
|
+
name: `${props.name}-${scope.props.stage}`,
|
|
63
|
+
resourceGroupName: resourceGroup.name,
|
|
64
|
+
apiManagementName: apiManagement.name,
|
|
65
|
+
applicationInsights: {
|
|
66
|
+
instrumentationKey: applicationInsightsKey,
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
}
|
|
50
70
|
(0, utils_1.createAzureTfOutput)(`${id}-apiManagementName`, scope, apiManagement.name);
|
|
51
71
|
(0, utils_1.createAzureTfOutput)(`${id}-apiManagementFriendlyUniqueId`, scope, apiManagement.friendlyUniqueId);
|
|
52
72
|
(0, utils_1.createAzureTfOutput)(`${id}-apiManagementId`, scope, apiManagement.id);
|
|
53
73
|
return apiManagement;
|
|
54
74
|
}
|
|
75
|
+
/**
|
|
76
|
+
* @summary Method to resolve an api management
|
|
77
|
+
* @param id scoped id of the resource
|
|
78
|
+
* @param scope scope in which this resource is defined
|
|
79
|
+
* @param props api management properties
|
|
80
|
+
* @see [CDKTF Api management Module]{@link https://github.com/cdktf/cdktf-provider-azurerm/blob/main/docs/apiManagement.typescript.md}
|
|
81
|
+
*/
|
|
82
|
+
resolveApiManagement(id, scope, props) {
|
|
83
|
+
if (!props)
|
|
84
|
+
throw `Props undefined for ${id}`;
|
|
85
|
+
const resourceGroup = new data_azurerm_resource_group_1.DataAzurermResourceGroup(scope, `${id}-am-rg`, {
|
|
86
|
+
name: scope.props.resourceGroupName
|
|
87
|
+
? `${scope.props.resourceGroupName}-${scope.props.stage}`
|
|
88
|
+
: `${props.resourceGroupName}`,
|
|
89
|
+
});
|
|
90
|
+
if (!resourceGroup)
|
|
91
|
+
throw `Resource group undefined for ${id}`;
|
|
92
|
+
const apiManagement = new data_azurerm_api_management_1.DataAzurermApiManagement(scope, `${id}-am`, {
|
|
93
|
+
...props,
|
|
94
|
+
name: `${props.name}-${scope.props.stage}`,
|
|
95
|
+
resourceGroupName: scope.props.resourceGroupName
|
|
96
|
+
? `${scope.props.resourceGroupName}-${scope.props.stage}`
|
|
97
|
+
: `${props.resourceGroupName}`,
|
|
98
|
+
});
|
|
99
|
+
return apiManagement;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* @summary Method to create a new api management backend
|
|
103
|
+
* @param id scoped id of the resource
|
|
104
|
+
* @param scope scope in which this resource is defined
|
|
105
|
+
* @param props api management backend properties
|
|
106
|
+
* @see [CDKTF Api management Backend Module]{@link https://github.com/cdktf/cdktf-provider-azurerm/blob/main/docs/ApiManagementBackend.typescript.md}
|
|
107
|
+
*/
|
|
108
|
+
createApiManagementBackend(id, scope, props) {
|
|
109
|
+
if (!props)
|
|
110
|
+
throw `Props undefined for ${id}`;
|
|
111
|
+
const apiManagementBackend = new api_management_backend_1.ApiManagementBackend(scope, `${id}-am-be`, {
|
|
112
|
+
...props,
|
|
113
|
+
name: `${props.name}-${scope.props.stage}`,
|
|
114
|
+
description: props.description || `Backend for ${props.name}-${scope.props.stage}`,
|
|
115
|
+
protocol: props.protocol || 'http',
|
|
116
|
+
});
|
|
117
|
+
(0, utils_1.createAzureTfOutput)(`${id}-apiManagementBackendName`, scope, apiManagementBackend.name);
|
|
118
|
+
(0, utils_1.createAzureTfOutput)(`${id}-apiManagementBackendFriendlyUniqueId`, scope, apiManagementBackend.friendlyUniqueId);
|
|
119
|
+
(0, utils_1.createAzureTfOutput)(`${id}-apiManagementBackendId`, scope, apiManagementBackend.id);
|
|
120
|
+
return apiManagementBackend;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* @summary Method to create a new api management api
|
|
124
|
+
* @param id scoped id of the resource
|
|
125
|
+
* @param scope scope in which this resource is defined
|
|
126
|
+
* @param props api management api properties
|
|
127
|
+
* @see [CDKTF Api management Api Module]{@link https://github.com/cdktf/cdktf-provider-azurerm/blob/main/docs/ApiManagementApi.typescript.md}
|
|
128
|
+
*/
|
|
129
|
+
createApiManagementApi(id, scope, props) {
|
|
130
|
+
if (!props)
|
|
131
|
+
throw `Props undefined for ${id}`;
|
|
132
|
+
const apiManagementApi = new api_management_api_1.ApiManagementApi(scope, `${id}-am-api`, {
|
|
133
|
+
...props,
|
|
134
|
+
name: `${props.name}-${scope.props.stage}`,
|
|
135
|
+
displayName: props.displayName || props.name,
|
|
136
|
+
revision: props.revision || '1',
|
|
137
|
+
protocols: props.protocols || ['https'],
|
|
138
|
+
});
|
|
139
|
+
(0, utils_1.createAzureTfOutput)(`${id}-apiManagementApiName`, scope, apiManagementApi.name);
|
|
140
|
+
(0, utils_1.createAzureTfOutput)(`${id}-apiManagementApiFriendlyUniqueId`, scope, apiManagementApi.friendlyUniqueId);
|
|
141
|
+
(0, utils_1.createAzureTfOutput)(`${id}-apiManagementApiId`, scope, apiManagementApi.id);
|
|
142
|
+
lodash_1.default.forEach(props.operations, operation => {
|
|
143
|
+
const apimOperation = new api_management_api_operation_1.ApiManagementApiOperation(scope, `${id}-apim-api-operation-${operation.path}-${operation.method}`, {
|
|
144
|
+
operationId: `${operation.path}-${operation.method}`,
|
|
145
|
+
method: operation.method.toUpperCase(),
|
|
146
|
+
apiManagementName: apiManagementApi.apiManagementName,
|
|
147
|
+
resourceGroupName: apiManagementApi.resourceGroupName,
|
|
148
|
+
apiName: apiManagementApi.name,
|
|
149
|
+
displayName: `/${operation.path}`,
|
|
150
|
+
urlTemplate: `/${operation.path}`,
|
|
151
|
+
});
|
|
152
|
+
(0, utils_1.createAzureTfOutput)(`${id}-${operation.path}-${operation.method}-apimOperationOperationId`, scope, apimOperation.operationId);
|
|
153
|
+
(0, utils_1.createAzureTfOutput)(`${id}-${operation.path}-${operation.method}-apimOperationFriendlyUniqueId`, scope, apimOperation.friendlyUniqueId);
|
|
154
|
+
(0, utils_1.createAzureTfOutput)(`${id}-${operation.path}-${operation.method}-apimOperationId`, scope, apimOperation.id);
|
|
155
|
+
if (props.policyXmlContent) {
|
|
156
|
+
const apimOperationPolicy = new api_management_api_operation_policy_1.ApiManagementApiOperationPolicy(scope, `${id}-apim-api-operation-policy-${operation.path}-${operation.method}`, {
|
|
157
|
+
apiManagementName: apiManagementApi.apiManagementName,
|
|
158
|
+
resourceGroupName: apiManagementApi.resourceGroupName,
|
|
159
|
+
apiName: apiManagementApi.name,
|
|
160
|
+
operationId: apimOperation.operationId,
|
|
161
|
+
xmlContent: props.policyXmlContent,
|
|
162
|
+
});
|
|
163
|
+
(0, utils_1.createAzureTfOutput)(`${id}-${operation.path}-${operation.method}-apimOperationPolicyFriendlyUniqueId`, scope, apimOperationPolicy.friendlyUniqueId);
|
|
164
|
+
(0, utils_1.createAzureTfOutput)(`${id}-${operation.path}-${operation.method}-apimOperationPolicyId`, scope, apimOperationPolicy.id);
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
return apiManagementApi;
|
|
168
|
+
}
|
|
55
169
|
}
|
|
56
170
|
exports.AzureApiManagementManager = AzureApiManagementManager;
|
|
@@ -1,3 +1,17 @@
|
|
|
1
1
|
import { ApiManagementConfig } from '@cdktf/provider-azurerm/lib/api-management';
|
|
2
|
+
import { ApiManagementBackendConfig } from '@cdktf/provider-azurerm/lib/api-management-backend';
|
|
3
|
+
import { ApiManagementApiConfig } from '@cdktf/provider-azurerm/lib/api-management-api';
|
|
4
|
+
import { ApiManagementApiOperationConfig } from '@cdktf/provider-azurerm/lib/api-management-api-operation';
|
|
5
|
+
import { ApiManagementApiOperationPolicyConfig } from '@cdktf/provider-azurerm/lib/api-management-api-operation-policy';
|
|
2
6
|
export interface ApiManagementProps extends ApiManagementConfig {
|
|
3
7
|
}
|
|
8
|
+
export interface ApiManagementBackendProps extends ApiManagementBackendConfig {
|
|
9
|
+
}
|
|
10
|
+
export interface ApiManagementApiProps extends ApiManagementApiConfig {
|
|
11
|
+
operations: OperationsProps[];
|
|
12
|
+
policyXmlContent?: ApiManagementApiOperationPolicyConfig['xmlContent'];
|
|
13
|
+
}
|
|
14
|
+
export interface OperationsProps {
|
|
15
|
+
path: ApiManagementApiOperationConfig['urlTemplate'];
|
|
16
|
+
method: ApiManagementApiOperationConfig['method'];
|
|
17
|
+
}
|
|
@@ -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,48 @@
|
|
|
1
|
+
import { CosmosdbAccount } from '@cdktf/provider-azurerm/lib/cosmosdb-account';
|
|
2
|
+
import { CosmosdbSqlDatabase } from '@cdktf/provider-azurerm/lib/cosmosdb-sql-database';
|
|
3
|
+
import { CosmosdbSqlContainer } from '@cdktf/provider-azurerm/lib/cosmosdb-sql-container';
|
|
4
|
+
import { CommonAzureConstruct } from '../../common';
|
|
5
|
+
import { CosmosdbAccountProps, CosmosdbSqlContainerProps, CosmosdbSqlDatabaseProps } from './types';
|
|
6
|
+
/**
|
|
7
|
+
* @classdesc Provides operations on Azure CosmosDB
|
|
8
|
+
* - A new instance of this class is injected into {@link CommonAzureConstruct} constructor.
|
|
9
|
+
* - If a custom construct extends {@link CommonAzureConstruct}, an instance is available within the context.
|
|
10
|
+
* @example
|
|
11
|
+
* ```
|
|
12
|
+
* import { CommonAzureConstruct, CommonAzureStackProps } from '@gradientedge/cdk-utils'
|
|
13
|
+
*
|
|
14
|
+
* class CustomConstruct extends CommonAzureConstruct {
|
|
15
|
+
* constructor(parent: Construct, id: string, props: CommonAzureStackProps) {
|
|
16
|
+
* super(parent, id, props)
|
|
17
|
+
* this.props = props
|
|
18
|
+
* this.CosmosDbManager.createCosmosAccount('MyCosmosDb', this, props)
|
|
19
|
+
* }
|
|
20
|
+
* }
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare class AzureCosmosDbManager {
|
|
24
|
+
/**
|
|
25
|
+
* @summary Method to create a new cosmosdb account
|
|
26
|
+
* @param id scoped id of the resource
|
|
27
|
+
* @param scope scope in which this resource is defined
|
|
28
|
+
* @param props cosmosdb account properties
|
|
29
|
+
* @see [CDKTF CosmosDb Account Module]{@link https://github.com/cdktf/cdktf-provider-azurerm/blob/main/docs/cosmosdbAccount.typescript.md}
|
|
30
|
+
*/
|
|
31
|
+
createCosmosDbAccount(id: string, scope: CommonAzureConstruct, props: CosmosdbAccountProps): CosmosdbAccount;
|
|
32
|
+
/**
|
|
33
|
+
* @summary Method to create a new cosmosdb database
|
|
34
|
+
* @param id scoped id of the resource
|
|
35
|
+
* @param scope scope in which this resource is defined
|
|
36
|
+
* @param props cosmosdb container properties
|
|
37
|
+
* @see [CDKTF CosmosDb Container Module]{@link https://github.com/cdktf/cdktf-provider-azurerm/blob/main/docs/cosmosdbSqlContainer.typescript.md}
|
|
38
|
+
*/
|
|
39
|
+
createCosmosDbDatabase(id: string, scope: CommonAzureConstruct, props: CosmosdbSqlDatabaseProps): CosmosdbSqlDatabase;
|
|
40
|
+
/**
|
|
41
|
+
* @summary Method to create a new cosmosdb container
|
|
42
|
+
* @param id scoped id of the resource
|
|
43
|
+
* @param scope scope in which this resource is defined
|
|
44
|
+
* @param props cosmosdb container properties
|
|
45
|
+
* @see [CDKTF CosmosDb Container Module]{@link https://github.com/cdktf/cdktf-provider-azurerm/blob/main/docs/cosmosdbSqlContainer.typescript.md}
|
|
46
|
+
*/
|
|
47
|
+
createCosmosDbContainer(id: string, scope: CommonAzureConstruct, props: CosmosdbSqlContainerProps): CosmosdbSqlContainer;
|
|
48
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AzureCosmosDbManager = void 0;
|
|
4
|
+
const data_azurerm_resource_group_1 = require("@cdktf/provider-azurerm/lib/data-azurerm-resource-group");
|
|
5
|
+
const cosmosdb_account_1 = require("@cdktf/provider-azurerm/lib/cosmosdb-account");
|
|
6
|
+
const cosmosdb_sql_database_1 = require("@cdktf/provider-azurerm/lib/cosmosdb-sql-database");
|
|
7
|
+
const cosmosdb_sql_container_1 = require("@cdktf/provider-azurerm/lib/cosmosdb-sql-container");
|
|
8
|
+
const utils_1 = require("../../utils");
|
|
9
|
+
/**
|
|
10
|
+
* @classdesc Provides operations on Azure CosmosDB
|
|
11
|
+
* - A new instance of this class is injected into {@link CommonAzureConstruct} constructor.
|
|
12
|
+
* - If a custom construct extends {@link CommonAzureConstruct}, an instance is available within the context.
|
|
13
|
+
* @example
|
|
14
|
+
* ```
|
|
15
|
+
* import { CommonAzureConstruct, CommonAzureStackProps } from '@gradientedge/cdk-utils'
|
|
16
|
+
*
|
|
17
|
+
* class CustomConstruct extends CommonAzureConstruct {
|
|
18
|
+
* constructor(parent: Construct, id: string, props: CommonAzureStackProps) {
|
|
19
|
+
* super(parent, id, props)
|
|
20
|
+
* this.props = props
|
|
21
|
+
* this.CosmosDbManager.createCosmosAccount('MyCosmosDb', this, props)
|
|
22
|
+
* }
|
|
23
|
+
* }
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
class AzureCosmosDbManager {
|
|
27
|
+
/**
|
|
28
|
+
* @summary Method to create a new cosmosdb account
|
|
29
|
+
* @param id scoped id of the resource
|
|
30
|
+
* @param scope scope in which this resource is defined
|
|
31
|
+
* @param props cosmosdb account properties
|
|
32
|
+
* @see [CDKTF CosmosDb Account Module]{@link https://github.com/cdktf/cdktf-provider-azurerm/blob/main/docs/cosmosdbAccount.typescript.md}
|
|
33
|
+
*/
|
|
34
|
+
createCosmosDbAccount(id, scope, props) {
|
|
35
|
+
if (!props)
|
|
36
|
+
throw `Props undefined for ${id}`;
|
|
37
|
+
const resourceGroup = new data_azurerm_resource_group_1.DataAzurermResourceGroup(scope, `${id}-ca-rg`, {
|
|
38
|
+
name: scope.props.resourceGroupName
|
|
39
|
+
? `${scope.props.resourceGroupName}-${scope.props.stage}`
|
|
40
|
+
: `${props.resourceGroupName}`,
|
|
41
|
+
});
|
|
42
|
+
if (!resourceGroup)
|
|
43
|
+
throw `Resource group undefined for ${id}`;
|
|
44
|
+
const cosmosdbAccount = new cosmosdb_account_1.CosmosdbAccount(scope, `${id}-ca`, {
|
|
45
|
+
...props,
|
|
46
|
+
name: `${props.name}-${scope.props.stage}`,
|
|
47
|
+
location: resourceGroup.location,
|
|
48
|
+
resourceGroupName: resourceGroup.name,
|
|
49
|
+
tags: props.tags ?? {
|
|
50
|
+
environment: scope.props.stage,
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
(0, utils_1.createAzureTfOutput)(`${id}-cosmosdbAccountName`, scope, cosmosdbAccount.name);
|
|
54
|
+
(0, utils_1.createAzureTfOutput)(`${id}-cosmosdbAccountFriendlyUniqueId`, scope, cosmosdbAccount.friendlyUniqueId);
|
|
55
|
+
(0, utils_1.createAzureTfOutput)(`${id}-cosmosdbAccountId`, scope, cosmosdbAccount.id);
|
|
56
|
+
return cosmosdbAccount;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* @summary Method to create a new cosmosdb database
|
|
60
|
+
* @param id scoped id of the resource
|
|
61
|
+
* @param scope scope in which this resource is defined
|
|
62
|
+
* @param props cosmosdb container properties
|
|
63
|
+
* @see [CDKTF CosmosDb Container Module]{@link https://github.com/cdktf/cdktf-provider-azurerm/blob/main/docs/cosmosdbSqlContainer.typescript.md}
|
|
64
|
+
*/
|
|
65
|
+
createCosmosDbDatabase(id, scope, props) {
|
|
66
|
+
if (!props)
|
|
67
|
+
throw `Props undefined for ${id}`;
|
|
68
|
+
const resourceGroup = new data_azurerm_resource_group_1.DataAzurermResourceGroup(scope, `${id}-cd-rg`, {
|
|
69
|
+
name: scope.props.resourceGroupName
|
|
70
|
+
? `${scope.props.resourceGroupName}-${scope.props.stage}`
|
|
71
|
+
: `${props.resourceGroupName}`,
|
|
72
|
+
});
|
|
73
|
+
if (!resourceGroup)
|
|
74
|
+
throw `Resource group undefined for ${id}`;
|
|
75
|
+
const cosmosdbDatatbase = new cosmosdb_sql_database_1.CosmosdbSqlDatabase(scope, `${id}-cd`, {
|
|
76
|
+
...props,
|
|
77
|
+
name: `${props.name}-${scope.props.stage}`,
|
|
78
|
+
resourceGroupName: resourceGroup.name,
|
|
79
|
+
});
|
|
80
|
+
(0, utils_1.createAzureTfOutput)(`${id}-cosmosdbDatatbasetName`, scope, cosmosdbDatatbase.name);
|
|
81
|
+
(0, utils_1.createAzureTfOutput)(`${id}-cosmosdbDatatbaseFriendlyUniqueId`, scope, cosmosdbDatatbase.friendlyUniqueId);
|
|
82
|
+
(0, utils_1.createAzureTfOutput)(`${id}-cosmosdbDatatbaseId`, scope, cosmosdbDatatbase.id);
|
|
83
|
+
return cosmosdbDatatbase;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* @summary Method to create a new cosmosdb container
|
|
87
|
+
* @param id scoped id of the resource
|
|
88
|
+
* @param scope scope in which this resource is defined
|
|
89
|
+
* @param props cosmosdb container properties
|
|
90
|
+
* @see [CDKTF CosmosDb Container Module]{@link https://github.com/cdktf/cdktf-provider-azurerm/blob/main/docs/cosmosdbSqlContainer.typescript.md}
|
|
91
|
+
*/
|
|
92
|
+
createCosmosDbContainer(id, scope, props) {
|
|
93
|
+
if (!props)
|
|
94
|
+
throw `Props undefined for ${id}`;
|
|
95
|
+
const resourceGroup = new data_azurerm_resource_group_1.DataAzurermResourceGroup(scope, `${id}-cc-rg`, {
|
|
96
|
+
name: scope.props.resourceGroupName
|
|
97
|
+
? `${scope.props.resourceGroupName}-${scope.props.stage}`
|
|
98
|
+
: `${props.resourceGroupName}`,
|
|
99
|
+
});
|
|
100
|
+
if (!resourceGroup)
|
|
101
|
+
throw `Resource group undefined for ${id}`;
|
|
102
|
+
const cosmosdbContainer = new cosmosdb_sql_container_1.CosmosdbSqlContainer(scope, `${id}-cc`, {
|
|
103
|
+
...props,
|
|
104
|
+
name: `${props.name}-${scope.props.stage}`,
|
|
105
|
+
resourceGroupName: resourceGroup.name,
|
|
106
|
+
});
|
|
107
|
+
(0, utils_1.createAzureTfOutput)(`${id}-cosmosdbContainertName`, scope, cosmosdbContainer.name);
|
|
108
|
+
(0, utils_1.createAzureTfOutput)(`${id}-cosmosdbContainerFriendlyUniqueId`, scope, cosmosdbContainer.friendlyUniqueId);
|
|
109
|
+
(0, utils_1.createAzureTfOutput)(`${id}-cosmosdbContainerId`, scope, cosmosdbContainer.id);
|
|
110
|
+
return cosmosdbContainer;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
exports.AzureCosmosDbManager = AzureCosmosDbManager;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { CosmosdbAccountConfig } from '@cdktf/provider-azurerm/lib/cosmosdb-account';
|
|
2
|
+
import { CosmosdbSqlDatabaseConfig } from '@cdktf/provider-azurerm/lib/cosmosdb-sql-database';
|
|
3
|
+
import { CosmosdbSqlContainerConfig } from '@cdktf/provider-azurerm/lib/cosmosdb-sql-container';
|
|
4
|
+
import { CosmosdbTableConfig } from '@cdktf/provider-azurerm/lib/cosmosdb-table';
|
|
5
|
+
export interface CosmosdbAccountProps extends CosmosdbAccountConfig {
|
|
6
|
+
}
|
|
7
|
+
export interface CosmosdbSqlDatabaseProps extends CosmosdbSqlDatabaseConfig {
|
|
8
|
+
}
|
|
9
|
+
export interface CosmosdbSqlContainerProps extends CosmosdbSqlContainerConfig {
|
|
10
|
+
}
|
|
11
|
+
export interface CosmosdbTableProps extends CosmosdbTableConfig {
|
|
12
|
+
}
|
|
@@ -2,6 +2,7 @@ export * from './api-management';
|
|
|
2
2
|
export * from './app-configuration';
|
|
3
3
|
export * from './app-service';
|
|
4
4
|
export * from './application-insights';
|
|
5
|
+
export * from './cosmosdb';
|
|
5
6
|
export * from './function';
|
|
6
7
|
export * from './key-vault';
|
|
7
8
|
export * from './resource-group';
|
|
@@ -18,6 +18,7 @@ __exportStar(require("./api-management"), exports);
|
|
|
18
18
|
__exportStar(require("./app-configuration"), exports);
|
|
19
19
|
__exportStar(require("./app-service"), exports);
|
|
20
20
|
__exportStar(require("./application-insights"), exports);
|
|
21
|
+
__exportStar(require("./cosmosdb"), exports);
|
|
21
22
|
__exportStar(require("./function"), exports);
|
|
22
23
|
__exportStar(require("./key-vault"), exports);
|
|
23
24
|
__exportStar(require("./resource-group"), exports);
|
package/package.json
CHANGED
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
AzureAppServiceManager,
|
|
13
13
|
AzureApplicationInsightsManager,
|
|
14
14
|
AzureAppConfigurationManager,
|
|
15
|
+
AzureCosmosDbManager,
|
|
15
16
|
} from '../services'
|
|
16
17
|
import { CommonAzureStackProps } from './types'
|
|
17
18
|
import { AzureRemoteBackend } from './constants'
|
|
@@ -25,6 +26,7 @@ export class CommonAzureConstruct extends TerraformStack {
|
|
|
25
26
|
appServiceManager: AzureAppServiceManager
|
|
26
27
|
applicationInsightsManager: AzureApplicationInsightsManager
|
|
27
28
|
appConfigurationManager: AzureAppConfigurationManager
|
|
29
|
+
cosmosDbManager: AzureCosmosDbManager
|
|
28
30
|
functiontManager: AzureFunctionManager
|
|
29
31
|
keyVaultManager: AzureKeyVaultManager
|
|
30
32
|
resourceGroupManager: AzureResourceGroupManager
|
|
@@ -39,6 +41,7 @@ export class CommonAzureConstruct extends TerraformStack {
|
|
|
39
41
|
this.appServiceManager = new AzureAppServiceManager()
|
|
40
42
|
this.applicationInsightsManager = new AzureApplicationInsightsManager()
|
|
41
43
|
this.appConfigurationManager = new AzureAppConfigurationManager()
|
|
44
|
+
this.cosmosDbManager = new AzureCosmosDbManager()
|
|
42
45
|
this.functiontManager = new AzureFunctionManager()
|
|
43
46
|
this.keyVaultManager = new AzureKeyVaultManager()
|
|
44
47
|
this.resourceGroupManager = new AzureResourceGroupManager()
|
|
@@ -1,8 +1,21 @@
|
|
|
1
1
|
import { DataAzurermResourceGroup } from '@cdktf/provider-azurerm/lib/data-azurerm-resource-group'
|
|
2
|
+
import {
|
|
3
|
+
DataAzurermApiManagement,
|
|
4
|
+
DataAzurermApiManagementConfig,
|
|
5
|
+
} from '@cdktf/provider-azurerm/lib/data-azurerm-api-management'
|
|
6
|
+
import { ApiManagementBackend } from '@cdktf/provider-azurerm/lib/api-management-backend'
|
|
2
7
|
import { ApiManagement } from '@cdktf/provider-azurerm/lib/api-management'
|
|
8
|
+
import { ApiManagementApi } from '@cdktf/provider-azurerm/lib/api-management-api'
|
|
9
|
+
import { ApiManagementApiOperation } from '@cdktf/provider-azurerm/lib/api-management-api-operation'
|
|
10
|
+
import { ApiManagementApiOperationPolicy } from '@cdktf/provider-azurerm/lib/api-management-api-operation-policy'
|
|
11
|
+
import {
|
|
12
|
+
ApiManagementLogger,
|
|
13
|
+
ApiManagementLoggerApplicationInsights,
|
|
14
|
+
} from '@cdktf/provider-azurerm/lib/api-management-logger'
|
|
3
15
|
import { CommonAzureConstruct } from '../../common'
|
|
4
16
|
import { createAzureTfOutput } from '../../utils'
|
|
5
|
-
import { ApiManagementProps } from './types'
|
|
17
|
+
import { ApiManagementProps, ApiManagementBackendProps, ApiManagementApiProps } from './types'
|
|
18
|
+
import _ from 'lodash'
|
|
6
19
|
|
|
7
20
|
/**
|
|
8
21
|
* @classdesc Provides operations on Azure Api Management
|
|
@@ -29,7 +42,12 @@ export class AzureApiManagementManager {
|
|
|
29
42
|
* @param props api management properties
|
|
30
43
|
* @see [CDKTF Api management Module]{@link https://github.com/cdktf/cdktf-provider-azurerm/blob/main/docs/apiManagement.typescript.md}
|
|
31
44
|
*/
|
|
32
|
-
public createApiManagement(
|
|
45
|
+
public createApiManagement(
|
|
46
|
+
id: string,
|
|
47
|
+
scope: CommonAzureConstruct,
|
|
48
|
+
props: ApiManagementProps,
|
|
49
|
+
applicationInsightsKey?: ApiManagementLoggerApplicationInsights['instrumentationKey']
|
|
50
|
+
) {
|
|
33
51
|
if (!props) throw `Props undefined for ${id}`
|
|
34
52
|
|
|
35
53
|
const resourceGroup = new DataAzurermResourceGroup(scope, `${id}-am-rg`, {
|
|
@@ -49,10 +67,152 @@ export class AzureApiManagementManager {
|
|
|
49
67
|
},
|
|
50
68
|
})
|
|
51
69
|
|
|
70
|
+
if (applicationInsightsKey) {
|
|
71
|
+
new ApiManagementLogger(scope, `${id}-am-logger`, {
|
|
72
|
+
name: `${props.name}-${scope.props.stage}`,
|
|
73
|
+
resourceGroupName: resourceGroup.name,
|
|
74
|
+
apiManagementName: apiManagement.name,
|
|
75
|
+
applicationInsights: {
|
|
76
|
+
instrumentationKey: applicationInsightsKey,
|
|
77
|
+
},
|
|
78
|
+
})
|
|
79
|
+
}
|
|
80
|
+
|
|
52
81
|
createAzureTfOutput(`${id}-apiManagementName`, scope, apiManagement.name)
|
|
53
82
|
createAzureTfOutput(`${id}-apiManagementFriendlyUniqueId`, scope, apiManagement.friendlyUniqueId)
|
|
54
83
|
createAzureTfOutput(`${id}-apiManagementId`, scope, apiManagement.id)
|
|
55
84
|
|
|
56
85
|
return apiManagement
|
|
57
86
|
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* @summary Method to resolve an api management
|
|
90
|
+
* @param id scoped id of the resource
|
|
91
|
+
* @param scope scope in which this resource is defined
|
|
92
|
+
* @param props api management properties
|
|
93
|
+
* @see [CDKTF Api management Module]{@link https://github.com/cdktf/cdktf-provider-azurerm/blob/main/docs/apiManagement.typescript.md}
|
|
94
|
+
*/
|
|
95
|
+
public resolveApiManagement(id: string, scope: CommonAzureConstruct, props: DataAzurermApiManagementConfig) {
|
|
96
|
+
if (!props) throw `Props undefined for ${id}`
|
|
97
|
+
|
|
98
|
+
const resourceGroup = new DataAzurermResourceGroup(scope, `${id}-am-rg`, {
|
|
99
|
+
name: scope.props.resourceGroupName
|
|
100
|
+
? `${scope.props.resourceGroupName}-${scope.props.stage}`
|
|
101
|
+
: `${props.resourceGroupName}`,
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
if (!resourceGroup) throw `Resource group undefined for ${id}`
|
|
105
|
+
|
|
106
|
+
const apiManagement = new DataAzurermApiManagement(scope, `${id}-am`, {
|
|
107
|
+
...props,
|
|
108
|
+
name: `${props.name}-${scope.props.stage}`,
|
|
109
|
+
resourceGroupName: scope.props.resourceGroupName
|
|
110
|
+
? `${scope.props.resourceGroupName}-${scope.props.stage}`
|
|
111
|
+
: `${props.resourceGroupName}`,
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
return apiManagement
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* @summary Method to create a new api management backend
|
|
119
|
+
* @param id scoped id of the resource
|
|
120
|
+
* @param scope scope in which this resource is defined
|
|
121
|
+
* @param props api management backend properties
|
|
122
|
+
* @see [CDKTF Api management Backend Module]{@link https://github.com/cdktf/cdktf-provider-azurerm/blob/main/docs/ApiManagementBackend.typescript.md}
|
|
123
|
+
*/
|
|
124
|
+
public createApiManagementBackend(id: string, scope: CommonAzureConstruct, props: ApiManagementBackendProps) {
|
|
125
|
+
if (!props) throw `Props undefined for ${id}`
|
|
126
|
+
|
|
127
|
+
const apiManagementBackend = new ApiManagementBackend(scope, `${id}-am-be`, {
|
|
128
|
+
...props,
|
|
129
|
+
name: `${props.name}-${scope.props.stage}`,
|
|
130
|
+
description: props.description || `Backend for ${props.name}-${scope.props.stage}`,
|
|
131
|
+
protocol: props.protocol || 'http',
|
|
132
|
+
})
|
|
133
|
+
|
|
134
|
+
createAzureTfOutput(`${id}-apiManagementBackendName`, scope, apiManagementBackend.name)
|
|
135
|
+
createAzureTfOutput(`${id}-apiManagementBackendFriendlyUniqueId`, scope, apiManagementBackend.friendlyUniqueId)
|
|
136
|
+
createAzureTfOutput(`${id}-apiManagementBackendId`, scope, apiManagementBackend.id)
|
|
137
|
+
|
|
138
|
+
return apiManagementBackend
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* @summary Method to create a new api management api
|
|
143
|
+
* @param id scoped id of the resource
|
|
144
|
+
* @param scope scope in which this resource is defined
|
|
145
|
+
* @param props api management api properties
|
|
146
|
+
* @see [CDKTF Api management Api Module]{@link https://github.com/cdktf/cdktf-provider-azurerm/blob/main/docs/ApiManagementApi.typescript.md}
|
|
147
|
+
*/
|
|
148
|
+
public createApiManagementApi(id: string, scope: CommonAzureConstruct, props: ApiManagementApiProps) {
|
|
149
|
+
if (!props) throw `Props undefined for ${id}`
|
|
150
|
+
|
|
151
|
+
const apiManagementApi = new ApiManagementApi(scope, `${id}-am-api`, {
|
|
152
|
+
...props,
|
|
153
|
+
name: `${props.name}-${scope.props.stage}`,
|
|
154
|
+
displayName: props.displayName || props.name,
|
|
155
|
+
revision: props.revision || '1',
|
|
156
|
+
protocols: props.protocols || ['https'],
|
|
157
|
+
})
|
|
158
|
+
|
|
159
|
+
createAzureTfOutput(`${id}-apiManagementApiName`, scope, apiManagementApi.name)
|
|
160
|
+
createAzureTfOutput(`${id}-apiManagementApiFriendlyUniqueId`, scope, apiManagementApi.friendlyUniqueId)
|
|
161
|
+
createAzureTfOutput(`${id}-apiManagementApiId`, scope, apiManagementApi.id)
|
|
162
|
+
|
|
163
|
+
_.forEach(props.operations, operation => {
|
|
164
|
+
const apimOperation = new ApiManagementApiOperation(
|
|
165
|
+
scope,
|
|
166
|
+
`${id}-apim-api-operation-${operation.path}-${operation.method}`,
|
|
167
|
+
{
|
|
168
|
+
operationId: `${operation.path}-${operation.method}`,
|
|
169
|
+
method: operation.method.toUpperCase(),
|
|
170
|
+
apiManagementName: apiManagementApi.apiManagementName,
|
|
171
|
+
resourceGroupName: apiManagementApi.resourceGroupName,
|
|
172
|
+
apiName: apiManagementApi.name,
|
|
173
|
+
displayName: `/${operation.path}`,
|
|
174
|
+
urlTemplate: `/${operation.path}`,
|
|
175
|
+
}
|
|
176
|
+
)
|
|
177
|
+
|
|
178
|
+
createAzureTfOutput(
|
|
179
|
+
`${id}-${operation.path}-${operation.method}-apimOperationOperationId`,
|
|
180
|
+
scope,
|
|
181
|
+
apimOperation.operationId
|
|
182
|
+
)
|
|
183
|
+
createAzureTfOutput(
|
|
184
|
+
`${id}-${operation.path}-${operation.method}-apimOperationFriendlyUniqueId`,
|
|
185
|
+
scope,
|
|
186
|
+
apimOperation.friendlyUniqueId
|
|
187
|
+
)
|
|
188
|
+
createAzureTfOutput(`${id}-${operation.path}-${operation.method}-apimOperationId`, scope, apimOperation.id)
|
|
189
|
+
|
|
190
|
+
if (props.policyXmlContent) {
|
|
191
|
+
const apimOperationPolicy = new ApiManagementApiOperationPolicy(
|
|
192
|
+
scope,
|
|
193
|
+
`${id}-apim-api-operation-policy-${operation.path}-${operation.method}`,
|
|
194
|
+
{
|
|
195
|
+
apiManagementName: apiManagementApi.apiManagementName,
|
|
196
|
+
resourceGroupName: apiManagementApi.resourceGroupName,
|
|
197
|
+
apiName: apiManagementApi.name,
|
|
198
|
+
operationId: apimOperation.operationId,
|
|
199
|
+
xmlContent: props.policyXmlContent,
|
|
200
|
+
}
|
|
201
|
+
)
|
|
202
|
+
|
|
203
|
+
createAzureTfOutput(
|
|
204
|
+
`${id}-${operation.path}-${operation.method}-apimOperationPolicyFriendlyUniqueId`,
|
|
205
|
+
scope,
|
|
206
|
+
apimOperationPolicy.friendlyUniqueId
|
|
207
|
+
)
|
|
208
|
+
createAzureTfOutput(
|
|
209
|
+
`${id}-${operation.path}-${operation.method}-apimOperationPolicyId`,
|
|
210
|
+
scope,
|
|
211
|
+
apimOperationPolicy.id
|
|
212
|
+
)
|
|
213
|
+
}
|
|
214
|
+
})
|
|
215
|
+
|
|
216
|
+
return apiManagementApi
|
|
217
|
+
}
|
|
58
218
|
}
|
|
@@ -1,3 +1,19 @@
|
|
|
1
1
|
import { ApiManagementConfig } from '@cdktf/provider-azurerm/lib/api-management'
|
|
2
|
+
import { ApiManagementBackendConfig } from '@cdktf/provider-azurerm/lib/api-management-backend'
|
|
3
|
+
import { ApiManagementApiConfig } from '@cdktf/provider-azurerm/lib/api-management-api'
|
|
4
|
+
import { ApiManagementApiOperationConfig } from '@cdktf/provider-azurerm/lib/api-management-api-operation'
|
|
5
|
+
import { ApiManagementApiOperationPolicyConfig } from '@cdktf/provider-azurerm/lib/api-management-api-operation-policy'
|
|
2
6
|
|
|
3
7
|
export interface ApiManagementProps extends ApiManagementConfig {}
|
|
8
|
+
|
|
9
|
+
export interface ApiManagementBackendProps extends ApiManagementBackendConfig {}
|
|
10
|
+
|
|
11
|
+
export interface ApiManagementApiProps extends ApiManagementApiConfig {
|
|
12
|
+
operations: OperationsProps[]
|
|
13
|
+
policyXmlContent?: ApiManagementApiOperationPolicyConfig['xmlContent']
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface OperationsProps {
|
|
17
|
+
path: ApiManagementApiOperationConfig['urlTemplate']
|
|
18
|
+
method: ApiManagementApiOperationConfig['method']
|
|
19
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { DataAzurermResourceGroup } from '@cdktf/provider-azurerm/lib/data-azurerm-resource-group'
|
|
2
|
+
import { CosmosdbAccount } from '@cdktf/provider-azurerm/lib/cosmosdb-account'
|
|
3
|
+
import { CosmosdbSqlDatabase } from '@cdktf/provider-azurerm/lib/cosmosdb-sql-database'
|
|
4
|
+
import { CosmosdbSqlContainer } from '@cdktf/provider-azurerm/lib/cosmosdb-sql-container'
|
|
5
|
+
import { CosmosdbTable } from '@cdktf/provider-azurerm/lib/cosmosdb-table'
|
|
6
|
+
import { CommonAzureConstruct } from '../../common'
|
|
7
|
+
import { createAzureTfOutput } from '../../utils'
|
|
8
|
+
import { CosmosdbAccountProps, CosmosdbTableProps, CosmosdbSqlContainerProps, CosmosdbSqlDatabaseProps } from './types'
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @classdesc Provides operations on Azure CosmosDB
|
|
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.CosmosDbManager.createCosmosAccount('MyCosmosDb', this, props)
|
|
23
|
+
* }
|
|
24
|
+
* }
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export class AzureCosmosDbManager {
|
|
28
|
+
/**
|
|
29
|
+
* @summary Method to create a new cosmosdb account
|
|
30
|
+
* @param id scoped id of the resource
|
|
31
|
+
* @param scope scope in which this resource is defined
|
|
32
|
+
* @param props cosmosdb account properties
|
|
33
|
+
* @see [CDKTF CosmosDb Account Module]{@link https://github.com/cdktf/cdktf-provider-azurerm/blob/main/docs/cosmosdbAccount.typescript.md}
|
|
34
|
+
*/
|
|
35
|
+
public createCosmosDbAccount(id: string, scope: CommonAzureConstruct, props: CosmosdbAccountProps) {
|
|
36
|
+
if (!props) throw `Props undefined for ${id}`
|
|
37
|
+
|
|
38
|
+
const resourceGroup = new DataAzurermResourceGroup(scope, `${id}-ca-rg`, {
|
|
39
|
+
name: scope.props.resourceGroupName
|
|
40
|
+
? `${scope.props.resourceGroupName}-${scope.props.stage}`
|
|
41
|
+
: `${props.resourceGroupName}`,
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
if (!resourceGroup) throw `Resource group undefined for ${id}`
|
|
45
|
+
|
|
46
|
+
const cosmosdbAccount = new CosmosdbAccount(scope, `${id}-ca`, {
|
|
47
|
+
...props,
|
|
48
|
+
name: `${props.name}-${scope.props.stage}`,
|
|
49
|
+
location: resourceGroup.location,
|
|
50
|
+
resourceGroupName: resourceGroup.name,
|
|
51
|
+
tags: props.tags ?? {
|
|
52
|
+
environment: scope.props.stage,
|
|
53
|
+
},
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
createAzureTfOutput(`${id}-cosmosdbAccountName`, scope, cosmosdbAccount.name)
|
|
57
|
+
createAzureTfOutput(`${id}-cosmosdbAccountFriendlyUniqueId`, scope, cosmosdbAccount.friendlyUniqueId)
|
|
58
|
+
createAzureTfOutput(`${id}-cosmosdbAccountId`, scope, cosmosdbAccount.id)
|
|
59
|
+
|
|
60
|
+
return cosmosdbAccount
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* @summary Method to create a new cosmosdb database
|
|
65
|
+
* @param id scoped id of the resource
|
|
66
|
+
* @param scope scope in which this resource is defined
|
|
67
|
+
* @param props cosmosdb container properties
|
|
68
|
+
* @see [CDKTF CosmosDb Container Module]{@link https://github.com/cdktf/cdktf-provider-azurerm/blob/main/docs/cosmosdbSqlContainer.typescript.md}
|
|
69
|
+
*/
|
|
70
|
+
public createCosmosDbDatabase(id: string, scope: CommonAzureConstruct, props: CosmosdbSqlDatabaseProps) {
|
|
71
|
+
if (!props) throw `Props undefined for ${id}`
|
|
72
|
+
|
|
73
|
+
const resourceGroup = new DataAzurermResourceGroup(scope, `${id}-cd-rg`, {
|
|
74
|
+
name: scope.props.resourceGroupName
|
|
75
|
+
? `${scope.props.resourceGroupName}-${scope.props.stage}`
|
|
76
|
+
: `${props.resourceGroupName}`,
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
if (!resourceGroup) throw `Resource group undefined for ${id}`
|
|
80
|
+
|
|
81
|
+
const cosmosdbDatatbase = new CosmosdbSqlDatabase(scope, `${id}-cd`, {
|
|
82
|
+
...props,
|
|
83
|
+
name: `${props.name}-${scope.props.stage}`,
|
|
84
|
+
resourceGroupName: resourceGroup.name,
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
createAzureTfOutput(`${id}-cosmosdbDatatbasetName`, scope, cosmosdbDatatbase.name)
|
|
88
|
+
createAzureTfOutput(`${id}-cosmosdbDatatbaseFriendlyUniqueId`, scope, cosmosdbDatatbase.friendlyUniqueId)
|
|
89
|
+
createAzureTfOutput(`${id}-cosmosdbDatatbaseId`, scope, cosmosdbDatatbase.id)
|
|
90
|
+
|
|
91
|
+
return cosmosdbDatatbase
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* @summary Method to create a new cosmosdb container
|
|
96
|
+
* @param id scoped id of the resource
|
|
97
|
+
* @param scope scope in which this resource is defined
|
|
98
|
+
* @param props cosmosdb container properties
|
|
99
|
+
* @see [CDKTF CosmosDb Container Module]{@link https://github.com/cdktf/cdktf-provider-azurerm/blob/main/docs/cosmosdbSqlContainer.typescript.md}
|
|
100
|
+
*/
|
|
101
|
+
public createCosmosDbContainer(id: string, scope: CommonAzureConstruct, props: CosmosdbSqlContainerProps) {
|
|
102
|
+
if (!props) throw `Props undefined for ${id}`
|
|
103
|
+
|
|
104
|
+
const resourceGroup = new DataAzurermResourceGroup(scope, `${id}-cc-rg`, {
|
|
105
|
+
name: scope.props.resourceGroupName
|
|
106
|
+
? `${scope.props.resourceGroupName}-${scope.props.stage}`
|
|
107
|
+
: `${props.resourceGroupName}`,
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
if (!resourceGroup) throw `Resource group undefined for ${id}`
|
|
111
|
+
|
|
112
|
+
const cosmosdbContainer = new CosmosdbSqlContainer(scope, `${id}-cc`, {
|
|
113
|
+
...props,
|
|
114
|
+
name: `${props.name}-${scope.props.stage}`,
|
|
115
|
+
resourceGroupName: resourceGroup.name,
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
createAzureTfOutput(`${id}-cosmosdbContainertName`, scope, cosmosdbContainer.name)
|
|
119
|
+
createAzureTfOutput(`${id}-cosmosdbContainerFriendlyUniqueId`, scope, cosmosdbContainer.friendlyUniqueId)
|
|
120
|
+
createAzureTfOutput(`${id}-cosmosdbContainerId`, scope, cosmosdbContainer.id)
|
|
121
|
+
|
|
122
|
+
return cosmosdbContainer
|
|
123
|
+
}
|
|
124
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { CosmosdbAccountConfig } from '@cdktf/provider-azurerm/lib/cosmosdb-account'
|
|
2
|
+
import { CosmosdbSqlDatabaseConfig } from '@cdktf/provider-azurerm/lib/cosmosdb-sql-database'
|
|
3
|
+
import { CosmosdbSqlContainerConfig } from '@cdktf/provider-azurerm/lib/cosmosdb-sql-container'
|
|
4
|
+
import { CosmosdbTableConfig } from '@cdktf/provider-azurerm/lib/cosmosdb-table'
|
|
5
|
+
|
|
6
|
+
export interface CosmosdbAccountProps extends CosmosdbAccountConfig {}
|
|
7
|
+
export interface CosmosdbSqlDatabaseProps extends CosmosdbSqlDatabaseConfig {}
|
|
8
|
+
export interface CosmosdbSqlContainerProps extends CosmosdbSqlContainerConfig {}
|
|
9
|
+
export interface CosmosdbTableProps extends CosmosdbTableConfig {}
|