@gradientedge/cdk-utils 9.35.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.js +14 -13
- package/dist/src/lib/azure/services/api-management/types.d.ts +1 -1
- 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 +28 -27
- package/src/lib/azure/services/api-management/types.ts +1 -1
- 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();
|
|
@@ -135,8 +135,10 @@ class AzureApiManagementManager {
|
|
|
135
135
|
displayName: props.displayName || props.name,
|
|
136
136
|
revision: props.revision || '1',
|
|
137
137
|
protocols: props.protocols || ['https'],
|
|
138
|
-
subscriptionRequired: props.subscriptionRequired || true,
|
|
139
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);
|
|
140
142
|
lodash_1.default.forEach(props.operations, operation => {
|
|
141
143
|
const apimOperation = new api_management_api_operation_1.ApiManagementApiOperation(scope, `${id}-apim-api-operation-${operation.path}-${operation.method}`, {
|
|
142
144
|
operationId: `${operation.path}-${operation.method}`,
|
|
@@ -147,22 +149,21 @@ class AzureApiManagementManager {
|
|
|
147
149
|
displayName: `/${operation.path}`,
|
|
148
150
|
urlTemplate: `/${operation.path}`,
|
|
149
151
|
});
|
|
150
|
-
const apimOperationPolicy = new api_management_api_operation_policy_1.ApiManagementApiOperationPolicy(scope, `${id}-apim-api-operation-policy-${operation.path}-${operation.method}`, {
|
|
151
|
-
apiManagementName: apiManagementApi.apiManagementName,
|
|
152
|
-
resourceGroupName: apiManagementApi.resourceGroupName,
|
|
153
|
-
apiName: apiManagementApi.name,
|
|
154
|
-
operationId: apimOperation.operationId,
|
|
155
|
-
xmlContent: operation.xmlContent,
|
|
156
|
-
});
|
|
157
152
|
(0, utils_1.createAzureTfOutput)(`${id}-${operation.path}-${operation.method}-apimOperationOperationId`, scope, apimOperation.operationId);
|
|
158
153
|
(0, utils_1.createAzureTfOutput)(`${id}-${operation.path}-${operation.method}-apimOperationFriendlyUniqueId`, scope, apimOperation.friendlyUniqueId);
|
|
159
154
|
(0, utils_1.createAzureTfOutput)(`${id}-${operation.path}-${operation.method}-apimOperationId`, scope, apimOperation.id);
|
|
160
|
-
(
|
|
161
|
-
|
|
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
|
+
}
|
|
162
166
|
});
|
|
163
|
-
(0, utils_1.createAzureTfOutput)(`${id}-apiManagementApiName`, scope, apiManagementApi.name);
|
|
164
|
-
(0, utils_1.createAzureTfOutput)(`${id}-apiManagementApiFriendlyUniqueId`, scope, apiManagementApi.friendlyUniqueId);
|
|
165
|
-
(0, utils_1.createAzureTfOutput)(`${id}-apiManagementApiId`, scope, apiManagementApi.id);
|
|
166
167
|
return apiManagementApi;
|
|
167
168
|
}
|
|
168
169
|
}
|
|
@@ -9,9 +9,9 @@ export interface ApiManagementBackendProps extends ApiManagementBackendConfig {
|
|
|
9
9
|
}
|
|
10
10
|
export interface ApiManagementApiProps extends ApiManagementApiConfig {
|
|
11
11
|
operations: OperationsProps[];
|
|
12
|
+
policyXmlContent?: ApiManagementApiOperationPolicyConfig['xmlContent'];
|
|
12
13
|
}
|
|
13
14
|
export interface OperationsProps {
|
|
14
15
|
path: ApiManagementApiOperationConfig['urlTemplate'];
|
|
15
16
|
method: ApiManagementApiOperationConfig['method'];
|
|
16
|
-
xmlContent?: ApiManagementApiOperationPolicyConfig['xmlContent'];
|
|
17
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()
|
|
@@ -154,9 +154,12 @@ export class AzureApiManagementManager {
|
|
|
154
154
|
displayName: props.displayName || props.name,
|
|
155
155
|
revision: props.revision || '1',
|
|
156
156
|
protocols: props.protocols || ['https'],
|
|
157
|
-
subscriptionRequired: props.subscriptionRequired || true,
|
|
158
157
|
})
|
|
159
158
|
|
|
159
|
+
createAzureTfOutput(`${id}-apiManagementApiName`, scope, apiManagementApi.name)
|
|
160
|
+
createAzureTfOutput(`${id}-apiManagementApiFriendlyUniqueId`, scope, apiManagementApi.friendlyUniqueId)
|
|
161
|
+
createAzureTfOutput(`${id}-apiManagementApiId`, scope, apiManagementApi.id)
|
|
162
|
+
|
|
160
163
|
_.forEach(props.operations, operation => {
|
|
161
164
|
const apimOperation = new ApiManagementApiOperation(
|
|
162
165
|
scope,
|
|
@@ -172,18 +175,6 @@ export class AzureApiManagementManager {
|
|
|
172
175
|
}
|
|
173
176
|
)
|
|
174
177
|
|
|
175
|
-
const apimOperationPolicy = new ApiManagementApiOperationPolicy(
|
|
176
|
-
scope,
|
|
177
|
-
`${id}-apim-api-operation-policy-${operation.path}-${operation.method}`,
|
|
178
|
-
{
|
|
179
|
-
apiManagementName: apiManagementApi.apiManagementName,
|
|
180
|
-
resourceGroupName: apiManagementApi.resourceGroupName,
|
|
181
|
-
apiName: apiManagementApi.name,
|
|
182
|
-
operationId: apimOperation.operationId,
|
|
183
|
-
xmlContent: operation.xmlContent,
|
|
184
|
-
}
|
|
185
|
-
)
|
|
186
|
-
|
|
187
178
|
createAzureTfOutput(
|
|
188
179
|
`${id}-${operation.path}-${operation.method}-apimOperationOperationId`,
|
|
189
180
|
scope,
|
|
@@ -196,22 +187,32 @@ export class AzureApiManagementManager {
|
|
|
196
187
|
)
|
|
197
188
|
createAzureTfOutput(`${id}-${operation.path}-${operation.method}-apimOperationId`, scope, apimOperation.id)
|
|
198
189
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
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
|
+
}
|
|
209
214
|
})
|
|
210
215
|
|
|
211
|
-
createAzureTfOutput(`${id}-apiManagementApiName`, scope, apiManagementApi.name)
|
|
212
|
-
createAzureTfOutput(`${id}-apiManagementApiFriendlyUniqueId`, scope, apiManagementApi.friendlyUniqueId)
|
|
213
|
-
createAzureTfOutput(`${id}-apiManagementApiId`, scope, apiManagementApi.id)
|
|
214
|
-
|
|
215
216
|
return apiManagementApi
|
|
216
217
|
}
|
|
217
218
|
}
|
|
@@ -10,10 +10,10 @@ export interface ApiManagementBackendProps extends ApiManagementBackendConfig {}
|
|
|
10
10
|
|
|
11
11
|
export interface ApiManagementApiProps extends ApiManagementApiConfig {
|
|
12
12
|
operations: OperationsProps[]
|
|
13
|
+
policyXmlContent?: ApiManagementApiOperationPolicyConfig['xmlContent']
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
export interface OperationsProps {
|
|
16
17
|
path: ApiManagementApiOperationConfig['urlTemplate']
|
|
17
18
|
method: ApiManagementApiOperationConfig['method']
|
|
18
|
-
xmlContent?: ApiManagementApiOperationPolicyConfig['xmlContent']
|
|
19
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 {}
|