cedar-aws-stack.ts1.8 KBView on GitHub import { Stack } from 'aws-cdk-lib';
import { Construct } from 'constructs';
import {
buildEnvironmentConfig,
resolveAwsRegion,
type CedarAwsDeploymentMode,
type CedarAwsEnvironmentName,
} from './config.js';
import { CedarEnvironmentStack } from './cedar-environment-stack.js';
import { MigrationDashboardStack } from './stacks/migration-dashboard-stack.js';
import { CedarSecurityStack } from './stacks/security-stack.js';
type CedarAwsStackProps = {
environments?: Array<{
envName: CedarAwsEnvironmentName;
deploymentMode?: CedarAwsDeploymentMode;
}>;
};
export class CedarAwsStack extends Construct {
constructor(scope: Construct, id: string, props: CedarAwsStackProps) {
super(scope, id);
const account = process.env.CDK_DEFAULT_ACCOUNT;
const region = resolveAwsRegion();
const environments = props.environments ?? [
{ envName: 'staging', deploymentMode: 'staging' },
{ envName: 'prod', deploymentMode: 'prod' },
];
const dashboardStack = new Stack(scope, 'CedarMigrationDashboardHostingStack', {
env: account && region ? { account, region } : undefined,
});
new MigrationDashboardStack(dashboardStack, 'CedarMigrationDashboard');
// Account-level security controls (one trail covers the whole account).
const securityStack = new Stack(scope, 'CedarSecurityStack', {
env: account && region ? { account, region } : undefined,
});
new CedarSecurityStack(securityStack, 'CedarSecurity');
for (const environment of environments) {
const config = buildEnvironmentConfig(environment.envName, environment.deploymentMode);
new CedarEnvironmentStack(scope, config.stackNames.environment, {
config,
env: account && region ? { account, region } : undefined,
});
}
}
}