Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: stops cdk v1 warning for non cdk custom resource #12241

Merged
merged 2 commits into from
Mar 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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