Skip to content

Commit ac90399

Browse files
authored
refactor(cli): collate existing files into new deployments api (#33094)
### Reason for this change Cleaning up the CLI code base in preparation for splitting out the library parts. It's currently quite hard to reason about the existing api code as its spread across many files and deep subpath imports. This change attempts to partly rectify the situation by grouping files with strong interdependencies together and creating a unified import location. The change deliberately gives up on potential feature reusability of some helpers in order to create locality. ### Description of changes Collating existing files and APIs into a new submodule `api/deployments`. Updated imports accordingly. No functional changes. ### Describe any new or updated permissions being added n/a ### Description of how you validated changes exiting tests ### 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 8506d31 commit ac90399

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+233
-223
lines changed

packages/aws-cdk/lib/api/bootstrap/bootstrap-environment.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { loadStructuredFile, serializeStructure } from '../../serialize';
99
import { ToolkitError } from '../../toolkit/error';
1010
import { rootDir } from '../../util/directories';
1111
import type { SDK, SdkProvider } from '../aws-auth';
12-
import type { SuccessfulDeployStackResult } from '../deploy-stack';
12+
import type { SuccessfulDeployStackResult } from '../deployments';
1313
import { Mode } from '../plugin/mode';
1414

1515
export type BootstrapSource = { source: 'legacy' } | { source: 'default' } | { source: 'custom'; templateFile: string };

packages/aws-cdk/lib/api/bootstrap/deploy-bootstrap.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ import {
1212
} from './bootstrap-props';
1313
import * as logging from '../../logging';
1414
import type { SDK, SdkProvider } from '../aws-auth';
15-
import { assertIsSuccessfulDeployStackResult, deployStack, SuccessfulDeployStackResult } from '../deploy-stack';
15+
import { assertIsSuccessfulDeployStackResult, SuccessfulDeployStackResult } from '../deployments';
16+
import { deployStack } from '../deployments/deploy-stack';
1617
import { NoBootstrapStackEnvironmentResources } from '../environment-resources';
1718
import { Mode } from '../plugin/mode';
1819
import { DEFAULT_TOOLKIT_STACK_NAME, ToolkitInfo } from '../toolkit-info';

packages/aws-cdk/lib/util/asset-manifest-builder.ts renamed to packages/aws-cdk/lib/api/deployments/asset-manifest-builder.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as cxschema from '@aws-cdk/cloud-assembly-schema';
2-
import * as cdk_assets from 'cdk-assets';
2+
import { AssetManifest } from 'cdk-assets';
33

44
export class AssetManifestBuilder {
55
private readonly manifest: cxschema.AssetManifest = {
@@ -26,7 +26,7 @@ export class AssetManifestBuilder {
2626
};
2727
}
2828

29-
public toManifest(directory: string): cdk_assets.AssetManifest {
30-
return new cdk_assets.AssetManifest(directory, this.manifest);
29+
public toManifest(directory: string): AssetManifest {
30+
return new AssetManifest(directory, this.manifest);
3131
}
3232
}

packages/aws-cdk/lib/util/asset-publishing.ts renamed to packages/aws-cdk/lib/api/deployments/asset-publishing.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ import {
1212
type IS3Client,
1313
type ISecretsManagerClient,
1414
} from 'cdk-assets';
15-
import type { SDK } from '../api';
16-
import type { SdkProvider } from '../api/aws-auth/sdk-provider';
17-
import { Mode } from '../api/plugin/mode';
18-
import { debug, error, info } from '../logging';
19-
import { ToolkitError } from '../toolkit/error';
15+
import type { SDK } from '..';
16+
import { debug, error, info } from '../../logging';
17+
import { ToolkitError } from '../../toolkit/error';
18+
import type { SdkProvider } from '../aws-auth';
19+
import { Mode } from '../plugin';
2020

2121
export interface PublishAssetsOptions {
2222
/**

packages/aws-cdk/lib/assets.ts renamed to packages/aws-cdk/lib/api/deployments/assets.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ import * as path from 'path';
33
import * as cxschema from '@aws-cdk/cloud-assembly-schema';
44
import * as cxapi from '@aws-cdk/cx-api';
55
import * as chalk from 'chalk';
6-
import { EnvironmentResources } from './api/environment-resources';
7-
import { ToolkitInfo } from './api/toolkit-info';
8-
import { debug } from './logging';
9-
import { ToolkitError } from './toolkit/error';
10-
import { AssetManifestBuilder } from './util/asset-manifest-builder';
6+
import { AssetManifestBuilder } from './asset-manifest-builder';
7+
import { debug } from '../../logging';
8+
import { ToolkitError } from '../../toolkit/error';
9+
import { EnvironmentResources } from '../environment-resources';
10+
import { ToolkitInfo } from '../toolkit-info';
1111

1212
/**
1313
* Take the metadata assets from the given stack and add them to the given asset manifest

packages/aws-cdk/lib/api/util/checks.ts renamed to packages/aws-cdk/lib/api/deployments/checks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { debug } from '../../logging';
22
import { ToolkitError } from '../../toolkit/error';
3-
import { SDK } from '../aws-auth/sdk';
3+
import { SDK } from '../aws-auth';
44

55
export async function determineAllowCrossAccountAssetPublishing(sdk: SDK, customStackName?: string): Promise<boolean> {
66
try {

packages/aws-cdk/lib/api/util/cloudformation.ts renamed to packages/aws-cdk/lib/api/deployments/cloudformation.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ import {
1010
type Tag,
1111
} from '@aws-sdk/client-cloudformation';
1212
import { AssetManifest, FileManifestEntry } from 'cdk-assets';
13-
import { StackStatus } from './cloudformation/stack-status';
14-
import { makeBodyParameter, TemplateBodyParameter } from './template-body-parameter';
13+
import { AssetManifestBuilder } from './asset-manifest-builder';
1514
import { debug } from '../../logging';
1615
import { deserializeStructure } from '../../serialize';
1716
import { ToolkitError } from '../../toolkit/error';
18-
import { AssetManifestBuilder } from '../../util/asset-manifest-builder';
1917
import { formatErrorMessage } from '../../util/error';
2018
import type { ICloudFormationClient, SdkProvider } from '../aws-auth';
21-
import type { Deployments } from '../deployments';
19+
import type { Deployments } from './deployments';
20+
import { StackStatus } from '../util/cloudformation/stack-status';
21+
import { makeBodyParameter, TemplateBodyParameter } from '../util/template-body-parameter';
2222

2323
export type ResourcesToImport = ResourceToImport[];
2424
export type ResourceIdentifierSummaries = ResourceIdentifierSummary[];

packages/aws-cdk/lib/api/deploy-stack.ts renamed to packages/aws-cdk/lib/api/deployments/deploy-stack.ts

Lines changed: 18 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,10 @@ import type {
99
} from '@aws-sdk/client-cloudformation';
1010
import * as chalk from 'chalk';
1111
import * as uuid from 'uuid';
12-
import type { SDK, SdkProvider, ICloudFormationClient } from './aws-auth';
13-
import type { EnvironmentResources } from './environment-resources';
14-
import { CfnEvaluationException } from './evaluate-cloudformation-template';
15-
import { HotswapMode, HotswapPropertyOverrides, ICON } from './hotswap/common';
16-
import { tryHotswapDeployment } from './hotswap-deployments';
17-
import { addMetadataAssetsToManifest } from '../assets';
18-
import { debug, info, warning } from '../logging';
12+
import { AssetManifestBuilder } from './asset-manifest-builder';
13+
import { publishAssets } from './asset-publishing';
14+
import { addMetadataAssetsToManifest } from './assets';
15+
import { determineAllowCrossAccountAssetPublishing } from './checks';
1916
import {
2017
changeSetHasNoChanges,
2118
CloudFormationStack,
@@ -26,47 +23,20 @@ import {
2623
ParameterValues,
2724
ParameterChanges,
2825
ResourcesToImport,
29-
} from './util/cloudformation';
30-
import { StackActivityMonitor, type StackActivityProgress } from './util/cloudformation/stack-activity-monitor';
31-
import { type TemplateBodyParameter, makeBodyParameter } from './util/template-body-parameter';
32-
import { AssetManifestBuilder } from '../util/asset-manifest-builder';
33-
import { determineAllowCrossAccountAssetPublishing } from './util/checks';
34-
import { publishAssets } from '../util/asset-publishing';
35-
import { StringWithoutPlaceholders } from './util/placeholders';
36-
import { ToolkitError } from '../toolkit/error';
37-
import { formatErrorMessage } from '../util/error';
38-
39-
export type DeployStackResult =
40-
| SuccessfulDeployStackResult
41-
| NeedRollbackFirstDeployStackResult
42-
| ReplacementRequiresRollbackStackResult
43-
;
44-
45-
/** Successfully deployed a stack */
46-
export interface SuccessfulDeployStackResult {
47-
readonly type: 'did-deploy-stack';
48-
readonly noOp: boolean;
49-
readonly outputs: { [name: string]: string };
50-
readonly stackArn: string;
51-
}
52-
53-
/** The stack is currently in a failpaused state, and needs to be rolled back before the deployment */
54-
export interface NeedRollbackFirstDeployStackResult {
55-
readonly type: 'failpaused-need-rollback-first';
56-
readonly reason: 'not-norollback' | 'replacement';
57-
readonly status: string;
58-
}
59-
60-
/** The upcoming change has a replacement, which requires deploying with --rollback */
61-
export interface ReplacementRequiresRollbackStackResult {
62-
readonly type: 'replacement-requires-rollback';
63-
}
64-
65-
export function assertIsSuccessfulDeployStackResult(x: DeployStackResult): asserts x is SuccessfulDeployStackResult {
66-
if (x.type !== 'did-deploy-stack') {
67-
throw new ToolkitError(`Unexpected deployStack result. This should not happen: ${JSON.stringify(x)}. If you are seeing this error, please report it at https://github.com/aws/aws-cdk/issues/new/choose.`);
68-
}
69-
}
26+
} from './cloudformation';
27+
import { ChangeSetDeploymentMethod, DeploymentMethod } from './deployment-method';
28+
import { DeployStackResult, SuccessfulDeployStackResult } from './deployment-result';
29+
import { tryHotswapDeployment } from './hotswap-deployments';
30+
import { debug, info, warning } from '../../logging';
31+
import { ToolkitError } from '../../toolkit/error';
32+
import { formatErrorMessage } from '../../util/error';
33+
import type { SDK, SdkProvider, ICloudFormationClient } from '../aws-auth';
34+
import type { EnvironmentResources } from '../environment-resources';
35+
import { CfnEvaluationException } from '../evaluate-cloudformation-template';
36+
import { HotswapMode, HotswapPropertyOverrides, ICON } from '../hotswap/common';
37+
import { StackActivityMonitor, type StackActivityProgress } from '../util/cloudformation/stack-activity-monitor';
38+
import { StringWithoutPlaceholders } from '../util/placeholders';
39+
import { type TemplateBodyParameter, makeBodyParameter } from '../util/template-body-parameter';
7040

7141
export interface DeployStackOptions {
7242
/**
@@ -251,36 +221,6 @@ export interface DeployStackOptions {
251221
readonly assetParallelism?: boolean;
252222
}
253223

254-
export type DeploymentMethod = DirectDeploymentMethod | ChangeSetDeploymentMethod;
255-
256-
export interface DirectDeploymentMethod {
257-
readonly method: 'direct';
258-
}
259-
260-
export interface ChangeSetDeploymentMethod {
261-
readonly method: 'change-set';
262-
263-
/**
264-
* Whether to execute the changeset or leave it in review.
265-
*
266-
* @default true
267-
*/
268-
readonly execute?: boolean;
269-
270-
/**
271-
* Optional name to use for the CloudFormation change set.
272-
* If not provided, a name will be generated automatically.
273-
*/
274-
readonly changeSetName?: string;
275-
276-
/**
277-
* Indicates if the change set imports resources that already exist.
278-
*
279-
* @default false
280-
*/
281-
readonly importExistingResources?: boolean;
282-
}
283-
284224
export async function deployStack(options: DeployStackOptions): Promise<DeployStackResult> {
285225
const stackArtifact = options.stack;
286226

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
export type DeploymentMethod = DirectDeploymentMethod | ChangeSetDeploymentMethod;
2+
3+
export interface DirectDeploymentMethod {
4+
readonly method: 'direct';
5+
}
6+
7+
export interface ChangeSetDeploymentMethod {
8+
readonly method: 'change-set';
9+
10+
/**
11+
* Whether to execute the changeset or leave it in review.
12+
*
13+
* @default true
14+
*/
15+
readonly execute?: boolean;
16+
17+
/**
18+
* Optional name to use for the CloudFormation change set.
19+
* If not provided, a name will be generated automatically.
20+
*/
21+
readonly changeSetName?: string;
22+
23+
/**
24+
* Indicates if the change set imports resources that already exist.
25+
*
26+
* @default false
27+
*/
28+
readonly importExistingResources?: boolean;
29+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { ToolkitError } from '../../toolkit/error';
2+
3+
export type DeployStackResult =
4+
| SuccessfulDeployStackResult
5+
| NeedRollbackFirstDeployStackResult
6+
| ReplacementRequiresRollbackStackResult
7+
;
8+
9+
/** Successfully deployed a stack */
10+
export interface SuccessfulDeployStackResult {
11+
readonly type: 'did-deploy-stack';
12+
readonly noOp: boolean;
13+
readonly outputs: { [name: string]: string };
14+
readonly stackArn: string;
15+
}
16+
17+
/** The stack is currently in a failpaused state, and needs to be rolled back before the deployment */
18+
export interface NeedRollbackFirstDeployStackResult {
19+
readonly type: 'failpaused-need-rollback-first';
20+
readonly reason: 'not-norollback' | 'replacement';
21+
readonly status: string;
22+
}
23+
24+
/** The upcoming change has a replacement, which requires deploying with --rollback */
25+
export interface ReplacementRequiresRollbackStackResult {
26+
readonly type: 'replacement-requires-rollback';
27+
}
28+
29+
export function assertIsSuccessfulDeployStackResult(x: DeployStackResult): asserts x is SuccessfulDeployStackResult {
30+
if (x.type !== 'did-deploy-stack') {
31+
throw new ToolkitError(`Unexpected deployStack result. This should not happen: ${JSON.stringify(x)}. If you are seeing this error, please report it at https://github.com/aws/aws-cdk/issues/new/choose.`);
32+
}
33+
}

0 commit comments

Comments
 (0)