Skip to content

Commit 99683bd

Browse files
Kamil SobolakshbhuAkshay Upadhyay
authored
fix: stops cdk v1 warning for non cdk custom resource (#12241) (#12249)
* fix: stops cdk warning for non cdk custom resource * fix: added unit test --------- Co-authored-by: akshbhu <39866697+akshbhu@users.noreply.github.com> Co-authored-by: Akshay Upadhyay <akz@amazon.com>
1 parent f45671b commit 99683bd

File tree

4 files changed

+56
-2
lines changed

4 files changed

+56
-2
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"AWSTemplateFormatVersion": "2010-09-09",
3+
"Parameters": {
4+
"env": {
5+
"Type": "String"
6+
}
7+
},
8+
"Resources": {
9+
"HelloBucket": {
10+
"Type": "AWS::S3::Bucket"
11+
}
12+
},
13+
"Outputs": {}
14+
}

packages/amplify-migration-tests/src/__tests__/migration_tests_v10/custom-stack.migration.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,25 @@ describe('adding custom resources migration test', () => {
3232
it('add/update CDK and CFN custom resources', async () => {
3333
const cdkResourceName = `custom${uuid().split('-')[0]}`;
3434
const cfnResourceName = `custom${uuid().split('-')[0]}`;
35+
const cfnResourceNameWithV10 = `custom${uuid().split('-')[0]}`;
3536

3637
await initJSProjectWithProfileV10(projRoot, { name: 'customMigration', disableAmplifyAppCreation: false });
3738
const appId = getAppId(projRoot);
3839
expect(appId).toBeDefined();
3940

4041
await addCDKCustomResource(projRoot, { name: cdkResourceName });
42+
await addCFNCustomResource(projRoot, { name: cfnResourceNameWithV10, promptForCategorySelection: false });
43+
const srcCFNCustomResourceFilePath = path.join(__dirname, '..', '..', '..', 'custom-resources', 'custom-cfn-stack.json');
44+
// adding a resource to custom cfn stack
45+
const destCFNCustomResourceFilePath = path.join(
46+
projRoot,
47+
'amplify',
48+
'backend',
49+
'custom',
50+
cfnResourceNameWithV10,
51+
`${cfnResourceNameWithV10}-cloudformation-template.json`,
52+
);
53+
fs.copyFileSync(srcCFNCustomResourceFilePath, destCFNCustomResourceFilePath);
4154

4255
// this is where we will write our custom cdk stack logic to
4356
const destCustomResourceFilePath = path.join(projRoot, 'amplify', 'backend', 'custom', cdkResourceName, 'cdk-stack.ts');

packages/amplify-provider-awscloudformation/src/__tests__/print-cdk-migration-warning.test.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ describe('print migration warning tests', () => {
105105
{
106106
category: 'custom',
107107
resourceName: 'someResource2',
108-
service: 'mockService2',
108+
service: 'customCDK',
109109
},
110110
];
111111

@@ -128,6 +128,31 @@ describe('print migration warning tests', () => {
128128
`);
129129
});
130130

131+
it('no migration message when there are only custom CFN resources', async () => {
132+
const resourcesToBeCreated = [
133+
{
134+
category: 'auth',
135+
resourceName: 'someResource',
136+
service: 'Cognito',
137+
},
138+
];
139+
const resourcesToBeUpdated = [
140+
{
141+
category: 'custom',
142+
resourceName: 'someResource3',
143+
service: 'customCloudformation',
144+
},
145+
];
146+
147+
const allResources = [...resourcesToBeCreated, ...resourcesToBeUpdated];
148+
mockContext.amplify.getResourceStatus.mockResolvedValue({ allResources });
149+
detectAffectedDirectDependenciesMock.mockReturnValue(inputPayload);
150+
fsMock.existsSync.mockReturnValue(false);
151+
printerMock.warn.mockReturnValue(undefined);
152+
await printCdkMigrationWarning(mockContext as unknown as $TSContext);
153+
expect(printerMock.warn).not.toBeCalled();
154+
});
155+
131156
it('migration message when there are only overrides', async () => {
132157
const resourcesToBeCreated = [
133158
{

packages/amplify-provider-awscloudformation/src/print-cdk-migration-warning.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ const getOverridesWarning = (resourcesToBuild: IAmplifyResource[], dependencyToS
6565
const getCustomResourcesWarning = (resourcesToBuild: IAmplifyResource[], dependencyToSearch: string): AmplifyWarning | undefined => {
6666
let customResourcesWarningObject;
6767
const customResourceImpactedFiles = [];
68-
const customCategoryResources = resourcesToBuild.filter((resource) => resource.category === AmplifyCategories.CUSTOM);
68+
const customCategoryResources = resourcesToBuild.filter(
69+
(resource) => resource.category === AmplifyCategories.CUSTOM && resource.service !== 'customCloudformation',
70+
);
6971
customCategoryResources.forEach((resource) => {
7072
const targetDir = path.join(pathManager.getBackendDirPath(), resource.category, resource.resourceName);
7173
const amplifyDetectorProps: AmplifyNodePkgDetectorProps = {

0 commit comments

Comments
 (0)