1- import { Stack , type StackProps , CfnOutput } from 'aws-cdk-lib' ;
1+ import * as cdk from 'aws-cdk-lib' ;
22import { type Construct } from 'constructs' ;
3- import { type ApiKeySSMParameterNames } from '../interfaces/api-key-ssm-parameter-names' ;
4- import { TenantApiKey } from './tenant-api-key' ;
53import { Table , AttributeType } from 'aws-cdk-lib/aws-dynamodb' ;
64import { PolicyDocument } from 'aws-cdk-lib/aws-iam' ;
75import { EventBus } from 'aws-cdk-lib/aws-events' ;
6+ import * as fs from 'fs' ;
87import { UserInterface } from './user-interface' ;
98import { CoreAppPlaneNag } from '../cdknag/core-app-plane-nag' ;
10- import * as fs from 'fs' ;
11- import * as core_app_plane from '@cdklabs/sbt-aws' ;
12- import { type CoreApplicationPlaneJobRunnerProps , DetailType , EventManager } from '@cdklabs/sbt-aws' ;
9+ import * as sbt from '@cdklabs/sbt-aws' ;
1310
14- interface CoreAppPlaneStackProps extends StackProps {
15- ApiKeySSMParameterNames : ApiKeySSMParameterNames
16- apiKeyPlatinumTierParameter : string
17- apiKeyPremiumTierParameter : string
18- apiKeyAdvancedTierParameter : string
19- apiKeyBasicTierParameter : string
20- eventBusArn : string
11+ interface CoreAppPlaneStackProps extends cdk . StackProps {
12+ eventManager : sbt . IEventManager
2113 systemAdminEmail : string
2214 regApiGatewayUrl : string
2315}
2416
25- export class CoreAppPlaneStack extends Stack {
17+ export class CoreAppPlaneStack extends cdk . Stack {
2618 public readonly userInterface : UserInterface ;
2719 public readonly tenantMappingTable : Table ;
2820 constructor ( scope : Construct , id : string , props : CoreAppPlaneStackProps ) {
@@ -34,8 +26,7 @@ export class CoreAppPlaneStack extends Stack {
3426 partitionKey : { name : 'tenantId' , type : AttributeType . STRING }
3527 } ) ;
3628
37- const provisioningJobRunnerProps : CoreApplicationPlaneJobRunnerProps = {
38- name : 'provisioning' ,
29+ const provisioningJobRunnerProps = {
3930 permissions : PolicyDocument . fromJson (
4031 JSON . parse ( `
4132{
@@ -53,28 +44,26 @@ export class CoreAppPlaneStack extends Stack {
5344` )
5445 ) ,
5546 script : fs . readFileSync ( '../scripts/provision-tenant.sh' , 'utf8' ) ,
56- outgoingEvent : DetailType . PROVISION_SUCCESS ,
57- incomingEvent : DetailType . ONBOARDING_REQUEST ,
58-
59- postScript : '' ,
60- environmentStringVariablesFromIncomingEvent : [
61- 'tenantId' ,
62- 'tier' ,
63- 'tenantName' ,
64- 'email' ,
65- 'tenantStatus'
47+ environmentStringVariablesFromIncomingEvent : [ 'tenantId' , 'tier' , 'tenantName' , 'email' ] ,
48+ environmentVariablesToOutgoingEvent : [
49+ 'tenantConfig' ,
50+ 'tenantStatus' ,
51+ 'prices' , // added so we don't lose it for targets beyond provisioning (ex. billing)
52+ 'tenantName' , // added so we don't lose it for targets beyond provisioning (ex. billing)
53+ 'email' , // added so we don't lose it for targets beyond provisioning (ex. billing)
6654 ] ,
67- environmentVariablesToOutgoingEvent : [ 'tenantConfig' , 'tenantStatus' ] ,
6855 scriptEnvironmentVariables : {
69- // CDK_PARAM_SYSTEM_ADMIN_EMAIL is required - as part of deploying the bootstrap-template
56+ // CDK_PARAM_SYSTEM_ADMIN_EMAIL is required because as part of deploying the bootstrap-template
7057 // the control plane is also deployed. To ensure the operation does not error out, this value
7158 // is provided as an env parameter.
72- CDK_PARAM_SYSTEM_ADMIN_EMAIL : systemAdminEmail
73- }
59+ CDK_PARAM_SYSTEM_ADMIN_EMAIL : systemAdminEmail ,
60+ } ,
61+ outgoingEvent : sbt . DetailType . PROVISION_SUCCESS ,
62+ incomingEvent : sbt . DetailType . ONBOARDING_REQUEST ,
63+ eventManager : props . eventManager
7464 } ;
7565
76- const deprovisioningJobRunnerProps : CoreApplicationPlaneJobRunnerProps = {
77- name : 'deprovisioning' ,
66+ const deprovisioningJobRunnerProps = {
7867 permissions : PolicyDocument . fromJson (
7968 JSON . parse ( `
8069{
@@ -92,56 +81,38 @@ export class CoreAppPlaneStack extends Stack {
9281` )
9382 ) ,
9483 script : fs . readFileSync ( '../scripts/deprovision-tenant.sh' , 'utf8' ) ,
95- environmentStringVariablesFromIncomingEvent : [ 'tenantId' , 'tier' ] ,
84+ environmentStringVariablesFromIncomingEvent : [ 'tenantId' ] ,
9685 environmentVariablesToOutgoingEvent : [ 'tenantStatus' ] ,
97- outgoingEvent : DetailType . DEPROVISION_SUCCESS ,
98- incomingEvent : DetailType . OFFBOARDING_REQUEST ,
99-
86+ outgoingEvent : sbt . DetailType . DEPROVISION_SUCCESS ,
87+ incomingEvent : sbt . DetailType . OFFBOARDING_REQUEST ,
10088 scriptEnvironmentVariables : {
10189 TENANT_STACK_MAPPING_TABLE : this . tenantMappingTable . tableName ,
102- CDK_PARAM_SYSTEM_ADMIN_EMAIL : systemAdminEmail
103- }
90+ // CDK_PARAM_SYSTEM_ADMIN_EMAIL is required because as part of deploying the bootstrap-template
91+ // the control plane is also deployed. To ensure the operation does not error out, this value
92+ // is provided as an env parameter.
93+ CDK_PARAM_SYSTEM_ADMIN_EMAIL : systemAdminEmail ,
94+ } ,
95+ eventManager : props . eventManager
10496 } ;
10597
106- const eventBus = EventBus . fromEventBusArn ( this , 'EventBus' , props . eventBusArn ) ;
107- const eventManager = new EventManager ( this , 'EventManager' , {
108- eventBus : eventBus ,
109- } ) ;
110-
111- new core_app_plane . CoreApplicationPlane ( this , 'coreappplane-sbt' , {
112- eventManager : eventManager ,
113- jobRunnerPropsList : [ provisioningJobRunnerProps , deprovisioningJobRunnerProps ]
114- } ) ;
115-
116- new TenantApiKey ( this , 'BasicTierApiKey' , {
117- apiKeyValue : props . apiKeyBasicTierParameter ,
118- ssmParameterApiKeyIdName : props . ApiKeySSMParameterNames . basic . keyId ,
119- ssmParameterApiValueName : props . ApiKeySSMParameterNames . basic . value
120- } ) ;
121-
122- new TenantApiKey ( this , 'AdvancedTierApiKey' , {
123- apiKeyValue : props . apiKeyAdvancedTierParameter ,
124- ssmParameterApiKeyIdName : props . ApiKeySSMParameterNames . advanced . keyId ,
125- ssmParameterApiValueName : props . ApiKeySSMParameterNames . advanced . value
126- } ) ;
98+ const provisioningJobRunner : sbt . BashJobRunner = new sbt . BashJobRunner ( this ,
99+ 'provisioningJobRunner' , provisioningJobRunnerProps
100+ ) ;
127101
128- new TenantApiKey ( this , 'PremiumTierApiKey' , {
129- apiKeyValue : props . apiKeyPremiumTierParameter ,
130- ssmParameterApiKeyIdName : props . ApiKeySSMParameterNames . premium . keyId ,
131- ssmParameterApiValueName : props . ApiKeySSMParameterNames . premium . value
132- } ) ;
102+ const deprovisioningJobRunner : sbt . BashJobRunner = new sbt . BashJobRunner ( this ,
103+ 'deprovisioningJobRunner' , deprovisioningJobRunnerProps
104+ ) ;
133105
134- new TenantApiKey ( this , 'PlatinumTierApiKey' , {
135- apiKeyValue : props . apiKeyPlatinumTierParameter ,
136- ssmParameterApiKeyIdName : props . ApiKeySSMParameterNames . platinum . keyId ,
137- ssmParameterApiValueName : props . ApiKeySSMParameterNames . platinum . value
106+ new sbt . CoreApplicationPlane ( this , 'coreappplane-sbt' , {
107+ eventManager : props . eventManager ,
108+ jobRunnersList : [ provisioningJobRunner , deprovisioningJobRunner ]
138109 } ) ;
139110
140111 this . userInterface = new UserInterface ( this , 'saas-application-ui' , {
141112 regApiGatewayUrl : props . regApiGatewayUrl
142113 } ) ;
143114
144- new CfnOutput ( this , 'appSiteUrl' , {
115+ new cdk . CfnOutput ( this , 'appSiteUrl' , {
145116 value : this . userInterface . appSiteUrl
146117 } ) ;
147118
0 commit comments