@gradientedge/cdk-utils 8.121.0 → 8.122.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/README.md +2 -1
- package/dist/src/lib/aws/common/construct.d.ts +0 -1
- package/dist/src/lib/aws/common/construct.js +6 -13
- package/dist/src/lib/aws/common/stack.js +2 -2
- package/dist/src/lib/aws/common/types.d.ts +2 -8
- package/dist/src/lib/aws/types/index.d.ts +6 -1
- package/dist/src/lib/aws/types/index.js +0 -15
- package/dist/src/lib/aws/utils/index.d.ts +13 -23
- package/dist/src/lib/aws/utils/index.js +37 -46
- package/dist/src/lib/azure/common/construct.d.ts +35 -0
- package/dist/src/lib/azure/common/construct.js +49 -0
- package/dist/src/lib/azure/common/index.d.ts +3 -0
- package/dist/src/lib/azure/common/index.js +19 -0
- package/dist/src/lib/azure/common/stack.d.ts +52 -0
- package/dist/src/lib/azure/common/stack.js +136 -0
- package/dist/src/lib/azure/common/types.d.ts +7 -0
- package/dist/src/lib/azure/index.d.ts +4 -0
- package/dist/src/lib/azure/index.js +20 -0
- package/dist/src/lib/azure/services/index.d.ts +1 -0
- package/dist/src/lib/azure/services/index.js +17 -0
- package/dist/src/lib/azure/services/storage/index.d.ts +2 -0
- package/dist/src/lib/azure/services/storage/index.js +18 -0
- package/dist/src/lib/azure/services/storage/main.d.ts +43 -0
- package/dist/src/lib/azure/services/storage/main.js +124 -0
- package/dist/src/lib/azure/services/storage/types.d.ts +10 -0
- package/dist/src/lib/azure/services/storage/types.js +2 -0
- package/dist/src/lib/azure/types/index.d.ts +3 -0
- package/dist/src/lib/azure/types/index.js +2 -0
- package/dist/src/lib/azure/utils/index.d.ts +3 -0
- package/dist/src/lib/azure/utils/index.js +20 -0
- package/dist/src/lib/common/construct.d.ts +29 -0
- package/dist/src/lib/common/construct.js +8 -0
- package/dist/src/lib/common/index.d.ts +5 -0
- package/dist/src/lib/common/index.js +29 -0
- package/dist/src/lib/common/stack.d.ts +21 -0
- package/dist/src/lib/common/stack.js +8 -0
- package/dist/src/lib/common/types.d.ts +9 -0
- package/dist/src/lib/common/types.js +2 -0
- package/dist/src/lib/common/utils.d.ts +26 -0
- package/dist/src/lib/common/utils.js +34 -0
- package/dist/src/lib/index.d.ts +2 -0
- package/dist/src/lib/index.js +2 -0
- package/package.json +3 -1
- package/setup.js +2 -0
- package/src/lib/aws/common/construct.ts +2 -13
- package/src/lib/aws/common/stack.ts +1 -1
- package/src/lib/aws/common/types.ts +2 -8
- package/src/lib/aws/types/index.ts +6 -1
- package/src/lib/aws/utils/index.ts +41 -29
- package/src/lib/azure/common/construct.ts +57 -0
- package/src/lib/azure/common/index.ts +3 -0
- package/src/lib/azure/common/stack.ts +145 -0
- package/src/lib/azure/common/types.ts +8 -0
- package/src/lib/azure/index.ts +4 -0
- package/src/lib/azure/services/index.ts +1 -0
- package/src/lib/azure/services/storage/index.ts +2 -0
- package/src/lib/azure/services/storage/main.ts +134 -0
- package/src/lib/azure/services/storage/types.ts +10 -0
- package/src/lib/azure/types/index.ts +3 -0
- package/src/lib/azure/utils/index.ts +23 -0
- package/src/lib/common/construct.ts +35 -0
- package/src/lib/common/index.ts +16 -0
- package/src/lib/common/stack.ts +26 -0
- package/src/lib/common/types.ts +9 -0
- package/src/lib/common/utils.ts +27 -0
- package/src/lib/index.ts +2 -0
- package/dist/src/lib/aws/types/aws/index.d.ts +0 -6
- package/dist/src/lib/aws/utils/aws/index.d.ts +0 -17
- package/dist/src/lib/aws/utils/aws/index.js +0 -40
- package/src/lib/aws/types/aws/index.ts +0 -6
- package/src/lib/aws/utils/aws/index.ts +0 -41
- /package/dist/src/lib/{aws/types/aws/index.js → azure/common/types.js} +0 -0
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import fs from 'fs'
|
|
2
|
+
import { CommonAzureConstruct } from './construct'
|
|
3
|
+
import { CommonAzureStackProps } from './types'
|
|
4
|
+
|
|
5
|
+
import appRoot from 'app-root-path'
|
|
6
|
+
import { App, TerraformStack } from 'cdktf'
|
|
7
|
+
import { isDevStage } from '../../common'
|
|
8
|
+
import { Construct } from 'constructs'
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @classdesc Common stack to use as a base for all higher level constructs.
|
|
12
|
+
* @example
|
|
13
|
+
* import { CommonAzureStack } from '@gradientedge/cdk-utils'
|
|
14
|
+
*
|
|
15
|
+
* class CustomStack extends CommonAzureStack {
|
|
16
|
+
* constructor(parent: App, name: string, props: StackProps) {
|
|
17
|
+
* super(parent, name, props)
|
|
18
|
+
* // provision resources
|
|
19
|
+
* }
|
|
20
|
+
* }
|
|
21
|
+
*/
|
|
22
|
+
export class CommonAzureStack extends TerraformStack {
|
|
23
|
+
construct: CommonAzureConstruct
|
|
24
|
+
props: CommonAzureStackProps
|
|
25
|
+
|
|
26
|
+
constructor(parent: Construct, name: string, props: CommonAzureStackProps) {
|
|
27
|
+
super(parent, name)
|
|
28
|
+
|
|
29
|
+
/* determine extra cdk contexts */
|
|
30
|
+
this.determineExtraContexts()
|
|
31
|
+
|
|
32
|
+
/* determine extra cdk stage contexts */
|
|
33
|
+
this.determineStageContexts()
|
|
34
|
+
|
|
35
|
+
this.props = this.determineConstructProps(props)
|
|
36
|
+
|
|
37
|
+
/* initialise the construct */
|
|
38
|
+
this.construct = new CommonAzureConstruct(this, 'cdk-utils', this.props)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @summary Method to determine the core CDK construct properties injected via context cdktf.json
|
|
43
|
+
* @param props The stack properties
|
|
44
|
+
* @returns The stack properties
|
|
45
|
+
*/
|
|
46
|
+
protected determineConstructProps(props: CommonAzureStackProps) {
|
|
47
|
+
return {
|
|
48
|
+
domainName: this.node.tryGetContext('domainName'),
|
|
49
|
+
extraContexts: this.node.tryGetContext('extraContexts'),
|
|
50
|
+
features: this.node.tryGetContext('features'),
|
|
51
|
+
name: this.node.tryGetContext('resourceGroupName'),
|
|
52
|
+
resourceGroupName: this.node.tryGetContext('resourceGroupName'),
|
|
53
|
+
skipStageForARecords: this.node.tryGetContext('skipStageForARecords'),
|
|
54
|
+
stage: this.node.tryGetContext('stage'),
|
|
55
|
+
subDomain: this.node.tryGetContext('subDomain'),
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* @summary Method to determine extra cdk contexts apart from the main cdktf.json
|
|
61
|
+
* - Sets the properties from the extra contexts into cdk node context
|
|
62
|
+
* - Primary use is to have layered config in separate files to enable easier maintenance and readability
|
|
63
|
+
*/
|
|
64
|
+
protected determineExtraContexts() {
|
|
65
|
+
const extraContexts = this.node.tryGetContext('extraContexts')
|
|
66
|
+
const debug = this.node.tryGetContext('debug')
|
|
67
|
+
|
|
68
|
+
if (!extraContexts) {
|
|
69
|
+
if (debug) console.debug(`No additional contexts provided. Using default context properties from cdktf.json`)
|
|
70
|
+
return
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
extraContexts.forEach((context: string) => {
|
|
74
|
+
const extraContextPath = `${appRoot.path}/${context}`
|
|
75
|
+
|
|
76
|
+
/* scenario where extra context is configured in cdk.json but absent in file system */
|
|
77
|
+
if (!fs.existsSync(extraContextPath)) throw `Extra context properties unavailable in path:${extraContextPath}`
|
|
78
|
+
|
|
79
|
+
/* read the extra properties */
|
|
80
|
+
const extraContextPropsBuffer = fs.readFileSync(extraContextPath)
|
|
81
|
+
if (debug) console.debug(`Adding additional contexts provided in ${extraContextPath}`)
|
|
82
|
+
|
|
83
|
+
/* parse as JSON properties */
|
|
84
|
+
const extraContextProps = JSON.parse(extraContextPropsBuffer.toString('utf-8'))
|
|
85
|
+
|
|
86
|
+
/* set each of the property into the cdk node context */
|
|
87
|
+
Object.keys(extraContextProps).forEach((propKey: any) => {
|
|
88
|
+
this.node.setContext(propKey, extraContextProps[propKey])
|
|
89
|
+
})
|
|
90
|
+
})
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* @summary Method to determine extra cdk stage contexts apart from the main cdktf.json
|
|
95
|
+
* - Sets the properties from the extra stage contexts into cdk node context
|
|
96
|
+
* - Primary use is to have layered config for each environment which is injected into the context
|
|
97
|
+
*/
|
|
98
|
+
protected determineStageContexts() {
|
|
99
|
+
const stage = this.node.tryGetContext('stage')
|
|
100
|
+
const stageContextPath = this.node.tryGetContext('stageContextPath') || 'cdkEnv'
|
|
101
|
+
const stageContextFilePath = `${appRoot.path}/${stageContextPath}/${stage}.json`
|
|
102
|
+
const debug = this.node.tryGetContext('debug')
|
|
103
|
+
|
|
104
|
+
if (isDevStage(stage)) {
|
|
105
|
+
if (debug) console.debug(`Development stage. Using default stage context properties`)
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/* alert default context usage when extra stage config is missing */
|
|
109
|
+
if (!fs.existsSync(stageContextFilePath)) {
|
|
110
|
+
if (debug) console.debug(`Stage specific context properties unavailable in path:${stageContextFilePath}`)
|
|
111
|
+
if (debug) console.debug(`Using default stage context properties for ${stage} stage`)
|
|
112
|
+
return
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/* read the extra properties */
|
|
116
|
+
const stageContextPropsBuffer = fs.readFileSync(stageContextFilePath)
|
|
117
|
+
if (debug) console.debug(`Adding additional stage contexts provided in ${stageContextFilePath}`)
|
|
118
|
+
|
|
119
|
+
/* parse as JSON properties */
|
|
120
|
+
const stageContextProps = JSON.parse(stageContextPropsBuffer.toString('utf-8'))
|
|
121
|
+
|
|
122
|
+
/* set each of the property into the cdk node context */
|
|
123
|
+
Object.keys(stageContextProps).forEach((propKey: any) => {
|
|
124
|
+
/* handle object, array properties */
|
|
125
|
+
if (typeof stageContextProps[propKey] === 'object' && !Array.isArray(stageContextProps[propKey])) {
|
|
126
|
+
this.node.setContext(propKey, {
|
|
127
|
+
...this.node.tryGetContext(propKey),
|
|
128
|
+
...stageContextProps[propKey],
|
|
129
|
+
})
|
|
130
|
+
} else {
|
|
131
|
+
/* handle all other primitive properties */
|
|
132
|
+
this.node.setContext(propKey, stageContextProps[propKey])
|
|
133
|
+
}
|
|
134
|
+
})
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* @summary Determine the fully qualified domain name based on domainName & subDomain
|
|
139
|
+
*/
|
|
140
|
+
protected fullyQualifiedDomain() {
|
|
141
|
+
const domainName = this.node.tryGetContext('domainName')
|
|
142
|
+
const subDomain = this.node.tryGetContext('subDomain')
|
|
143
|
+
return subDomain ? `${subDomain}.${domainName}` : domainName
|
|
144
|
+
}
|
|
145
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './storage'
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { DataAzurermResourceGroup } from '@cdktf/provider-azurerm/lib/data-azurerm-resource-group'
|
|
2
|
+
import { DataAzurermStorageAccount } from '@cdktf/provider-azurerm/lib/data-azurerm-storage-account'
|
|
3
|
+
import { DataAzurermStorageContainer } from '@cdktf/provider-azurerm/lib/data-azurerm-storage-container'
|
|
4
|
+
import { StorageAccount } from '@cdktf/provider-azurerm/lib/storage-account'
|
|
5
|
+
import { StorageBlob } from '@cdktf/provider-azurerm/lib/storage-blob'
|
|
6
|
+
import { StorageContainer } from '@cdktf/provider-azurerm/lib/storage-container'
|
|
7
|
+
import { CommonAzureConstruct } from '../../common'
|
|
8
|
+
import { createTfOutput } from '../../utils'
|
|
9
|
+
import { StorageAccountProps, StorageBlobProps, StorageContainerProps } from './types'
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @classdesc Provides operations on Azure Storage
|
|
13
|
+
* - A new instance of this class is injected into {@link CommonAzureConstruct} constructor.
|
|
14
|
+
* - If a custom construct extends {@link CommonAzureConstruct}, an instance is available within the context.
|
|
15
|
+
* @example
|
|
16
|
+
* ```
|
|
17
|
+
* import { CommonAzureConstruct, CommonAzureStackProps } from '@gradientedge/cdk-utils'
|
|
18
|
+
*
|
|
19
|
+
* class CustomConstruct extends CommonAzureConstruct {
|
|
20
|
+
* constructor(parent: Construct, id: string, props: CommonAzureStackProps) {
|
|
21
|
+
* super(parent, id, props)
|
|
22
|
+
* this.props = props
|
|
23
|
+
* this.storageManager.createStorageAccount('MyAccount', this, props)
|
|
24
|
+
* }
|
|
25
|
+
* }
|
|
26
|
+
* @see [CDKTF S3 Module]{@link https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_s3-readme.html}
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export class AzureStorageManager {
|
|
30
|
+
/**
|
|
31
|
+
* @summary Method to create a new storage account
|
|
32
|
+
* @param id scoped id of the resource
|
|
33
|
+
* @param scope scope in which this resource is defined
|
|
34
|
+
* @param props storage account properties
|
|
35
|
+
*/
|
|
36
|
+
public createStorageAccount(id: string, scope: CommonAzureConstruct, props: StorageAccountProps) {
|
|
37
|
+
if (!props) throw `Props undefined for ${id}`
|
|
38
|
+
|
|
39
|
+
const resourceGroup = new DataAzurermResourceGroup(scope, `${id}-sc-rg`, {
|
|
40
|
+
name: scope.props.resourceGroupName
|
|
41
|
+
? `${scope.props.resourceGroupName}-${scope.props.stage}`
|
|
42
|
+
: `${props.resourceGroupName}-${scope.props.stage}`,
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
if (!resourceGroup) throw `Resource group undefined for ${id}`
|
|
46
|
+
|
|
47
|
+
const storageAccount = new StorageAccount(scope, `${id}-sa`, {
|
|
48
|
+
...props,
|
|
49
|
+
accountTier: props.accountTier ?? 'Standard',
|
|
50
|
+
location: props.location ?? resourceGroup.location,
|
|
51
|
+
name: `${props.name}-${scope.props.stage}`,
|
|
52
|
+
resourceGroupName: resourceGroup.name,
|
|
53
|
+
tags: props.tags ?? {
|
|
54
|
+
environment: scope.props.stage,
|
|
55
|
+
},
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
createTfOutput(`${id}-storageAccountName`, scope, storageAccount.name)
|
|
59
|
+
createTfOutput(`${id}-storageAccountFriendlyUniqueId`, scope, storageAccount.friendlyUniqueId)
|
|
60
|
+
createTfOutput(`${id}-storageAccountId`, scope, storageAccount.id)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* @summary Method to create a new storage container
|
|
65
|
+
* @param id scoped id of the resource
|
|
66
|
+
* @param scope scope in which this resource is defined
|
|
67
|
+
* @param props storage container properties
|
|
68
|
+
*/
|
|
69
|
+
public createStorageContainer(id: string, scope: CommonAzureConstruct, props: StorageContainerProps) {
|
|
70
|
+
if (!props) throw `Props undefined for ${id}`
|
|
71
|
+
|
|
72
|
+
const resourceGroup = new DataAzurermResourceGroup(scope, `${id}-sc-rg`, {
|
|
73
|
+
name: scope.props.resourceGroupName
|
|
74
|
+
? `${scope.props.resourceGroupName}-${scope.props.stage}`
|
|
75
|
+
: `${props.resourceGroupName}-${scope.props.stage}`,
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
if (!resourceGroup) throw `Resource group undefined for ${id}`
|
|
79
|
+
|
|
80
|
+
const storageAccount = new DataAzurermStorageAccount(scope, `${id}-sa`, {
|
|
81
|
+
name: `${props.storageAccountName}-${scope.props.stage}`,
|
|
82
|
+
resourceGroupName: resourceGroup.name,
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
const storageContainer = new StorageContainer(scope, `${id}-sc`, {
|
|
86
|
+
...props,
|
|
87
|
+
name: `${props.name}-${scope.props.stage}`,
|
|
88
|
+
storageAccountName: storageAccount.name,
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
createTfOutput(`${id}-storageContainerName`, scope, storageContainer.name)
|
|
92
|
+
createTfOutput(`${id}-storageContainerFriendlyUniqueId`, scope, storageContainer.friendlyUniqueId)
|
|
93
|
+
createTfOutput(`${id}-storageContainerId`, scope, storageContainer.id)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* @summary Method to create a new storage blob
|
|
98
|
+
* @param id scoped id of the resource
|
|
99
|
+
* @param scope scope in which this resource is defined
|
|
100
|
+
* @param props storage blob properties
|
|
101
|
+
*/
|
|
102
|
+
public createStorageBlob(id: string, scope: CommonAzureConstruct, props: StorageBlobProps) {
|
|
103
|
+
if (!props) throw `Props undefined for ${id}`
|
|
104
|
+
|
|
105
|
+
const resourceGroup = new DataAzurermResourceGroup(scope, `${id}-sb-rg`, {
|
|
106
|
+
name: scope.props.resourceGroupName
|
|
107
|
+
? `${scope.props.resourceGroupName}-${scope.props.stage}`
|
|
108
|
+
: `${props.resourceGroupName}-${scope.props.stage}`,
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
if (!resourceGroup) throw `Resource group undefined for ${id}`
|
|
112
|
+
|
|
113
|
+
const storageAccount = new DataAzurermStorageAccount(scope, `${id}-sa`, {
|
|
114
|
+
name: `${props.storageAccountName}-${scope.props.stage}`,
|
|
115
|
+
resourceGroupName: resourceGroup.name,
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
const storageContainer = new DataAzurermStorageContainer(scope, `${id}-sc`, {
|
|
119
|
+
name: `${props.storageContainerName}-${scope.props.stage}`,
|
|
120
|
+
storageAccountName: storageAccount.name,
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
const storageBlob = new StorageBlob(scope, `${id}-sb`, {
|
|
124
|
+
...props,
|
|
125
|
+
name: `${props.name}-${scope.props.stage}`,
|
|
126
|
+
storageAccountName: storageAccount.name,
|
|
127
|
+
storageContainerName: storageContainer.name,
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
createTfOutput(`${id}-storageBlobName`, scope, storageBlob.name)
|
|
131
|
+
createTfOutput(`${id}-storageBlobFriendlyUniqueId`, scope, storageBlob.friendlyUniqueId)
|
|
132
|
+
createTfOutput(`${id}-storageBlobId`, scope, storageBlob.id)
|
|
133
|
+
}
|
|
134
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { StorageAccountConfig } from '@cdktf/provider-azurerm/lib/storage-account'
|
|
2
|
+
import { StorageBlobConfig } from '@cdktf/provider-azurerm/lib/storage-blob'
|
|
3
|
+
import { StorageContainerConfig } from '@cdktf/provider-azurerm/lib/storage-container'
|
|
4
|
+
import { BaseConfigProps } from '../../types'
|
|
5
|
+
|
|
6
|
+
export interface StorageAccountProps extends StorageAccountConfig {}
|
|
7
|
+
|
|
8
|
+
export interface StorageContainerProps extends BaseConfigProps, StorageContainerConfig {}
|
|
9
|
+
|
|
10
|
+
export interface StorageBlobProps extends BaseConfigProps, StorageBlobConfig {}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { TerraformOutput } from 'cdktf'
|
|
2
|
+
import _ from 'lodash'
|
|
3
|
+
import { CommonAzureConstruct } from '../common'
|
|
4
|
+
|
|
5
|
+
export const createTfOutput = (
|
|
6
|
+
id: string,
|
|
7
|
+
scope: CommonAzureConstruct,
|
|
8
|
+
value?: string,
|
|
9
|
+
description?: string,
|
|
10
|
+
sensitive?: boolean,
|
|
11
|
+
overrideId = true
|
|
12
|
+
) => {
|
|
13
|
+
const output = new TerraformOutput(scope, id, {
|
|
14
|
+
description,
|
|
15
|
+
sensitive,
|
|
16
|
+
value,
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
if (overrideId) {
|
|
20
|
+
output.overrideLogicalId(_.camelCase(id))
|
|
21
|
+
}
|
|
22
|
+
return output
|
|
23
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Construct } from 'constructs'
|
|
2
|
+
import { BaseProps } from './types'
|
|
3
|
+
|
|
4
|
+
export abstract class BaseConstruct extends Construct {
|
|
5
|
+
props: BaseProps
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @summary Determine the fully qualified domain name based on domainName & subDomain
|
|
9
|
+
*/
|
|
10
|
+
public abstract determineFullyQualifiedDomain(): void
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @summary Utility method to determine if the initialisation is in development (dev) stage
|
|
14
|
+
* This is determined by the stage property injected via cdk context
|
|
15
|
+
*/
|
|
16
|
+
public abstract isDevelopmentStage(): void
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @summary Utility method to determine if the initialisation is in test (tst) stage
|
|
20
|
+
* This is determined by the stage property injected via cdk context
|
|
21
|
+
*/
|
|
22
|
+
public abstract isTestStage(): void
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @summary Utility method to determine if the initialisation is in uat (uat) stage
|
|
26
|
+
* This is determined by the stage property injected via cdk context
|
|
27
|
+
*/
|
|
28
|
+
public abstract isUatStage(): void
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @summary Utility method to determine if the initialisation is in production (prd) stage
|
|
32
|
+
* This is determined by the stage property injected via cdk context
|
|
33
|
+
*/
|
|
34
|
+
public abstract isProductionStage(): void
|
|
35
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export * from './construct'
|
|
2
|
+
export * from './stack'
|
|
3
|
+
export * from './types'
|
|
4
|
+
export * from './utils'
|
|
5
|
+
|
|
6
|
+
export const applyMixins = (derivedCtor: any, constructors: any[]) => {
|
|
7
|
+
constructors.forEach(baseCtor => {
|
|
8
|
+
Object.getOwnPropertyNames(baseCtor.prototype).forEach(name => {
|
|
9
|
+
Object.defineProperty(
|
|
10
|
+
derivedCtor.prototype,
|
|
11
|
+
name,
|
|
12
|
+
Object.getOwnPropertyDescriptor(baseCtor.prototype, name) || Object.create(null)
|
|
13
|
+
)
|
|
14
|
+
})
|
|
15
|
+
})
|
|
16
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Construct } from 'constructs'
|
|
2
|
+
import { BaseProps } from './types'
|
|
3
|
+
|
|
4
|
+
export abstract class BaseStack extends Construct {
|
|
5
|
+
props: BaseProps
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @summary Method to determine the core CDK construct properties injected via context cdktf.json
|
|
9
|
+
*/
|
|
10
|
+
protected abstract determineConstructProps(props: BaseProps): void
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @summary Method to determine extra cdk contexts apart from the main cdktf.json
|
|
14
|
+
*/
|
|
15
|
+
public abstract determineExtraContexts(): void
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @summary Method to determine extra cdk stage contexts apart from the main cdktf.json
|
|
19
|
+
*/
|
|
20
|
+
public abstract determineStageContexts(): void
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @summary Determine the fully qualified domain name based on domainName & subDomain
|
|
24
|
+
*/
|
|
25
|
+
public abstract fullyQualifiedDomain(): void
|
|
26
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*/
|
|
3
|
+
export enum LogLevel {
|
|
4
|
+
DEBUG = 'DEBUG',
|
|
5
|
+
INFO = 'INFO',
|
|
6
|
+
WARNING = 'WARNING',
|
|
7
|
+
TRACE = 'TRACE',
|
|
8
|
+
ERROR = 'ERROR',
|
|
9
|
+
CRITICAL = 'CRITICAL',
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @param stage
|
|
14
|
+
*/
|
|
15
|
+
export const isDevStage = (stage: string) => stage === 'dev'
|
|
16
|
+
/**
|
|
17
|
+
* @param stage
|
|
18
|
+
*/
|
|
19
|
+
export const isTestStage = (stage: string) => stage === 'tst'
|
|
20
|
+
/**
|
|
21
|
+
* @param stage
|
|
22
|
+
*/
|
|
23
|
+
export const isUatStage = (stage: string) => stage === 'uat'
|
|
24
|
+
/**
|
|
25
|
+
* @param stage
|
|
26
|
+
*/
|
|
27
|
+
export const isPrdStage = (stage: string) => stage === 'prd'
|
package/src/lib/index.ts
CHANGED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { AwsCredentialIdentityProvider } from '@aws-sdk/types';
|
|
2
|
-
import { CfnOutput } from 'aws-cdk-lib';
|
|
3
|
-
import { CommonConstruct } from '../../common';
|
|
4
|
-
/**
|
|
5
|
-
* @summary Helper method to add CloudFormation outputs from the construct
|
|
6
|
-
* @param id scoped id of the resource
|
|
7
|
-
* @param scope scope in which this resource is defined
|
|
8
|
-
* @param value the value of the exported output
|
|
9
|
-
* @param description optional description for the output
|
|
10
|
-
* @param overrideId Flag which indicates whether to override the default logical id of the output
|
|
11
|
-
* @returns The CloudFormation output
|
|
12
|
-
*/
|
|
13
|
-
export declare function createCfnOutput(id: string, scope: CommonConstruct, value?: string, description?: string, overrideId?: boolean): CfnOutput;
|
|
14
|
-
/**
|
|
15
|
-
*
|
|
16
|
-
*/
|
|
17
|
-
export declare function determineCredentials(): AwsCredentialIdentityProvider;
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.determineCredentials = exports.createCfnOutput = void 0;
|
|
7
|
-
const credential_providers_1 = require("@aws-sdk/credential-providers");
|
|
8
|
-
const aws_cdk_lib_1 = require("aws-cdk-lib");
|
|
9
|
-
const lodash_1 = __importDefault(require("lodash"));
|
|
10
|
-
/**
|
|
11
|
-
* @summary Helper method to add CloudFormation outputs from the construct
|
|
12
|
-
* @param id scoped id of the resource
|
|
13
|
-
* @param scope scope in which this resource is defined
|
|
14
|
-
* @param value the value of the exported output
|
|
15
|
-
* @param description optional description for the output
|
|
16
|
-
* @param overrideId Flag which indicates whether to override the default logical id of the output
|
|
17
|
-
* @returns The CloudFormation output
|
|
18
|
-
*/
|
|
19
|
-
function createCfnOutput(id, scope, value, description, overrideId = true) {
|
|
20
|
-
const camelName = lodash_1.default.camelCase(id);
|
|
21
|
-
const output = new aws_cdk_lib_1.CfnOutput(scope, id, {
|
|
22
|
-
description,
|
|
23
|
-
exportName: `${scope.props.stackName}-${camelName}`,
|
|
24
|
-
value: value ?? '',
|
|
25
|
-
});
|
|
26
|
-
if (overrideId) {
|
|
27
|
-
output.overrideLogicalId(camelName);
|
|
28
|
-
}
|
|
29
|
-
return output;
|
|
30
|
-
}
|
|
31
|
-
exports.createCfnOutput = createCfnOutput;
|
|
32
|
-
/**
|
|
33
|
-
*
|
|
34
|
-
*/
|
|
35
|
-
function determineCredentials() {
|
|
36
|
-
if (process.env.AWS_PROFILE)
|
|
37
|
-
return (0, credential_providers_1.fromIni)();
|
|
38
|
-
return (0, credential_providers_1.fromEnv)();
|
|
39
|
-
}
|
|
40
|
-
exports.determineCredentials = determineCredentials;
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { fromEnv, fromIni } from '@aws-sdk/credential-providers'
|
|
2
|
-
import { AwsCredentialIdentityProvider } from '@aws-sdk/types'
|
|
3
|
-
import { CfnOutput } from 'aws-cdk-lib'
|
|
4
|
-
import _ from 'lodash'
|
|
5
|
-
import { CommonConstruct } from '../../common'
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* @summary Helper method to add CloudFormation outputs from the construct
|
|
9
|
-
* @param id scoped id of the resource
|
|
10
|
-
* @param scope scope in which this resource is defined
|
|
11
|
-
* @param value the value of the exported output
|
|
12
|
-
* @param description optional description for the output
|
|
13
|
-
* @param overrideId Flag which indicates whether to override the default logical id of the output
|
|
14
|
-
* @returns The CloudFormation output
|
|
15
|
-
*/
|
|
16
|
-
export function createCfnOutput(
|
|
17
|
-
id: string,
|
|
18
|
-
scope: CommonConstruct,
|
|
19
|
-
value?: string,
|
|
20
|
-
description?: string,
|
|
21
|
-
overrideId = true
|
|
22
|
-
): CfnOutput {
|
|
23
|
-
const camelName = _.camelCase(id)
|
|
24
|
-
const output = new CfnOutput(scope, id, {
|
|
25
|
-
description,
|
|
26
|
-
exportName: `${scope.props.stackName}-${camelName}`,
|
|
27
|
-
value: value ?? '',
|
|
28
|
-
})
|
|
29
|
-
if (overrideId) {
|
|
30
|
-
output.overrideLogicalId(camelName)
|
|
31
|
-
}
|
|
32
|
-
return output
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
*
|
|
37
|
-
*/
|
|
38
|
-
export function determineCredentials(): AwsCredentialIdentityProvider {
|
|
39
|
-
if (process.env.AWS_PROFILE) return fromIni()
|
|
40
|
-
return fromEnv()
|
|
41
|
-
}
|
|
File without changes
|