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

Cannot get .resourceType, because the type was changed #13921

Closed
DmPanov opened this issue Apr 1, 2021 · 5 comments · Fixed by #19891
Closed

Cannot get .resourceType, because the type was changed #13921

DmPanov opened this issue Apr 1, 2021 · 5 comments · Fixed by #19891
Labels
@aws-cdk/cloudformation-diff bug This issue is a bug. effort/medium Medium work item – several days of effort p1 package/tools Related to AWS CDK Tools or CLI

Comments

@DmPanov
Copy link

DmPanov commented Apr 1, 2021

cdk diff exits with Cannot get .resourceType, because the type was changed error message, cdk synth works fine.

Reproduction Steps

Cannot provide them, I still have no idea how I ended up in that state, sorry.

What did you expect to happen?

Diff should be shown or at least a clear error message with exact resource id, old and new types.

What actually happened?

Cannot get .resourceType, because the type was changed

Environment

  • CDK CLI Version : 1.95.1
  • Framework Version: 1.95.1
  • Node.js Version: v15.12.0
  • OS : macOS 11.2.3
  • Language (Version): Java (8)

Other

Reading existing template for stack
Cannot get .resourceType, because the type was changed
Error: Cannot get .resourceType, because the type was changed
    at ResourceDifference.get resourceType [as resourceType] (/usr/local/lib/node_modules/aws-cdk/node_modules/@aws-cdk/cloudformation-diff/lib/diff/types.ts:587:13)
    at TemplateDiff.scrutinizablePropertyChanges (/usr/local/lib/node_modules/aws-cdk/node_modules/@aws-cdk/cloudformation-diff/lib/diff/types.ts:124:40)
    at new TemplateDiff (/usr/local/lib/node_modules/aws-cdk/node_modules/@aws-cdk/cloudformation-diff/lib/diff/types.ts:53:29)
    at calculateTemplateDiff (/usr/local/lib/node_modules/aws-cdk/node_modules/@aws-cdk/cloudformation-diff/lib/diff-template.ts:110:10)
    at Object.diffTemplate (/usr/local/lib/node_modules/aws-cdk/node_modules/@aws-cdk/cloudformation-diff/lib/diff-template.ts:43:19)
    at Object.printStackDiff (/usr/local/lib/node_modules/aws-cdk/lib/diff.ts:24:24)
    at CdkToolkit.diff (/usr/local/lib/node_modules/aws-cdk/lib/cdk-toolkit.ts:103:18)
    at processTicksAndRejections (node:internal/process/task_queues:94:5)
    at initCommandLine (/usr/local/lib/node_modules/aws-cdk/bin/cdk.ts:208:9)

This is 🐛 Bug Report

@DmPanov DmPanov added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Apr 1, 2021
@peterwoodworth peterwoodworth added the package/tools Related to AWS CDK Tools or CLI label Apr 2, 2021
@rix0rrr rix0rrr assigned skinny85 and unassigned rix0rrr Apr 2, 2021
@rix0rrr
Copy link
Contributor

rix0rrr commented Apr 2, 2021

I think the issue is that your deployed stack and your new proposed template have a resource with the same logical ID, but a different Type.

Apparently our diff tool doesn't deal with that situation very well.

@skinny85
Copy link
Contributor

skinny85 commented Apr 5, 2021

Thanks for reporting @DmPanov . Yes, this is a flaw in the cloudformation-diff module that I hope to fix one day.

@skinny85 skinny85 added effort/medium Medium work item – several days of effort p1 and removed needs-triage This issue or PR still needs to be triaged. labels Apr 5, 2021
@shefaa89
Copy link

I'm facing the same problem described earlier by DmPanov.
I tried doing cdk diff my-stack --template template.json, which exists and shows a handful of trivial differences, none of which are resource type changes. Next, I compared the 'Type' fields on all the resources from the before and after and there were no difference. diff <(cat before-template.json| grep '"Type":' | sort) <(cat after-template.json | grep '"Type":' | sort) | less.
I'm surprised that cdk diff fails, while cdk diff --template completes. Also, could the error message here be a bit misleading? Hinting incorrectly that a resource type has changed.

@dannyfritz
Copy link

dannyfritz commented Jan 28, 2022

Is there a suggested workaround for this? I'm using CfnInclude.

When I copy the template (a yaml file using a serverless transform) I get this:

Maximum call stack size exceeded
Subprocess exited with error 1
Error: Subprocess exited with error 1
    at ChildProcess.<anonymous> (/Users/daniel.fritz/Dev/sales-platform-auth-service/node_modules/aws-cdk/lib/api/cxapp/exec.ts:127:23)
    at ChildProcess.emit (events.js:400:28)
    at ChildProcess.emit (domain.js:470:12)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:277:12)

^^^ is this bug #16654

But then when I copy the processed json template I get this:

daniel.fritz ~/Dev/sales-platform-auth-service (convert-to-cdk x!?)
% ENV_VAR=devmaj cdk diff
[Info at /local-sales-platform-auth-service/local-template/$Mappings/EnvMap] Consider making this CfnMapping a lazy mapping by providing `lazy: true`: either no findInMap was called or every findInMap could be immediately resolved without using Fn::FindInMap
Stack local-sales-platform-auth-service
Cannot get .resourceType, because the type was changed

⏱: 0h:00m:08s
(1) daniel.fritz ~/Dev/sales-platform-auth-service (convert-to-cdk x!?)
%

The type it is complaining about (after adding in some logs) being changed is:

Stack local-sales-platform-auth-service
Reading existing template for stack local-sales-platform-auth-service.
Retrieved account ID *** from disk cache
Assuming role 'arn:aws:iam::***:role/cdk-hnb659fds-lookup-role-***-us-west-2'.
{ oldType: 'AWS::KMS::Key', newType: 'AWS::KMS::Key' }
{ oldType: 'AWS::KMS::Key', newType: 'AWS::KMS::Key' }
{
  oldType: 'AWS::Serverless::Api',
  newType: 'AWS::ApiGateway::RestApi'
}
Cannot get .resourceType, because the type was changed
Error: Cannot get .resourceType, because the type was changed
    at ResourceDifference.get resourceType [as resourceType] (/Users/daniel.fritz/Dev/sales-platform-auth-service/node_modules/aws-cdk/node_modules/@aws-cdk/cloudformation-diff/lib/diff/types.ts:588:6)
    at TemplateDiff.scrutinizablePropertyChanges (/Users/daniel.fritz/Dev/sales-platform-auth-service/node_modules/aws-cdk/node_modules/@aws-cdk/cloudformation-diff/lib/diff/types.ts:124:40)
    at new TemplateDiff (/Users/daniel.fritz/Dev/sales-platform-auth-service/node_modules/aws-cdk/node_modules/@aws-cdk/cloudformation-diff/lib/diff/types.ts:53:29)
    at calculateTemplateDiff (/Users/daniel.fritz/Dev/sales-platform-auth-service/node_modules/aws-cdk/node_modules/@aws-cdk/cloudformation-diff/lib/diff-template.ts:114:10)
    at Object.diffTemplate (/Users/daniel.fritz/Dev/sales-platform-auth-service/node_modules/aws-cdk/node_modules/@aws-cdk/cloudformation-diff/lib/diff-template.ts:43:19)
    at Object.printStackDiff (/Users/daniel.fritz/Dev/sales-platform-auth-service/node_modules/aws-cdk/lib/diff.ts:24:24)
    at CdkToolkit.diff (/Users/daniel.fritz/Dev/sales-platform-auth-service/node_modules/aws-cdk/lib/cdk-toolkit.ts:110:13)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at initCommandLine (/Users/daniel.fritz/Dev/sales-platform-auth-service/node_modules/aws-cdk/bin/cdk.ts:281:9)

⏱: 0h:00m:08s
(1) daniel.fritz ~/Dev/sales-platform-auth-service (convert-to-cdk x!?)
%

UPDATE: Fixed this by doing cdk deploy --no-execute and executing the change-set through the AWS Console. It deploys normally now.

skinny85 added a commit to skinny85/aws-cdk that referenced this issue Apr 13, 2022
When writing the cloudformation-diff module,
it was assumed that resources would never change their CloudFormation types between deployments.
As it turns out, there is a legitimate case for resources changing types,
and that's when you migrate from a template that uses Transforms
(like the Serverless Transform) to one that doesn't use them.

Because of that, handle the case of resources changing types in diff.

Fixes aws#13921
@mergify mergify bot closed this as completed in #19891 Apr 14, 2022
mergify bot pushed a commit that referenced this issue Apr 14, 2022
When writing the cloudformation-diff module,
it was assumed that resources would never change their CloudFormation types between deployments.
As it turns out, there is a legitimate case for resources changing types,
and that's when you migrate from a template that uses Transforms
(like the Serverless Transform) to one that doesn't use them.

Because of that, handle the case of resources changing types in diff.

Fixes #13921

----

### All Submissions:

* [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md)

### Adding new Unconventional Dependencies:

* [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md/#adding-new-unconventional-dependencies)

### New Features

* [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/master/INTEGRATION_TESTS.md)?
	* [ ] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)?

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

StevePotter pushed a commit to StevePotter/aws-cdk that referenced this issue Apr 27, 2022
When writing the cloudformation-diff module,
it was assumed that resources would never change their CloudFormation types between deployments.
As it turns out, there is a legitimate case for resources changing types,
and that's when you migrate from a template that uses Transforms
(like the Serverless Transform) to one that doesn't use them.

Because of that, handle the case of resources changing types in diff.

Fixes aws#13921

----

### All Submissions:

* [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md)

### Adding new Unconventional Dependencies:

* [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md/#adding-new-unconventional-dependencies)

### New Features

* [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/master/INTEGRATION_TESTS.md)?
	* [ ] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)?

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/cloudformation-diff bug This issue is a bug. effort/medium Medium work item – several days of effort p1 package/tools Related to AWS CDK Tools or CLI
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants