From b404c4ee3ebed3f17d7657d5cdfdaba8d280c058 Mon Sep 17 00:00:00 2001 From: Adrian Dimech Date: Mon, 30 Oct 2023 10:38:21 +1100 Subject: [PATCH] feat(infrastructure): allow stackName to be configurable --- .../java/src/java/groupId/Main.java.mustache | 2 +- .../samples/infrastructure/python/src/main.py.mustache | 2 +- .../infrastructure/typescript/src/main.ts.mustache | 2 +- packages/infrastructure/src/consts.ts | 3 +++ .../src/projects/java/infrastructure-java-project.ts | 9 +++++++++ .../src/projects/python/infrastructure-py-project.ts | 9 +++++++++ .../src/projects/typescript/infrastructure-ts-project.ts | 9 +++++++++ 7 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 packages/infrastructure/src/consts.ts diff --git a/packages/infrastructure/samples/infrastructure/java/src/java/groupId/Main.java.mustache b/packages/infrastructure/samples/infrastructure/java/src/java/groupId/Main.java.mustache index bc73500ca..90b23cb0b 100644 --- a/packages/infrastructure/samples/infrastructure/java/src/java/groupId/Main.java.mustache +++ b/packages/infrastructure/samples/infrastructure/java/src/java/groupId/Main.java.mustache @@ -27,7 +27,7 @@ public class Main { .nagPacks(Arrays.asList(new AwsPrototypingChecks())) .build()); - new ApplicationStack(app, "infra-dev", StackProps.builder() + new ApplicationStack(app, "{{{stackName}}}", StackProps.builder() .env(Environment.builder() .account(System.getenv("CDK_DEFAULT_ACCOUNT")) .region(System.getenv("CDK_DEFAULT_REGION")) diff --git a/packages/infrastructure/samples/infrastructure/python/src/main.py.mustache b/packages/infrastructure/samples/infrastructure/python/src/main.py.mustache index 405641827..a8915382c 100644 --- a/packages/infrastructure/samples/infrastructure/python/src/main.py.mustache +++ b/packages/infrastructure/samples/infrastructure/python/src/main.py.mustache @@ -12,7 +12,7 @@ dev_env = Environment( ) app = PDKNag.app(nag_packs=[AwsPrototypingChecks()]) -ApplicationStack(app, "infra-dev", env=dev_env) +ApplicationStack(app, "{{{stackName}}}", env=dev_env) graph = CdkGraph(app, plugins=[CdkGraphDiagramPlugin( defaults=IDiagramConfigBase( diff --git a/packages/infrastructure/samples/infrastructure/typescript/src/main.ts.mustache b/packages/infrastructure/samples/infrastructure/typescript/src/main.ts.mustache index e170eafd1..5124be4ce 100644 --- a/packages/infrastructure/samples/infrastructure/typescript/src/main.ts.mustache +++ b/packages/infrastructure/samples/infrastructure/typescript/src/main.ts.mustache @@ -15,7 +15,7 @@ const devEnv = { nagPacks: [new AwsPrototypingChecks()], }); - new ApplicationStack(app, "infra-dev", { env: devEnv }); + new ApplicationStack(app, "{{{stackName}}}", { env: devEnv }); const graph = new CdkGraph(app, { plugins: [ diff --git a/packages/infrastructure/src/consts.ts b/packages/infrastructure/src/consts.ts new file mode 100644 index 000000000..9606fe097 --- /dev/null +++ b/packages/infrastructure/src/consts.ts @@ -0,0 +1,3 @@ +/*! Copyright [Amazon.com](http://amazon.com/), Inc. or its affiliates. All Rights Reserved. +SPDX-License-Identifier: Apache-2.0 */ +export const DEFAULT_STACK_NAME = "infra-dev"; diff --git a/packages/infrastructure/src/projects/java/infrastructure-java-project.ts b/packages/infrastructure/src/projects/java/infrastructure-java-project.ts index 5127c9cb2..e1bd44e3f 100644 --- a/packages/infrastructure/src/projects/java/infrastructure-java-project.ts +++ b/packages/infrastructure/src/projects/java/infrastructure-java-project.ts @@ -9,11 +9,19 @@ import * as Mustache from "mustache"; import { SampleFile } from "projen"; import { AwsCdkJavaApp } from "projen/lib/awscdk"; import { AwsCdkJavaAppOptions } from "./aws-cdk-java-app-options"; +import { DEFAULT_STACK_NAME } from "../../consts"; /** * Configuration options for the InfrastructureJavaProject. */ export interface InfrastructureJavaProjectOptions extends AwsCdkJavaAppOptions { + /** + * Stack name. + * + * @default infra-dev + */ + readonly stackName?: string; + /** * TypeSafeApi instance to use when setting up the initial project sample code. */ @@ -110,6 +118,7 @@ export class InfrastructureJavaProject extends AwsCdkJavaApp { const mustacheConfig = { hasApi, hasWebsite, + stackName: options.stackName || DEFAULT_STACK_NAME, infraPackage: `${options.typeSafeApi?.infrastructure.java?.pom.groupId}.${options.typeSafeApi?.infrastructure.java?.pom.name}.infra`, groupId, websiteDistRelativePath: diff --git a/packages/infrastructure/src/projects/python/infrastructure-py-project.ts b/packages/infrastructure/src/projects/python/infrastructure-py-project.ts index 9ca1e59b0..fd59c9807 100644 --- a/packages/infrastructure/src/projects/python/infrastructure-py-project.ts +++ b/packages/infrastructure/src/projects/python/infrastructure-py-project.ts @@ -9,11 +9,19 @@ import * as Mustache from "mustache"; import { SampleFile } from "projen"; import { AwsCdkPythonApp } from "projen/lib/awscdk"; import { AwsCdkPythonAppOptions } from "./aws-cdk-py-app-options"; +import { DEFAULT_STACK_NAME } from "../../consts"; /** * Configuration options for the InfrastructurePyProject. */ export interface InfrastructurePyProjectOptions extends AwsCdkPythonAppOptions { + /** + * Stack name. + * + * @default infra-dev + */ + readonly stackName?: string; + /** * TypeSafeApi instance to use when setting up the initial project sample code. */ @@ -96,6 +104,7 @@ export class InfrastructurePyProject extends AwsCdkPythonApp { const mustacheConfig = { hasApi, hasWebsite, + stackName: options.stackName || DEFAULT_STACK_NAME, infraPackage: options.typeSafeApi?.infrastructure.python?.moduleName, moduleName, websiteDistRelativePath: diff --git a/packages/infrastructure/src/projects/typescript/infrastructure-ts-project.ts b/packages/infrastructure/src/projects/typescript/infrastructure-ts-project.ts index b1299b5b6..712426d46 100644 --- a/packages/infrastructure/src/projects/typescript/infrastructure-ts-project.ts +++ b/packages/infrastructure/src/projects/typescript/infrastructure-ts-project.ts @@ -10,12 +10,20 @@ import { SampleFile } from "projen"; import { AwsCdkTypeScriptApp } from "projen/lib/awscdk"; import { NodeProject } from "projen/lib/javascript"; import { AwsCdkTypeScriptAppOptions } from "./aws-cdk-ts-app-options"; +import { DEFAULT_STACK_NAME } from "../../consts"; /** * Configuration options for the InfrastructureTsProject. */ export interface InfrastructureTsProjectOptions extends AwsCdkTypeScriptAppOptions { + /** + * Stack name. + * + * @default infra-dev + */ + readonly stackName?: string; + /** * TypeSafeApi instance to use when setting up the initial project sample code. */ @@ -91,6 +99,7 @@ export class InfrastructureTsProject extends AwsCdkTypeScriptApp { const mustacheConfig = { hasApi, hasWebsite, + stackName: options.stackName || DEFAULT_STACK_NAME, infraPackage: options.typeSafeApi?.infrastructure.typescript?.package.packageName, websiteDistRelativePath: