Skip to content

Commit

Permalink
try fixing migrate import diff in cdktoolkit
Browse files Browse the repository at this point in the history
Signed-off-by: Sumu <[email protected]>
  • Loading branch information
sumupitchayan committed Feb 28, 2024
1 parent 4df1cf0 commit bcb544c
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion packages/aws-cdk/lib/cdk-toolkit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { Concurrency, WorkGraph } from './util/work-graph';
import { WorkGraphBuilder } from './util/work-graph-builder';
import { AssetBuildNode, AssetPublishNode, StackNode } from './util/work-graph-types';
import { environmentsFromDescriptors, globEnvironmentsFromStacks, looksLikeGlob } from '../lib/api/cxapp/environments';
import { CloudFormation } from 'aws-sdk';

export interface CdkToolkitProps {

Expand Down Expand Up @@ -167,7 +168,12 @@ export class CdkToolkit {
removeNonImportResources(stack);
}

const changeSet = options.changeSet ? await createDiffChangeSet({
let resourcesToImportLogicalIds = new Set<string>();
resourcesToImport?.forEach((value: CloudFormation.ResourceToImport, _index: number, _array: CloudFormation.ResourceToImport[]) => {
resourcesToImportLogicalIds.add(value.LogicalResourceId);
});

let changeSet = options.changeSet ? await createDiffChangeSet({
stack,
uuid: uuid.v4(),
deployments: this.props.deployments,
Expand All @@ -178,6 +184,12 @@ export class CdkToolkit {
stream,
}) : undefined;

changeSet?.Changes?.forEach((value: CloudFormation.Change, _index: number, _array: CloudFormation.Change[]) => {
if (resourcesToImportLogicalIds.has(value.ResourceChange?.LogicalResourceId!)) {
value.ResourceChange!.Action = 'Import';
}
});

if (resourcesToImport) {
stream.write('Parameters and rules created during migration do not affect resource configuration.\n');
}
Expand Down

0 comments on commit bcb544c

Please sign in to comment.