@gradientedge/cdk-utils 9.31.0 → 9.32.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/constants.d.ts +4 -0
- package/dist/src/lib/azure/common/constants.js +8 -0
- package/dist/src/lib/azure/common/construct.d.ts +8 -1
- package/dist/src/lib/azure/common/construct.js +36 -0
- package/dist/src/lib/azure/common/index.d.ts +1 -0
- package/dist/src/lib/azure/common/index.js +1 -0
- package/dist/src/lib/azure/common/stack.d.ts +1 -0
- package/dist/src/lib/azure/common/stack.js +1 -3
- package/dist/src/lib/azure/common/types.d.ts +6 -0
- package/dist/src/lib/azure/services/api-management/index.d.ts +2 -0
- package/dist/src/lib/azure/services/api-management/index.js +18 -0
- package/dist/src/lib/azure/services/api-management/main.d.ts +30 -0
- package/dist/src/lib/azure/services/api-management/main.js +56 -0
- package/dist/src/lib/azure/services/api-management/types.d.ts +3 -0
- package/dist/src/lib/azure/services/api-management/types.js +2 -0
- package/dist/src/lib/azure/services/function/index.d.ts +2 -0
- package/dist/src/lib/azure/services/function/index.js +18 -0
- package/dist/src/lib/azure/services/function/main.d.ts +39 -0
- package/dist/src/lib/azure/services/function/main.js +88 -0
- package/dist/src/lib/azure/services/function/types.d.ts +8 -0
- package/dist/src/lib/azure/services/function/types.js +2 -0
- package/dist/src/lib/azure/services/index.d.ts +4 -0
- package/dist/src/lib/azure/services/index.js +4 -0
- package/dist/src/lib/azure/services/key-vault/index.d.ts +2 -0
- package/dist/src/lib/azure/services/key-vault/index.js +18 -0
- package/dist/src/lib/azure/services/key-vault/main.d.ts +30 -0
- package/dist/src/lib/azure/services/key-vault/main.js +58 -0
- package/dist/src/lib/azure/services/key-vault/types.d.ts +3 -0
- package/dist/src/lib/azure/services/key-vault/types.js +2 -0
- package/dist/src/lib/azure/services/resource-group/index.d.ts +2 -0
- package/dist/src/lib/azure/services/resource-group/index.js +18 -0
- package/dist/src/lib/azure/services/resource-group/main.d.ts +30 -0
- package/dist/src/lib/azure/services/resource-group/main.js +48 -0
- package/dist/src/lib/azure/services/resource-group/types.d.ts +3 -0
- package/dist/src/lib/azure/services/resource-group/types.js +2 -0
- package/dist/src/lib/azure/services/storage/main.d.ts +6 -3
- package/dist/src/lib/azure/services/storage/main.js +3 -0
- package/package.json +1 -1
- package/src/lib/azure/common/constants.ts +4 -0
- package/src/lib/azure/common/construct.ts +45 -2
- package/src/lib/azure/common/index.ts +1 -0
- package/src/lib/azure/common/stack.ts +1 -3
- package/src/lib/azure/common/types.ts +7 -0
- package/src/lib/azure/services/api-management/index.ts +2 -0
- package/src/lib/azure/services/api-management/main.ts +58 -0
- package/src/lib/azure/services/api-management/types.ts +3 -0
- package/src/lib/azure/services/function/index.ts +2 -0
- package/src/lib/azure/services/function/main.ts +95 -0
- package/src/lib/azure/services/function/types.ts +9 -0
- package/src/lib/azure/services/index.ts +4 -0
- package/src/lib/azure/services/key-vault/index.ts +2 -0
- package/src/lib/azure/services/key-vault/main.ts +60 -0
- package/src/lib/azure/services/key-vault/types.ts +3 -0
- package/src/lib/azure/services/resource-group/index.ts +2 -0
- package/src/lib/azure/services/resource-group/main.ts +49 -0
- package/src/lib/azure/services/resource-group/types.ts +3 -0
- package/src/lib/azure/services/storage/main.ts +6 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { ResourceGroup } from '@cdktf/provider-azurerm/lib/resource-group';
|
|
2
|
+
import { CommonAzureConstruct } from '../../common';
|
|
3
|
+
import { ResourceGroupProps } from './types';
|
|
4
|
+
/**
|
|
5
|
+
* @classdesc Provides operations on Azure Resource Group
|
|
6
|
+
* - A new instance of this class is injected into {@link CommonAzureConstruct} constructor.
|
|
7
|
+
* - If a custom construct extends {@link CommonAzureConstruct}, an instance is available within the context.
|
|
8
|
+
* @example
|
|
9
|
+
* ```
|
|
10
|
+
* import { CommonAzureConstruct, CommonAzureStackProps } from '@gradientedge/cdk-utils'
|
|
11
|
+
*
|
|
12
|
+
* class CustomConstruct extends CommonAzureConstruct {
|
|
13
|
+
* constructor(parent: Construct, id: string, props: CommonAzureStackProps) {
|
|
14
|
+
* super(parent, id, props)
|
|
15
|
+
* this.props = props
|
|
16
|
+
* this.resourceGroupManager.createResourceGroup('MyResourceGroup', this, props)
|
|
17
|
+
* }
|
|
18
|
+
* }
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare class AzureResourceGroupManager {
|
|
22
|
+
/**
|
|
23
|
+
* @summary Method to create a new resource group
|
|
24
|
+
* @param id scoped id of the resource
|
|
25
|
+
* @param scope scope in which this resource is defined
|
|
26
|
+
* @param props resource group properties
|
|
27
|
+
* @see [CDKTF Resource Group Module]{@link https://github.com/cdktf/cdktf-provider-azurerm/blob/main/docs/resourceGroup.typescript.md}
|
|
28
|
+
*/
|
|
29
|
+
createResourceGroup(id: string, scope: CommonAzureConstruct, props: ResourceGroupProps): ResourceGroup;
|
|
30
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AzureResourceGroupManager = void 0;
|
|
4
|
+
const resource_group_1 = require("@cdktf/provider-azurerm/lib/resource-group");
|
|
5
|
+
const utils_1 = require("../../utils");
|
|
6
|
+
/**
|
|
7
|
+
* @classdesc Provides operations on Azure Resource Group
|
|
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.resourceGroupManager.createResourceGroup('MyResourceGroup', this, props)
|
|
19
|
+
* }
|
|
20
|
+
* }
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
class AzureResourceGroupManager {
|
|
24
|
+
/**
|
|
25
|
+
* @summary Method to create a new resource group
|
|
26
|
+
* @param id scoped id of the resource
|
|
27
|
+
* @param scope scope in which this resource is defined
|
|
28
|
+
* @param props resource group properties
|
|
29
|
+
* @see [CDKTF Resource Group Module]{@link https://github.com/cdktf/cdktf-provider-azurerm/blob/main/docs/resourceGroup.typescript.md}
|
|
30
|
+
*/
|
|
31
|
+
createResourceGroup(id, scope, props) {
|
|
32
|
+
if (!props)
|
|
33
|
+
throw `Props undefined for ${id}`;
|
|
34
|
+
const resourceGroup = new resource_group_1.ResourceGroup(scope, `${id}-rg`, {
|
|
35
|
+
...props,
|
|
36
|
+
name: props.name,
|
|
37
|
+
location: props.location,
|
|
38
|
+
tags: props.tags ?? {
|
|
39
|
+
environment: scope.props.stage,
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
(0, utils_1.createAzureTfOutput)(`${id}-resourceGroupName`, scope, resourceGroup.name);
|
|
43
|
+
(0, utils_1.createAzureTfOutput)(`${id}-resourceGroupFriendlyUniqueId`, scope, resourceGroup.friendlyUniqueId);
|
|
44
|
+
(0, utils_1.createAzureTfOutput)(`${id}-resourceGroupId`, scope, resourceGroup.id);
|
|
45
|
+
return resourceGroup;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.AzureResourceGroupManager = AzureResourceGroupManager;
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { StorageAccount } from '@cdktf/provider-azurerm/lib/storage-account';
|
|
2
|
+
import { StorageBlob } from '@cdktf/provider-azurerm/lib/storage-blob';
|
|
3
|
+
import { StorageContainer } from '@cdktf/provider-azurerm/lib/storage-container';
|
|
1
4
|
import { CommonAzureConstruct } from '../../common';
|
|
2
5
|
import { StorageAccountProps, StorageBlobProps, StorageContainerProps } from './types';
|
|
3
6
|
/**
|
|
@@ -25,7 +28,7 @@ export declare class AzureStorageManager {
|
|
|
25
28
|
* @param props storage account properties
|
|
26
29
|
* @see [CDKTF Storage Account Module]{@link https://github.com/cdktf/cdktf-provider-azurerm/blob/main/docs/storageAccount.typescript.md}
|
|
27
30
|
*/
|
|
28
|
-
createStorageAccount(id: string, scope: CommonAzureConstruct, props: StorageAccountProps):
|
|
31
|
+
createStorageAccount(id: string, scope: CommonAzureConstruct, props: StorageAccountProps): StorageAccount;
|
|
29
32
|
/**
|
|
30
33
|
* @summary Method to create a new storage container
|
|
31
34
|
* @param id scoped id of the resource
|
|
@@ -33,7 +36,7 @@ export declare class AzureStorageManager {
|
|
|
33
36
|
* @param props storage container properties
|
|
34
37
|
* @see [CDKTF Storage Container Module]{@link https://github.com/cdktf/cdktf-provider-azurerm/blob/main/docs/storageContainer.typescript.md}
|
|
35
38
|
*/
|
|
36
|
-
createStorageContainer(id: string, scope: CommonAzureConstruct, props: StorageContainerProps):
|
|
39
|
+
createStorageContainer(id: string, scope: CommonAzureConstruct, props: StorageContainerProps): StorageContainer;
|
|
37
40
|
/**
|
|
38
41
|
* @summary Method to create a new storage blob
|
|
39
42
|
* @param id scoped id of the resource
|
|
@@ -41,5 +44,5 @@ export declare class AzureStorageManager {
|
|
|
41
44
|
* @param props storage blob properties
|
|
42
45
|
* @see [CDKTF Storage Blob Module]{@link https://github.com/cdktf/cdktf-provider-azurerm/blob/main/docs/storageBlob.typescript.md}
|
|
43
46
|
*/
|
|
44
|
-
createStorageBlob(id: string, scope: CommonAzureConstruct, props: StorageBlobProps):
|
|
47
|
+
createStorageBlob(id: string, scope: CommonAzureConstruct, props: StorageBlobProps): StorageBlob;
|
|
45
48
|
}
|
|
@@ -56,6 +56,7 @@ class AzureStorageManager {
|
|
|
56
56
|
(0, utils_1.createAzureTfOutput)(`${id}-storageAccountName`, scope, storageAccount.name);
|
|
57
57
|
(0, utils_1.createAzureTfOutput)(`${id}-storageAccountFriendlyUniqueId`, scope, storageAccount.friendlyUniqueId);
|
|
58
58
|
(0, utils_1.createAzureTfOutput)(`${id}-storageAccountId`, scope, storageAccount.id);
|
|
59
|
+
return storageAccount;
|
|
59
60
|
}
|
|
60
61
|
/**
|
|
61
62
|
* @summary Method to create a new storage container
|
|
@@ -86,6 +87,7 @@ class AzureStorageManager {
|
|
|
86
87
|
(0, utils_1.createAzureTfOutput)(`${id}-storageContainerName`, scope, storageContainer.name);
|
|
87
88
|
(0, utils_1.createAzureTfOutput)(`${id}-storageContainerFriendlyUniqueId`, scope, storageContainer.friendlyUniqueId);
|
|
88
89
|
(0, utils_1.createAzureTfOutput)(`${id}-storageContainerId`, scope, storageContainer.id);
|
|
90
|
+
return storageContainer;
|
|
89
91
|
}
|
|
90
92
|
/**
|
|
91
93
|
* @summary Method to create a new storage blob
|
|
@@ -121,6 +123,7 @@ class AzureStorageManager {
|
|
|
121
123
|
(0, utils_1.createAzureTfOutput)(`${id}-storageBlobName`, scope, storageBlob.name);
|
|
122
124
|
(0, utils_1.createAzureTfOutput)(`${id}-storageBlobFriendlyUniqueId`, scope, storageBlob.friendlyUniqueId);
|
|
123
125
|
(0, utils_1.createAzureTfOutput)(`${id}-storageBlobId`, scope, storageBlob.id);
|
|
126
|
+
return storageBlob;
|
|
124
127
|
}
|
|
125
128
|
}
|
|
126
129
|
exports.AzureStorageManager = AzureStorageManager;
|
package/package.json
CHANGED
|
@@ -1,14 +1,27 @@
|
|
|
1
1
|
import { AzurermProvider } from '@cdktf/provider-azurerm/lib/provider'
|
|
2
|
-
import {
|
|
2
|
+
import { DataAzurermClientConfig } from '@cdktf/provider-azurerm/lib/data-azurerm-client-config'
|
|
3
|
+
import { AzurermBackend, TerraformStack } from 'cdktf'
|
|
3
4
|
import { Construct } from 'constructs'
|
|
4
5
|
import { isDevStage, isPrdStage, isTestStage, isUatStage } from '../../common'
|
|
5
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
AzureStorageManager,
|
|
8
|
+
AzureKeyVaultManager,
|
|
9
|
+
AzureApiManagementManager,
|
|
10
|
+
AzureFunctionManager,
|
|
11
|
+
AzureResourceGroupManager,
|
|
12
|
+
} from '../services'
|
|
6
13
|
import { CommonAzureStackProps } from './types'
|
|
14
|
+
import { AzureRemoteBackend } from './constants'
|
|
7
15
|
|
|
8
16
|
export class CommonAzureConstruct extends TerraformStack {
|
|
9
17
|
declare props: CommonAzureStackProps
|
|
10
18
|
id: string
|
|
11
19
|
fullyQualifiedDomainName: string
|
|
20
|
+
tenantId: string
|
|
21
|
+
apiManagementtManager: AzureApiManagementManager
|
|
22
|
+
functiontManager: AzureFunctionManager
|
|
23
|
+
keyVaultManager: AzureKeyVaultManager
|
|
24
|
+
resourceGroupManager: AzureResourceGroupManager
|
|
12
25
|
storageManager: AzureStorageManager
|
|
13
26
|
|
|
14
27
|
constructor(scope: Construct, id: string, props: CommonAzureStackProps) {
|
|
@@ -16,9 +29,15 @@ export class CommonAzureConstruct extends TerraformStack {
|
|
|
16
29
|
this.props = props
|
|
17
30
|
this.id = id
|
|
18
31
|
|
|
32
|
+
this.apiManagementtManager = new AzureApiManagementManager()
|
|
33
|
+
this.functiontManager = new AzureFunctionManager()
|
|
34
|
+
this.keyVaultManager = new AzureKeyVaultManager()
|
|
35
|
+
this.resourceGroupManager = new AzureResourceGroupManager()
|
|
19
36
|
this.storageManager = new AzureStorageManager()
|
|
20
37
|
|
|
21
38
|
this.determineFullyQualifiedDomain()
|
|
39
|
+
this.determineRemoteBackend()
|
|
40
|
+
this.determineTenantId()
|
|
22
41
|
new AzurermProvider(this, `${this.id}-provider`, this.props)
|
|
23
42
|
}
|
|
24
43
|
|
|
@@ -31,6 +50,30 @@ export class CommonAzureConstruct extends TerraformStack {
|
|
|
31
50
|
: this.props.domainName
|
|
32
51
|
}
|
|
33
52
|
|
|
53
|
+
protected determineRemoteBackend() {
|
|
54
|
+
const debug = this.node.tryGetContext('debug')
|
|
55
|
+
switch (this.props.remoteBackend?.type) {
|
|
56
|
+
case AzureRemoteBackend.azurerm:
|
|
57
|
+
new AzurermBackend(this, {
|
|
58
|
+
storageAccountName: this.props.remoteBackend.storageAccountName,
|
|
59
|
+
containerName: this.props.remoteBackend.containerName,
|
|
60
|
+
key: `${this.id}`,
|
|
61
|
+
subscriptionId: this.props.subscriptionId,
|
|
62
|
+
resourceGroupName: this.props.remoteBackend.resourceGroupName,
|
|
63
|
+
})
|
|
64
|
+
break
|
|
65
|
+
case AzureRemoteBackend.local:
|
|
66
|
+
if (debug) console.debug(`Using local backend for ${this.id}`)
|
|
67
|
+
break
|
|
68
|
+
default:
|
|
69
|
+
break
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
protected determineTenantId() {
|
|
74
|
+
this.tenantId = new DataAzurermClientConfig(this, 'current', {}).tenantId
|
|
75
|
+
}
|
|
76
|
+
|
|
34
77
|
/**
|
|
35
78
|
* @summary Utility method to determine if the initialisation is in development (dev) stage
|
|
36
79
|
* This is determined by the stage property injected via cdk context
|
|
@@ -35,9 +35,6 @@ export class CommonAzureStack extends TerraformStack {
|
|
|
35
35
|
this.determineStageContexts()
|
|
36
36
|
|
|
37
37
|
this.props = this.determineConstructProps(props)
|
|
38
|
-
|
|
39
|
-
/* initialise the construct */
|
|
40
|
-
this.construct = new CommonAzureConstruct(this, 'cdk-utils', this.props)
|
|
41
38
|
}
|
|
42
39
|
|
|
43
40
|
/**
|
|
@@ -55,6 +52,7 @@ export class CommonAzureStack extends TerraformStack {
|
|
|
55
52
|
skipStageForARecords: this.node.tryGetContext('skipStageForARecords'),
|
|
56
53
|
stage: this.node.tryGetContext('stage'),
|
|
57
54
|
subDomain: this.node.tryGetContext('subDomain'),
|
|
55
|
+
subscriptionId: this.node.tryGetContext('subscriptionId'),
|
|
58
56
|
}
|
|
59
57
|
}
|
|
60
58
|
|
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
import { AzurermProviderConfig } from '@cdktf/provider-azurerm/lib/provider'
|
|
2
2
|
import { BaseProps } from '../../common'
|
|
3
|
+
import { AzureRemoteBackend } from './constants'
|
|
4
|
+
import { AzurermBackendConfig } from 'cdktf'
|
|
3
5
|
|
|
4
6
|
/**
|
|
5
7
|
*/
|
|
6
8
|
export interface CommonAzureStackProps extends BaseProps, AzurermProviderConfig {
|
|
7
9
|
resourceGroupName?: string
|
|
10
|
+
remoteBackend?: AzureRemoteBackendProps
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface AzureRemoteBackendProps extends AzurermBackendConfig {
|
|
14
|
+
type: AzureRemoteBackend
|
|
8
15
|
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { DataAzurermResourceGroup } from '@cdktf/provider-azurerm/lib/data-azurerm-resource-group'
|
|
2
|
+
import { ApiManagement } from '@cdktf/provider-azurerm/lib/api-management'
|
|
3
|
+
import { CommonAzureConstruct } from '../../common'
|
|
4
|
+
import { createAzureTfOutput } from '../../utils'
|
|
5
|
+
import { ApiManagementProps } from './types'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @classdesc Provides operations on Azure Api Management
|
|
9
|
+
* - A new instance of this class is injected into {@link CommonAzureConstruct} constructor.
|
|
10
|
+
* - If a custom construct extends {@link CommonAzureConstruct}, an instance is available within the context.
|
|
11
|
+
* @example
|
|
12
|
+
* ```
|
|
13
|
+
* import { CommonAzureConstruct, CommonAzureStackProps } from '@gradientedge/cdk-utils'
|
|
14
|
+
*
|
|
15
|
+
* class CustomConstruct extends CommonAzureConstruct {
|
|
16
|
+
* constructor(parent: Construct, id: string, props: CommonAzureStackProps) {
|
|
17
|
+
* super(parent, id, props)
|
|
18
|
+
* this.props = props
|
|
19
|
+
* this.apiManagementManager.createApiManagement('MyApiManagement', this, props)
|
|
20
|
+
* }
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export class AzureApiManagementManager {
|
|
25
|
+
/**
|
|
26
|
+
* @summary Method to create a new api management
|
|
27
|
+
* @param id scoped id of the resource
|
|
28
|
+
* @param scope scope in which this resource is defined
|
|
29
|
+
* @param props api management properties
|
|
30
|
+
* @see [CDKTF Api management Module]{@link https://github.com/cdktf/cdktf-provider-azurerm/blob/main/docs/apiManagement.typescript.md}
|
|
31
|
+
*/
|
|
32
|
+
public createApiManagement(id: string, scope: CommonAzureConstruct, props: ApiManagementProps) {
|
|
33
|
+
if (!props) throw `Props undefined for ${id}`
|
|
34
|
+
|
|
35
|
+
const resourceGroup = new DataAzurermResourceGroup(scope, `${id}-am-rg`, {
|
|
36
|
+
name: scope.props.resourceGroupName
|
|
37
|
+
? `${scope.props.resourceGroupName}-${scope.props.stage}`
|
|
38
|
+
: `${props.resourceGroupName}-${scope.props.stage}`,
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
if (!resourceGroup) throw `Resource group undefined for ${id}`
|
|
42
|
+
|
|
43
|
+
const apiManagement = new ApiManagement(scope, `${id}-am`, {
|
|
44
|
+
...props,
|
|
45
|
+
name: `${props.name}-${scope.props.stage}`,
|
|
46
|
+
resourceGroupName: resourceGroup.name,
|
|
47
|
+
tags: props.tags ?? {
|
|
48
|
+
environment: scope.props.stage,
|
|
49
|
+
},
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
createAzureTfOutput(`${id}-apiManagementName`, scope, apiManagement.name)
|
|
53
|
+
createAzureTfOutput(`${id}-apiManagementFriendlyUniqueId`, scope, apiManagement.friendlyUniqueId)
|
|
54
|
+
createAzureTfOutput(`${id}-apiManagementId`, scope, apiManagement.id)
|
|
55
|
+
|
|
56
|
+
return apiManagement
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { DataAzurermResourceGroup } from '@cdktf/provider-azurerm/lib/data-azurerm-resource-group'
|
|
2
|
+
import { DataAzurermFunctionApp } from '@cdktf/provider-azurerm/lib/data-azurerm-function-app'
|
|
3
|
+
import { FunctionApp } from '@cdktf/provider-azurerm/lib/function-app'
|
|
4
|
+
import { FunctionAppFunction } from '@cdktf/provider-azurerm/lib/function-app-function'
|
|
5
|
+
import { CommonAzureConstruct } from '../../common'
|
|
6
|
+
import { createAzureTfOutput } from '../../utils'
|
|
7
|
+
import { FunctionAppProps, FunctionProps } from './types'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @classdesc Provides operations on Azure Functions
|
|
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.functionManager.createFunctionApp('MyFunctionApp', this, props)
|
|
22
|
+
* }
|
|
23
|
+
* }
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export class AzureFunctionManager {
|
|
27
|
+
/**
|
|
28
|
+
* @summary Method to create a new function app
|
|
29
|
+
* @param id scoped id of the resource
|
|
30
|
+
* @param scope scope in which this resource is defined
|
|
31
|
+
* @param props function app properties
|
|
32
|
+
* @see [CDKTF Function App Module]{@link https://github.com/cdktf/cdktf-provider-azurerm/blob/main/docs/functionApp.typescript.md}
|
|
33
|
+
*/
|
|
34
|
+
public createFunctionApp(id: string, scope: CommonAzureConstruct, props: FunctionAppProps) {
|
|
35
|
+
if (!props) throw `Props undefined for ${id}`
|
|
36
|
+
|
|
37
|
+
const resourceGroup = new DataAzurermResourceGroup(scope, `${id}-fa-rg`, {
|
|
38
|
+
name: scope.props.resourceGroupName
|
|
39
|
+
? `${scope.props.resourceGroupName}-${scope.props.stage}`
|
|
40
|
+
: `${props.resourceGroupName}-${scope.props.stage}`,
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
if (!resourceGroup) throw `Resource group undefined for ${id}`
|
|
44
|
+
|
|
45
|
+
const functionApp = new FunctionApp(scope, `${id}-fa`, {
|
|
46
|
+
...props,
|
|
47
|
+
name: `${props.name}-${scope.props.stage}`,
|
|
48
|
+
resourceGroupName: resourceGroup.name,
|
|
49
|
+
tags: props.tags ?? {
|
|
50
|
+
environment: scope.props.stage,
|
|
51
|
+
},
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
createAzureTfOutput(`${id}-functionAppName`, scope, functionApp.name)
|
|
55
|
+
createAzureTfOutput(`${id}-functionAppFriendlyUniqueId`, scope, functionApp.friendlyUniqueId)
|
|
56
|
+
createAzureTfOutput(`${id}-functionAppId`, scope, functionApp.id)
|
|
57
|
+
|
|
58
|
+
return functionApp
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* @summary Method to create a new function
|
|
63
|
+
* @param id scoped id of the resource
|
|
64
|
+
* @param scope scope in which this resource is defined
|
|
65
|
+
* @param props function properties
|
|
66
|
+
* @see [CDKTF Function Module]{@link https://github.com/cdktf/cdktf-provider-azurerm/blob/main/docs/functionAppFunction.typescript.md}
|
|
67
|
+
*/
|
|
68
|
+
public createFunction(id: string, scope: CommonAzureConstruct, props: FunctionProps) {
|
|
69
|
+
if (!props) throw `Props undefined for ${id}`
|
|
70
|
+
|
|
71
|
+
const resourceGroup = new DataAzurermResourceGroup(scope, `${id}-sb-rg`, {
|
|
72
|
+
name: scope.props.resourceGroupName
|
|
73
|
+
? `${scope.props.resourceGroupName}-${scope.props.stage}`
|
|
74
|
+
: `${props.resourceGroupName}-${scope.props.stage}`,
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
if (!resourceGroup) throw `Resource group undefined for ${id}`
|
|
78
|
+
|
|
79
|
+
const storageAccount = new DataAzurermFunctionApp(scope, `${id}-sa`, {
|
|
80
|
+
name: `${props.functionAppName}-${scope.props.stage}`,
|
|
81
|
+
resourceGroupName: resourceGroup.name,
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
const functionAppFunction = new FunctionAppFunction(scope, `${id}-fc`, {
|
|
85
|
+
...props,
|
|
86
|
+
name: `${props.name}-${scope.props.stage}`,
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
createAzureTfOutput(`${id}-functionName`, scope, functionAppFunction.name)
|
|
90
|
+
createAzureTfOutput(`${id}-functionFriendlyUniqueId`, scope, functionAppFunction.friendlyUniqueId)
|
|
91
|
+
createAzureTfOutput(`${id}-functionId`, scope, functionAppFunction.id)
|
|
92
|
+
|
|
93
|
+
return functionAppFunction
|
|
94
|
+
}
|
|
95
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { FunctionAppConfig } from '@cdktf/provider-azurerm/lib/function-app'
|
|
2
|
+
import { FunctionAppFunctionConfig } from '@cdktf/provider-azurerm/lib/function-app-function'
|
|
3
|
+
import { BaseAzureConfigProps } from '../../types'
|
|
4
|
+
|
|
5
|
+
export interface FunctionAppProps extends FunctionAppConfig {}
|
|
6
|
+
|
|
7
|
+
export interface FunctionProps extends BaseAzureConfigProps, FunctionAppFunctionConfig {
|
|
8
|
+
functionAppName: string
|
|
9
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { DataAzurermResourceGroup } from '@cdktf/provider-azurerm/lib/data-azurerm-resource-group'
|
|
2
|
+
import { KeyVault } from '@cdktf/provider-azurerm/lib/key-vault'
|
|
3
|
+
import { CommonAzureConstruct } from '../../common'
|
|
4
|
+
import { createAzureTfOutput } from '../../utils'
|
|
5
|
+
import { KeyVaultProps } from './types'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @classdesc Provides operations on Azure Key Vault
|
|
9
|
+
* - A new instance of this class is injected into {@link CommonAzureConstruct} constructor.
|
|
10
|
+
* - If a custom construct extends {@link CommonAzureConstruct}, an instance is available within the context.
|
|
11
|
+
* @example
|
|
12
|
+
* ```
|
|
13
|
+
* import { CommonAzureConstruct, CommonAzureStackProps } from '@gradientedge/cdk-utils'
|
|
14
|
+
*
|
|
15
|
+
* class CustomConstruct extends CommonAzureConstruct {
|
|
16
|
+
* constructor(parent: Construct, id: string, props: CommonAzureStackProps) {
|
|
17
|
+
* super(parent, id, props)
|
|
18
|
+
* this.props = props
|
|
19
|
+
* this.keyVaultManager.createKeyVault('MyKeyVault', this, props)
|
|
20
|
+
* }
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export class AzureKeyVaultManager {
|
|
25
|
+
/**
|
|
26
|
+
* @summary Method to create a new key vault
|
|
27
|
+
* @param id scoped id of the resource
|
|
28
|
+
* @param scope scope in which this resource is defined
|
|
29
|
+
* @param props key vault properties
|
|
30
|
+
* @see [CDKTF Key Vault Module]{@link https://github.com/cdktf/cdktf-provider-azurerm/blob/main/docs/keyVault.typescript.md}
|
|
31
|
+
*/
|
|
32
|
+
public createKeyVault(id: string, scope: CommonAzureConstruct, props: KeyVaultProps) {
|
|
33
|
+
if (!props) throw `Props undefined for ${id}`
|
|
34
|
+
|
|
35
|
+
const resourceGroup = new DataAzurermResourceGroup(scope, `${id}-kv-rg`, {
|
|
36
|
+
name: scope.props.resourceGroupName
|
|
37
|
+
? `${scope.props.resourceGroupName}-${scope.props.stage}`
|
|
38
|
+
: `${props.resourceGroupName}`,
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
if (!resourceGroup) throw `Resource group undefined for ${id}`
|
|
42
|
+
|
|
43
|
+
const keyVault = new KeyVault(scope, `${id}-kv`, {
|
|
44
|
+
...props,
|
|
45
|
+
name: `${props.name}-${scope.props.stage}`,
|
|
46
|
+
location: resourceGroup.location,
|
|
47
|
+
resourceGroupName: resourceGroup.name,
|
|
48
|
+
skuName: props.skuName ?? 'standard',
|
|
49
|
+
tags: props.tags ?? {
|
|
50
|
+
environment: scope.props.stage,
|
|
51
|
+
},
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
createAzureTfOutput(`${id}-keyVaultName`, scope, keyVault.name)
|
|
55
|
+
createAzureTfOutput(`${id}-keyVaultFriendlyUniqueId`, scope, keyVault.friendlyUniqueId)
|
|
56
|
+
createAzureTfOutput(`${id}-keyVaultId`, scope, keyVault.id)
|
|
57
|
+
|
|
58
|
+
return keyVault
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { ResourceGroup } from '@cdktf/provider-azurerm/lib/resource-group'
|
|
2
|
+
import { CommonAzureConstruct } from '../../common'
|
|
3
|
+
import { createAzureTfOutput } from '../../utils'
|
|
4
|
+
import { ResourceGroupProps } from './types'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @classdesc Provides operations on Azure Resource Group
|
|
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.resourceGroupManager.createResourceGroup('MyResourceGroup', this, props)
|
|
19
|
+
* }
|
|
20
|
+
* }
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export class AzureResourceGroupManager {
|
|
24
|
+
/**
|
|
25
|
+
* @summary Method to create a new resource group
|
|
26
|
+
* @param id scoped id of the resource
|
|
27
|
+
* @param scope scope in which this resource is defined
|
|
28
|
+
* @param props resource group properties
|
|
29
|
+
* @see [CDKTF Resource Group Module]{@link https://github.com/cdktf/cdktf-provider-azurerm/blob/main/docs/resourceGroup.typescript.md}
|
|
30
|
+
*/
|
|
31
|
+
public createResourceGroup(id: string, scope: CommonAzureConstruct, props: ResourceGroupProps) {
|
|
32
|
+
if (!props) throw `Props undefined for ${id}`
|
|
33
|
+
|
|
34
|
+
const resourceGroup = new ResourceGroup(scope, `${id}-rg`, {
|
|
35
|
+
...props,
|
|
36
|
+
name: props.name,
|
|
37
|
+
location: props.location,
|
|
38
|
+
tags: props.tags ?? {
|
|
39
|
+
environment: scope.props.stage,
|
|
40
|
+
},
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
createAzureTfOutput(`${id}-resourceGroupName`, scope, resourceGroup.name)
|
|
44
|
+
createAzureTfOutput(`${id}-resourceGroupFriendlyUniqueId`, scope, resourceGroup.friendlyUniqueId)
|
|
45
|
+
createAzureTfOutput(`${id}-resourceGroupId`, scope, resourceGroup.id)
|
|
46
|
+
|
|
47
|
+
return resourceGroup
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -58,6 +58,8 @@ export class AzureStorageManager {
|
|
|
58
58
|
createAzureTfOutput(`${id}-storageAccountName`, scope, storageAccount.name)
|
|
59
59
|
createAzureTfOutput(`${id}-storageAccountFriendlyUniqueId`, scope, storageAccount.friendlyUniqueId)
|
|
60
60
|
createAzureTfOutput(`${id}-storageAccountId`, scope, storageAccount.id)
|
|
61
|
+
|
|
62
|
+
return storageAccount
|
|
61
63
|
}
|
|
62
64
|
|
|
63
65
|
/**
|
|
@@ -92,6 +94,8 @@ export class AzureStorageManager {
|
|
|
92
94
|
createAzureTfOutput(`${id}-storageContainerName`, scope, storageContainer.name)
|
|
93
95
|
createAzureTfOutput(`${id}-storageContainerFriendlyUniqueId`, scope, storageContainer.friendlyUniqueId)
|
|
94
96
|
createAzureTfOutput(`${id}-storageContainerId`, scope, storageContainer.id)
|
|
97
|
+
|
|
98
|
+
return storageContainer
|
|
95
99
|
}
|
|
96
100
|
|
|
97
101
|
/**
|
|
@@ -132,5 +136,7 @@ export class AzureStorageManager {
|
|
|
132
136
|
createAzureTfOutput(`${id}-storageBlobName`, scope, storageBlob.name)
|
|
133
137
|
createAzureTfOutput(`${id}-storageBlobFriendlyUniqueId`, scope, storageBlob.friendlyUniqueId)
|
|
134
138
|
createAzureTfOutput(`${id}-storageBlobId`, scope, storageBlob.id)
|
|
139
|
+
|
|
140
|
+
return storageBlob
|
|
135
141
|
}
|
|
136
142
|
}
|