Skip to content

Commit

Permalink
fix: stops cdk v1 warning for non cdk custom resource (#12241) (#12249)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
3 people committed Mar 16, 2023
1 parent f45671b commit 99683bd
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"AWSTemplateFormatVersion": "2010-09-09",
"Parameters": {
"env": {
"Type": "String"
}
},
"Resources": {
"HelloBucket": {
"Type": "AWS::S3::Bucket"
}
},
"Outputs": {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,25 @@ describe('adding custom resources migration test', () => {
it('add/update CDK and CFN custom resources', async () => {
const cdkResourceName = `custom${uuid().split('-')[0]}`;
const cfnResourceName = `custom${uuid().split('-')[0]}`;
const cfnResourceNameWithV10 = `custom${uuid().split('-')[0]}`;

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

await addCDKCustomResource(projRoot, { name: cdkResourceName });
await addCFNCustomResource(projRoot, { name: cfnResourceNameWithV10, promptForCategorySelection: false });
const srcCFNCustomResourceFilePath = path.join(__dirname, '..', '..', '..', 'custom-resources', 'custom-cfn-stack.json');
// adding a resource to custom cfn stack
const destCFNCustomResourceFilePath = path.join(
projRoot,
'amplify',
'backend',
'custom',
cfnResourceNameWithV10,
`${cfnResourceNameWithV10}-cloudformation-template.json`,
);
fs.copyFileSync(srcCFNCustomResourceFilePath, destCFNCustomResourceFilePath);

// this is where we will write our custom cdk stack logic to
const destCustomResourceFilePath = path.join(projRoot, 'amplify', 'backend', 'custom', cdkResourceName, 'cdk-stack.ts');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ describe('print migration warning tests', () => {
{
category: 'custom',
resourceName: 'someResource2',
service: 'mockService2',
service: 'customCDK',
},
];

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

it('no migration message when there are only custom CFN resources', async () => {
const resourcesToBeCreated = [
{
category: 'auth',
resourceName: 'someResource',
service: 'Cognito',
},
];
const resourcesToBeUpdated = [
{
category: 'custom',
resourceName: 'someResource3',
service: 'customCloudformation',
},
];

const allResources = [...resourcesToBeCreated, ...resourcesToBeUpdated];
mockContext.amplify.getResourceStatus.mockResolvedValue({ allResources });
detectAffectedDirectDependenciesMock.mockReturnValue(inputPayload);
fsMock.existsSync.mockReturnValue(false);
printerMock.warn.mockReturnValue(undefined);
await printCdkMigrationWarning(mockContext as unknown as $TSContext);
expect(printerMock.warn).not.toBeCalled();
});

it('migration message when there are only overrides', async () => {
const resourcesToBeCreated = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ const getOverridesWarning = (resourcesToBuild: IAmplifyResource[], dependencyToS
const getCustomResourcesWarning = (resourcesToBuild: IAmplifyResource[], dependencyToSearch: string): AmplifyWarning | undefined => {
let customResourcesWarningObject;
const customResourceImpactedFiles = [];
const customCategoryResources = resourcesToBuild.filter((resource) => resource.category === AmplifyCategories.CUSTOM);
const customCategoryResources = resourcesToBuild.filter(
(resource) => resource.category === AmplifyCategories.CUSTOM && resource.service !== 'customCloudformation',
);
customCategoryResources.forEach((resource) => {
const targetDir = path.join(pathManager.getBackendDirPath(), resource.category, resource.resourceName);
const amplifyDetectorProps: AmplifyNodePkgDetectorProps = {
Expand Down

0 comments on commit 99683bd

Please sign in to comment.