forked from projen/projen
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(awscdk): awscdk-java-app (projen#1190)
Introduce an AWS CDK Java app project (`awscdk-java-app`). This is needed as a basis for adding support for AWS Lambda functions in Java (projen#1070). Extracts some common CDK app logic into components (`awscdk.CdkConfig` and `awscdk.CdkTasks`). BREAKING CHANGE: `CdkApprovalLevel` is now `awscdk.ApprovalLevel`. * **awscdk:** `cdkTypeScriptApp.cdkConfig` now refers to a `awscdk.CdkConfig` object. To add custom fields to `cdk.json` use `cdkTypeScriptApp.cdkConfig.json`. --- By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
- Loading branch information
Elad Ben-Israel
authored
Oct 31, 2021
1 parent
bff7bc8
commit b7753ec
Showing
14 changed files
with
1,809 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
import { Component } from '../component'; | ||
import { JsonFile } from '../json'; | ||
import { Project } from '../project'; | ||
import { FEATURE_FLAGS } from './internal'; | ||
|
||
/** | ||
* Common options for `cdk.json`. | ||
*/ | ||
export interface CdkConfigCommonOptions { | ||
/** | ||
* Additional context to include in `cdk.json`. | ||
* | ||
* @default - no additional context | ||
*/ | ||
readonly context?: { [key: string]: string }; | ||
|
||
/** | ||
* Include all feature flags in cdk.json | ||
* | ||
* @default true | ||
*/ | ||
readonly featureFlags?: boolean; | ||
|
||
/** | ||
* To protect you against unintended changes that affect your security posture, | ||
* the AWS CDK Toolkit prompts you to approve security-related changes before deploying them. | ||
* | ||
* @default ApprovalLevel.BROADENING | ||
*/ | ||
readonly requireApproval?: ApprovalLevel; | ||
|
||
/** | ||
* cdk.out directory. | ||
* | ||
* @default "cdk.out" | ||
*/ | ||
readonly cdkout?: string; | ||
} | ||
|
||
/** | ||
* Options for `CdkJson`. | ||
*/ | ||
export interface CdkConfigOptions extends CdkConfigCommonOptions { | ||
/** | ||
* The command line to execute in order to synthesize the CDK application | ||
* (language specific). | ||
*/ | ||
readonly app: string; | ||
} | ||
|
||
/** | ||
* Represents cdk.json file. | ||
*/ | ||
export class CdkConfig extends Component { | ||
|
||
/** | ||
* Represents the JSON file. | ||
*/ | ||
public readonly json: JsonFile; | ||
|
||
/** | ||
* Name of the cdk.out directory. | ||
*/ | ||
public readonly cdkout: string; | ||
|
||
constructor(project: Project, options: CdkConfigOptions) { | ||
super(project); | ||
|
||
this.cdkout = options.cdkout ?? 'cdk.out'; | ||
|
||
const context: Record<string, any> = { ...options.context }; | ||
const fflags = options.featureFlags ?? true; | ||
if (fflags) { | ||
for (const flag of FEATURE_FLAGS) { | ||
context[flag] = true; | ||
} | ||
} | ||
|
||
this.json = new JsonFile(project, 'cdk.json', { | ||
omitEmpty: true, | ||
obj: { | ||
app: options.app, | ||
context: context, | ||
requireApproval: options.requireApproval, | ||
output: this.cdkout, | ||
}, | ||
}); | ||
|
||
project.gitignore.exclude(`/${this.cdkout}/`); | ||
project.gitignore.exclude('.cdk.staging/'); | ||
} | ||
} | ||
|
||
/** | ||
* Which approval is required when deploying CDK apps. | ||
*/ | ||
export enum ApprovalLevel { | ||
/** | ||
* Approval is never required | ||
*/ | ||
NEVER = 'never', | ||
/** | ||
* Requires approval on any IAM or security-group-related change | ||
*/ | ||
ANY_CHANGE = 'any-change', | ||
/** | ||
* Requires approval when IAM statements or traffic rules are added; removals don't require approval | ||
*/ | ||
BROADENING = 'broadening', | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { Component } from '../component'; | ||
import { Project } from '../project'; | ||
import { Task } from '../tasks'; | ||
|
||
/** | ||
* Adds standard AWS CDK tasks to your project. | ||
*/ | ||
export class CdkTasks extends Component { | ||
/** | ||
* Synthesizes your app. | ||
*/ | ||
public readonly synth: Task; | ||
|
||
/** | ||
* Deploys your app. | ||
*/ | ||
public readonly deploy: Task; | ||
|
||
/** | ||
* Destroys all the stacks. | ||
*/ | ||
public readonly destroy: Task; | ||
|
||
/** | ||
* Diff against production. | ||
*/ | ||
public readonly diff: Task; | ||
|
||
constructor(project: Project) { | ||
super(project); | ||
|
||
this.synth = project.addTask('synth', { | ||
description: 'Synthesizes your cdk app into cdk.out (part of "yarn build")', | ||
exec: 'cdk synth', | ||
}); | ||
|
||
this.deploy = project.addTask('deploy', { | ||
description: 'Deploys your CDK app to the AWS cloud', | ||
exec: 'cdk deploy', | ||
}); | ||
|
||
this.destroy = project.addTask('destroy', { | ||
description: 'Destroys your cdk app in the AWS cloud', | ||
exec: 'cdk destroy', | ||
}); | ||
|
||
this.diff = project.addTask('diff', { | ||
description: 'Diffs the currently deployed app against your code', | ||
exec: 'cdk diff', | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './java-app'; | ||
export * from './cdk-config'; | ||
export * from './cdk-tasks'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** | ||
* Feature flags as of v1.130.0 | ||
*/ | ||
export const FEATURE_FLAGS = [ | ||
'aws-cdk:enableDiffNoFail', | ||
'@aws-cdk/aws-apigateway:usagePlanKeyOrderInsensitiveId', | ||
'@aws-cdk/core:enableStackNameDuplicates', | ||
'@aws-cdk/core:stackRelativeExports', | ||
'@aws-cdk/aws-ecr-assets:dockerIgnoreSupport', | ||
'@aws-cdk/aws-secretsmanager:parseOwnedSecretName', | ||
'@aws-cdk/aws-kms:defaultKeyPolicies', | ||
'@aws-cdk/aws-s3:grantWriteWithoutAcl', | ||
'@aws-cdk/aws-ecs-patterns:removeDefaultDesiredCount', | ||
'@aws-cdk/aws-rds:lowercaseDbIdentifier', | ||
'@aws-cdk/aws-efs:defaultEncryptionAtRest', | ||
'@aws-cdk/aws-lambda:recognizeVersionProps', | ||
'@aws-cdk/aws-cloudfront:defaultSecurityPolicyTLSv1.2_2021', | ||
]; |
Oops, something went wrong.