Skip to content

Commit dcf1d74

Browse files
authored
chore(toolkit): add proposed initial interfaces (#32643)
### Issue Close #32567 ### Reason for this change Add proposed interfaces and stub classes to the `@aws-cdk/toolkit` package according to RFC 300, so integrators can start designing their own solution. ### Describe any new or updated permissions being added n/a ### Description of how you validated changes n/a unused stub interfaces ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent fcf37ee commit dcf1d74

File tree

12 files changed

+520
-7
lines changed

12 files changed

+520
-7
lines changed
Lines changed: 228 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,228 @@
1+
import { StackSelector } from '../types';
2+
3+
export type DeploymentMethod = DirectDeploymentMethod | ChangeSetDeploymentMethod;
4+
5+
export interface DirectDeploymentMethod {
6+
/**
7+
* Use stack APIs to the deploy stack changes
8+
*/
9+
readonly method: 'direct';
10+
}
11+
12+
export interface ChangeSetDeploymentMethod {
13+
/**
14+
* Use change-set APIS to deploy a stack changes
15+
*/
16+
readonly method: 'change-set';
17+
18+
/**
19+
* Whether to execute the changeset or leave it in review.
20+
*
21+
* @default true
22+
*/
23+
readonly execute?: boolean;
24+
25+
/**
26+
* Optional name to use for the CloudFormation change set.
27+
* If not provided, a name will be generated automatically.
28+
*/
29+
readonly changeSetName?: string;
30+
}
31+
32+
/**
33+
* When to build assets
34+
*/
35+
export enum AssetBuildTime {
36+
/**
37+
* Build all assets before deploying the first stack
38+
*
39+
* This is intended for expensive Docker image builds; so that if the Docker image build
40+
* fails, no stacks are unnecessarily deployed (with the attendant wait time).
41+
*/
42+
ALL_BEFORE_DEPLOY = 'all-before-deploy',
43+
44+
/**
45+
* Build assets just-in-time, before publishing
46+
*/
47+
JUST_IN_TIME = 'just-in-time',
48+
}
49+
50+
export interface Tag {
51+
readonly Key: string;
52+
readonly Value: string;
53+
}
54+
55+
export enum RequireApproval {
56+
NEVER = 'never',
57+
ANY_CHANGE = 'any-change',
58+
BROADENING = 'broadening',
59+
}
60+
61+
export enum HotswapMode {
62+
/**
63+
* Will fall back to CloudFormation when a non-hotswappable change is detected
64+
*/
65+
FALL_BACK = 'fall-back',
66+
67+
/**
68+
* Will not fall back to CloudFormation when a non-hotswappable change is detected
69+
*/
70+
HOTSWAP_ONLY = 'hotswap-only',
71+
72+
/**
73+
* Will not attempt to hotswap anything and instead go straight to CloudFormation
74+
*/
75+
FULL_DEPLOYMENT = 'full-deployment',
76+
}
77+
78+
export class StackParameters {
79+
/**
80+
* Use only existing parameters on the stack.
81+
*/
82+
public static onlyExisting() {
83+
return new StackParameters({}, true);
84+
};
85+
86+
/**
87+
* Use exactly these parameters and remove any other existing parameters from the stack.
88+
*/
89+
public static exactly(params: { [name: string]: string | undefined }) {
90+
return new StackParameters(params, false);
91+
};
92+
93+
/**
94+
* Define additional parameters for the stack, while keeping existing parameters for unspecified values.
95+
*/
96+
public static withExisting(params: { [name: string]: string | undefined }) {
97+
return new StackParameters(params, true);
98+
};
99+
100+
public readonly parameters: Map<string, string | undefined>;
101+
public readonly keepExistingParameters: boolean;
102+
103+
private constructor(params: { [name: string]: string | undefined }, usePreviousParameters = true) {
104+
this.keepExistingParameters = usePreviousParameters;
105+
this.parameters = new Map(Object.entries(params));
106+
}
107+
}
108+
109+
export interface BaseDeployOptions {
110+
/**
111+
* Criteria for selecting stacks to deploy
112+
*/
113+
readonly stacks: StackSelector;
114+
115+
/**
116+
* Name of the toolkit stack to use/deploy
117+
*
118+
* @default CDKToolkit
119+
*/
120+
readonly toolkitStackName?: string;
121+
122+
/**
123+
* Role to pass to CloudFormation for deployment
124+
*/
125+
readonly roleArn?: string;
126+
127+
/**
128+
* @TODO can this be part of `DeploymentMethod`
129+
*
130+
* Always deploy, even if templates are identical.
131+
*
132+
* @default false
133+
*/
134+
readonly force?: boolean;
135+
136+
/**
137+
* Deployment method
138+
*/
139+
readonly deploymentMethod?: DeploymentMethod;
140+
141+
/**
142+
* @TODO can this be part of `DeploymentMethod`
143+
*
144+
* Whether to perform a 'hotswap' deployment.
145+
* A 'hotswap' deployment will attempt to short-circuit CloudFormation
146+
* and update the affected resources like Lambda functions directly.
147+
*
148+
* @default - `HotswapMode.FALL_BACK` for regular deployments, `HotswapMode.HOTSWAP_ONLY` for 'watch' deployments
149+
*/
150+
readonly hotswap: HotswapMode;
151+
152+
/**
153+
* Rollback failed deployments
154+
*
155+
* @default true
156+
*/
157+
readonly rollback?: boolean;
158+
159+
/**
160+
* Reuse the assets with the given asset IDs
161+
*/
162+
readonly reuseAssets?: string[];
163+
164+
/**
165+
* Maximum number of simultaneous deployments (dependency permitting) to execute.
166+
* The default is '1', which executes all deployments serially.
167+
*
168+
* @default 1
169+
*/
170+
readonly concurrency?: number;
171+
}
172+
173+
export interface DeployOptions extends BaseDeployOptions {
174+
/**
175+
* ARNs of SNS topics that CloudFormation will notify with stack related events
176+
*/
177+
readonly notificationArns?: string[];
178+
179+
/**
180+
* What kind of security changes require approval
181+
*
182+
* @default RequireApproval.Broadening
183+
*/
184+
readonly requireApproval?: RequireApproval;
185+
186+
/**
187+
* Tags to pass to CloudFormation for deployment
188+
*/
189+
readonly tags?: Tag[];
190+
191+
/**
192+
* Stack parameters for CloudFormation used at deploy time
193+
* @default StackParameters.onlyExisting()
194+
*/
195+
readonly parameters?: StackParameters;
196+
197+
/**
198+
* Path to file where stack outputs will be written after a successful deploy as JSON
199+
* @default - Outputs are not written to any file
200+
*/
201+
readonly outputsFile?: string;
202+
203+
/**
204+
* Whether to show logs from all CloudWatch log groups in the template
205+
* locally in the users terminal
206+
*
207+
* @default - false
208+
*/
209+
readonly traceLogs?: boolean;
210+
211+
/**
212+
* Build/publish assets for a single stack in parallel
213+
*
214+
* Independent of whether stacks are being done in parallel or no.
215+
*
216+
* @default true
217+
*/
218+
readonly assetParallelism?: boolean;
219+
220+
/**
221+
* When to build assets
222+
*
223+
* The default is the Docker-friendly default.
224+
*
225+
* @default AssetBuildTime.ALL_BEFORE_DEPLOY
226+
*/
227+
readonly assetBuildTime?: AssetBuildTime;
228+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { StackSelector } from '../types';
2+
3+
export interface DestroyOptions {
4+
/**
5+
* Criteria for selecting stacks to deploy
6+
*/
7+
readonly stacks: StackSelector;
8+
9+
/**
10+
* The arn of the IAM role to use
11+
*/
12+
readonly roleArn?: string;
13+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { BaseDeployOptions } from './deploy';
2+
3+
export interface ImportOptions extends Omit<BaseDeployOptions, 'reuseAssets' | 'hotswap'> {
4+
/**
5+
* Build a physical resource mapping and write it to the given file, without performing the actual import operation
6+
*
7+
* @default - No file
8+
*/
9+
readonly recordResourceMapping?: string;
10+
11+
/**
12+
* Path to a file with the physical resource mapping to CDK constructs in JSON format
13+
*
14+
* @default - No mapping file
15+
*/
16+
readonly resourceMappingFile?: string;
17+
18+
/**
19+
* Allow non-addition changes to the template
20+
*
21+
* @default false
22+
*/
23+
readonly force?: boolean;
24+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { StackSelector } from '../types';
2+
3+
export interface SynthOptions {
4+
/**
5+
* Select the stacks
6+
*/
7+
readonly stacks: StackSelector;
8+
9+
/**
10+
* After synthesis, validate stacks with the "validateOnSynth" attribute set (can also be controlled with CDK_VALIDATION)
11+
* @default true
12+
*/
13+
readonly validateStacks?: boolean;
14+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { BaseDeployOptions } from './deploy';
2+
3+
export interface WatchOptions extends BaseDeployOptions {
4+
/**
5+
* Whether to show CloudWatch logs for hotswapped resources
6+
* locally in the users terminal
7+
*
8+
* @default - false
9+
*/
10+
readonly traceLogs?: boolean;
11+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import { CloudAssembly } from '@aws-cdk/cx-api';
2+
3+
export interface ICloudAssemblySource {
4+
/**
5+
* produce
6+
*/
7+
produce(): Promise<CloudAssembly>;
8+
}
9+
10+
/**
11+
* Configuration for creating a CLI from an AWS CDK App directory
12+
*/
13+
export interface CdkAppDirectoryProps {
14+
/**
15+
* Command-line for executing your app or a cloud assembly directory
16+
* e.g. "node bin/my-app.js"
17+
* or
18+
* "cdk.out"
19+
*
20+
* @default - read from cdk.json
21+
*/
22+
readonly app?: string;
23+
24+
/**
25+
* Emits the synthesized cloud assembly into a directory
26+
*
27+
* @default cdk.out
28+
*/
29+
readonly output?: string;
30+
}
31+
32+
export class CloudAssemblySource implements ICloudAssemblySource {
33+
/**
34+
* Use a directory containing an AWS CDK app as source.
35+
* @param directory the directory of the AWS CDK app. Defaults to the current working directory.
36+
* @param props additional configuration properties
37+
* @returns an instance of `AwsCdkCli`
38+
*/
39+
public static fromCdkAppDirectory(_directory?: string, _props: CdkAppDirectoryProps = {}) {}
40+
41+
/**
42+
* Create the CLI from a Cloud Assembly builder function.
43+
*/
44+
public static fromAssemblyBuilder(_builder: (context: Record<string, any>) => Promise<CloudAssembly>) {}
45+
46+
public produce(): Promise<CloudAssembly> {
47+
throw new Error('Method not implemented.');
48+
}
49+
}
50+
51+
/**
52+
* A CloudAssemblySource that is caching its result once produced.
53+
*
54+
* Most Toolkit interactions should use a cached source.
55+
* Not caching is relevant when the source changes frequently
56+
* and it is to expensive to predict if the source has changed.
57+
*/
58+
export class CachedCloudAssemblySource implements ICloudAssemblySource {
59+
private source: ICloudAssemblySource;
60+
private cloudAssembly: CloudAssembly | undefined;
61+
62+
public constructor(source: ICloudAssemblySource) {
63+
this.source = source;
64+
}
65+
66+
public async produce(): Promise<CloudAssembly> {
67+
if (!this.cloudAssembly) {
68+
this.cloudAssembly = await this.source.produce();
69+
}
70+
return this.cloudAssembly;
71+
}
72+
}
Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,10 @@
1-
export class Toolkit {}
1+
export * from './toolkit';
2+
export * from './cloud-assembly-source';
3+
export * from './actions/deploy';
4+
export * from './actions/destroy';
5+
export * from './actions/import';
6+
export * from './actions/synth';
7+
export * from './actions/watch';
8+
9+
export * from './io-host';
10+
export * from './types';

0 commit comments

Comments
 (0)