Skip to content

Commit 4c94215

Browse files
Merge pull request #724 from gradientedge/feat/MAM-4_azure_constrcuts
feat(azure): MAM-4 azure constructs
2 parents 7571fb5 + 59a076f commit 4c94215

25 files changed

+1033
-490
lines changed

pnpm-lock.yaml

+432-455
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/lib/azure/common/construct.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ import {
99
AzureApiManagementManager,
1010
AzureFunctionManager,
1111
AzureResourceGroupManager,
12+
AzureAppServiceManager,
13+
AzureApplicationInsightsManager,
14+
AzureAppConfigurationManager,
1215
} from '../services'
1316
import { CommonAzureStackProps } from './types'
1417
import { AzureRemoteBackend } from './constants'
@@ -18,7 +21,10 @@ export class CommonAzureConstruct extends TerraformStack {
1821
id: string
1922
fullyQualifiedDomainName: string
2023
tenantId: string
21-
apiManagementtManager: AzureApiManagementManager
24+
apiManagementManager: AzureApiManagementManager
25+
appServiceManager: AzureAppServiceManager
26+
applicationInsightsManager: AzureApplicationInsightsManager
27+
appConfigurationManager: AzureAppConfigurationManager
2228
functiontManager: AzureFunctionManager
2329
keyVaultManager: AzureKeyVaultManager
2430
resourceGroupManager: AzureResourceGroupManager
@@ -29,7 +35,10 @@ export class CommonAzureConstruct extends TerraformStack {
2935
this.props = props
3036
this.id = id
3137

32-
this.apiManagementtManager = new AzureApiManagementManager()
38+
this.apiManagementManager = new AzureApiManagementManager()
39+
this.appServiceManager = new AzureAppServiceManager()
40+
this.applicationInsightsManager = new AzureApplicationInsightsManager()
41+
this.appConfigurationManager = new AzureAppConfigurationManager()
3342
this.functiontManager = new AzureFunctionManager()
3443
this.keyVaultManager = new AzureKeyVaultManager()
3544
this.resourceGroupManager = new AzureResourceGroupManager()

src/lib/azure/services/api-management/main.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export class AzureApiManagementManager {
3535
const resourceGroup = new DataAzurermResourceGroup(scope, `${id}-am-rg`, {
3636
name: scope.props.resourceGroupName
3737
? `${scope.props.resourceGroupName}-${scope.props.stage}`
38-
: `${props.resourceGroupName}-${scope.props.stage}`,
38+
: `${props.resourceGroupName}`,
3939
})
4040

4141
if (!resourceGroup) throw `Resource group undefined for ${id}`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './main'
2+
export * from './types'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { DataAzurermResourceGroup } from '@cdktf/provider-azurerm/lib/data-azurerm-resource-group'
2+
import { AppConfiguration } from '@cdktf/provider-azurerm/lib/app-configuration'
3+
import { CommonAzureConstruct } from '../../common'
4+
import { createAzureTfOutput } from '../../utils'
5+
import { AppConfigurationProps } from './types'
6+
7+
/**
8+
* @classdesc Provides operations on Azure App Configuration
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.appConfigurationManager.createAppConfiguration('MyAppConfiguration', this, props)
20+
* }
21+
* }
22+
* ```
23+
*/
24+
export class AzureAppConfigurationManager {
25+
/**
26+
* @summary Method to create a new app configuration
27+
* @param id scoped id of the resource
28+
* @param scope scope in which this resource is defined
29+
* @param props app configuration properties
30+
* @see [CDKTF App Configuration plan Module]{@link https://github.com/cdktf/cdktf-provider-azurerm/blob/main/docs/appConfiguration.typescript.md}
31+
*/
32+
public createAppConfiguration(id: string, scope: CommonAzureConstruct, props: AppConfigurationProps) {
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}`,
39+
})
40+
41+
if (!resourceGroup) throw `Resource group undefined for ${id}`
42+
43+
const appConfiguration = new AppConfiguration(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}-appConfigurationName`, scope, appConfiguration.name)
53+
createAzureTfOutput(`${id}-appConfigurationFriendlyUniqueId`, scope, appConfiguration.friendlyUniqueId)
54+
createAzureTfOutput(`${id}-appConfigurationId`, scope, appConfiguration.id)
55+
56+
return appConfiguration
57+
}
58+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { AppConfigurationConfig } from '@cdktf/provider-azurerm/lib/app-configuration'
2+
3+
export interface AppConfigurationProps extends AppConfigurationConfig {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './main'
2+
export * from './types'
+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { DataAzurermResourceGroup } from '@cdktf/provider-azurerm/lib/data-azurerm-resource-group'
2+
import { ServicePlan } from '@cdktf/provider-azurerm/lib/service-plan'
3+
import { CommonAzureConstruct } from '../../common'
4+
import { createAzureTfOutput } from '../../utils'
5+
import { ServicePlanProps } from './types'
6+
7+
/**
8+
* @classdesc Provides operations on Azure App Service
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.appServiceManager.createAppService('MyAppService', this, props)
20+
* }
21+
* }
22+
* ```
23+
*/
24+
export class AzureAppServiceManager {
25+
/**
26+
* @summary Method to create a new app service plan
27+
* @param id scoped id of the resource
28+
* @param scope scope in which this resource is defined
29+
* @param props app service plan properties
30+
* @see [CDKTF App service plan Module]{@link https://github.com/cdktf/cdktf-provider-azurerm/blob/main/docs/appServicePlan.typescript.md}
31+
*/
32+
public createAppServicePlan(id: string, scope: CommonAzureConstruct, props: ServicePlanProps) {
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}`,
39+
})
40+
41+
if (!resourceGroup) throw `Resource group undefined for ${id}`
42+
43+
const appServicePlan = new ServicePlan(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}-appServicePlanName`, scope, appServicePlan.name)
53+
createAzureTfOutput(`${id}-appServicePlanFriendlyUniqueId`, scope, appServicePlan.friendlyUniqueId)
54+
createAzureTfOutput(`${id}-appServicePlanId`, scope, appServicePlan.id)
55+
56+
return appServicePlan
57+
}
58+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { ServicePlanConfig } from '@cdktf/provider-azurerm/lib/service-plan'
2+
3+
export interface ServicePlanProps extends ServicePlanConfig {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './main'
2+
export * from './types'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { DataAzurermResourceGroup } from '@cdktf/provider-azurerm/lib/data-azurerm-resource-group'
2+
import { ApplicationInsights } from '@cdktf/provider-azurerm/lib/application-insights'
3+
import { CommonAzureConstruct } from '../../common'
4+
import { createAzureTfOutput } from '../../utils'
5+
import { ApplicationInsightsProps } from './types'
6+
7+
/**
8+
* @classdesc Provides operations on Azure Application Insights
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.applicationInsightseManager.createApplicationInsights('MyApplicationInsights', this, props)
20+
* }
21+
* }
22+
* ```
23+
*/
24+
export class AzureApplicationInsightsManager {
25+
/**
26+
* @summary Method to create a new application insights
27+
* @param id scoped id of the resource
28+
* @param scope scope in which this resource is defined
29+
* @param props application insights properties
30+
* @see [CDKTF Application insights Module]{@link https://github.com/cdktf/cdktf-provider-azurerm/blob/main/docs/applicationInsights.typescript.md}
31+
*/
32+
public createApplicationInsights(id: string, scope: CommonAzureConstruct, props: ApplicationInsightsProps) {
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}`,
39+
})
40+
41+
if (!resourceGroup) throw `Resource group undefined for ${id}`
42+
43+
const applicationInsights = new ApplicationInsights(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}-applicationInsightsName`, scope, applicationInsights.name)
53+
createAzureTfOutput(`${id}-applicationInsightsFriendlyUniqueId`, scope, applicationInsights.friendlyUniqueId)
54+
createAzureTfOutput(`${id}-applicationInsightsId`, scope, applicationInsights.id)
55+
56+
return applicationInsights
57+
}
58+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { ApplicationInsightsConfig } from '@cdktf/provider-azurerm/lib/application-insights'
2+
3+
export interface ApplicationInsightsProps extends ApplicationInsightsConfig {}

src/lib/azure/services/function/main.ts

+4-17
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
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'
2+
import { LinuxFunctionApp } from '@cdktf/provider-azurerm/lib/linux-function-app'
43
import { FunctionAppFunction } from '@cdktf/provider-azurerm/lib/function-app-function'
54
import { CommonAzureConstruct } from '../../common'
65
import { createAzureTfOutput } from '../../utils'
@@ -37,12 +36,12 @@ export class AzureFunctionManager {
3736
const resourceGroup = new DataAzurermResourceGroup(scope, `${id}-fa-rg`, {
3837
name: scope.props.resourceGroupName
3938
? `${scope.props.resourceGroupName}-${scope.props.stage}`
40-
: `${props.resourceGroupName}-${scope.props.stage}`,
39+
: `${props.resourceGroupName}`,
4140
})
4241

4342
if (!resourceGroup) throw `Resource group undefined for ${id}`
4443

45-
const functionApp = new FunctionApp(scope, `${id}-fa`, {
44+
const functionApp = new LinuxFunctionApp(scope, `${id}-fa`, {
4645
...props,
4746
name: `${props.name}-${scope.props.stage}`,
4847
resourceGroupName: resourceGroup.name,
@@ -68,22 +67,10 @@ export class AzureFunctionManager {
6867
public createFunction(id: string, scope: CommonAzureConstruct, props: FunctionProps) {
6968
if (!props) throw `Props undefined for ${id}`
7069

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-
8470
const functionAppFunction = new FunctionAppFunction(scope, `${id}-fc`, {
8571
...props,
8672
name: `${props.name}-${scope.props.stage}`,
73+
configJson: JSON.stringify(props.configJson || {}),
8774
})
8875

8976
createAzureTfOutput(`${id}-functionName`, scope, functionAppFunction.name)
+3-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
import { FunctionAppConfig } from '@cdktf/provider-azurerm/lib/function-app'
1+
import { LinuxFunctionAppConfig } from '@cdktf/provider-azurerm/lib/linux-function-app'
22
import { FunctionAppFunctionConfig } from '@cdktf/provider-azurerm/lib/function-app-function'
33
import { BaseAzureConfigProps } from '../../types'
44

5-
export interface FunctionAppProps extends FunctionAppConfig {}
5+
export interface FunctionAppProps extends LinuxFunctionAppConfig {}
66

7-
export interface FunctionProps extends BaseAzureConfigProps, FunctionAppFunctionConfig {
8-
functionAppName: string
9-
}
7+
export interface FunctionProps extends FunctionAppFunctionConfig {}

src/lib/azure/services/index.ts

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
export * from './api-management'
2+
export * from './app-configuration'
3+
export * from './app-service'
4+
export * from './application-insights'
25
export * from './function'
36
export * from './key-vault'
47
export * from './resource-group'

src/lib/azure/services/storage/main.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export class AzureStorageManager {
3939
const resourceGroup = new DataAzurermResourceGroup(scope, `${id}-sc-rg`, {
4040
name: scope.props.resourceGroupName
4141
? `${scope.props.resourceGroupName}-${scope.props.stage}`
42-
: `${props.resourceGroupName}-${scope.props.stage}`,
42+
: `${props.resourceGroupName}`,
4343
})
4444

4545
if (!resourceGroup) throw `Resource group undefined for ${id}`
@@ -48,7 +48,7 @@ export class AzureStorageManager {
4848
...props,
4949
accountTier: props.accountTier ?? 'Standard',
5050
location: props.location ?? resourceGroup.location,
51-
name: `${props.name}-${scope.props.stage}`,
51+
name: `${props.name}-${scope.props.stage}`.replace(/\W/g, '').toLowerCase(),
5252
resourceGroupName: resourceGroup.name,
5353
tags: props.tags ?? {
5454
environment: scope.props.stage,
@@ -75,7 +75,7 @@ export class AzureStorageManager {
7575
const resourceGroup = new DataAzurermResourceGroup(scope, `${id}-sc-rg`, {
7676
name: scope.props.resourceGroupName
7777
? `${scope.props.resourceGroupName}-${scope.props.stage}`
78-
: `${props.resourceGroupName}-${scope.props.stage}`,
78+
: `${props.resourceGroupName}`,
7979
})
8080

8181
if (!resourceGroup) throw `Resource group undefined for ${id}`
@@ -111,7 +111,7 @@ export class AzureStorageManager {
111111
const resourceGroup = new DataAzurermResourceGroup(scope, `${id}-sb-rg`, {
112112
name: scope.props.resourceGroupName
113113
? `${scope.props.resourceGroupName}-${scope.props.stage}`
114-
: `${props.resourceGroupName}-${scope.props.stage}`,
114+
: `${props.resourceGroupName}`,
115115
})
116116

117117
if (!resourceGroup) throw `Resource group undefined for ${id}`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"testAppConfiguration": {
3+
"name": "test-app-configuration"
4+
}
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"testAppServicePlan": {
3+
"name": "test-app-service-plan"
4+
}
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"testApplicationInsights": {
3+
"name": "test-application-insights"
4+
}
5+
}

src/test/azure/common/common-azure-construct.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ describe('TestAzureCommonConstruct', () => {
165165
expect(construct).toHaveResourceWithProperties(StorageAccount, {
166166
account_tier: 'Standard',
167167
location: '${data.azurerm_resource_group.test-storage-account-dev-sc-rg.location}',
168-
name: 'test-storage-account-dev',
168+
name: 'teststorageaccountdev',
169169
resource_group_name: '${data.azurerm_resource_group.test-storage-account-dev-sc-rg.name}',
170170
tags: {
171171
environment: 'dev',

src/test/azure/common/services/api-management-manager.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class TestCommonConstruct extends CommonAzureConstruct {
5252

5353
constructor(parent: Construct, name: string, props: TestAzureStackProps) {
5454
super(parent, name, props)
55-
this.apiManagementtManager.createApiManagement(
55+
this.apiManagementManager.createApiManagement(
5656
`test-api-management-${this.props.stage}`,
5757
this,
5858
this.props.testApiManagement

0 commit comments

Comments
 (0)