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(cfn-diff): allow resources to change types #19891

Merged
merged 2 commits into from
Apr 14, 2022

Conversation

skinny85
Copy link
Contributor

@skinny85 skinny85 commented 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 #13921


All Submissions:

Adding new Unconventional Dependencies:

  • This PR adds new unconventional dependencies following the process described here

New Features

  • Have you added the new feature to an integration test?
    • 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

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
@skinny85 skinny85 requested a review from rix0rrr April 13, 2022 01:00
@gitpod-io
Copy link

gitpod-io bot commented Apr 13, 2022

@github-actions github-actions bot added bug This issue is a bug. effort/medium Medium work item – several days of effort p1 labels Apr 13, 2022
@aws-cdk-automation aws-cdk-automation requested a review from a team April 13, 2022 01:00
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Apr 13, 2022
Copy link
Contributor

@rix0rrr rix0rrr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be interpreted as a replacement, no?

@skinny85
Copy link
Contributor Author

skinny85 commented Apr 13, 2022

This needs to be interpreted as a replacement, no?

Yes, this is already handled by scrutinizableResourceChanges() here:

// Even though it's not physically possible in CFN, let's pretend to handle a change of 'Type'.
if (resourceChange.resourceTypeChanged) {
// Treat as DELETE+ADD

This is how the experience looks like in the CDK CLI:

$ yarn cdk diff

...

Resources
[+] AWS::IAM::Role S1/Template/LambdaSaverRole LambdaSaverRole 
[+] AWS::ApiGateway::Deployment S1/Template/SaveApiDeployment14a59e22ee SaveApiDeployment14a59e22ee 
[+] AWS::ApiGateway::Stage S1/Template/SaveApiprodStage SaveApiprodStage 
[+] AWS::Lambda::Permission S1/Template/LambdaSaverSaveApiPermissionprod LambdaSaverSaveApiPermissionprod 
[~] AWS::Lambda::Function S1/Template/LambdaSaver LambdaSaver replace
[~] AWS::ApiGateway::RestApi S1/Template/SaveApi SaveApi replace

@rix0rrr
Copy link
Contributor

rix0rrr commented Apr 14, 2022

Yes, this is already handled by scrutinizableResourceChanges() here:

Damn that sounds weird

@mergify
Copy link
Contributor

mergify bot commented Apr 14, 2022

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject89A8053A-LhjRyN9kxr8o
  • Commit ID: 1d731cd
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify
Copy link
Contributor

mergify bot commented Apr 14, 2022

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify mergify bot merged commit 4f3a340 into aws:master Apr 14, 2022
@skinny85 skinny85 deleted the diff-resource-type-change branch April 14, 2022 16:08
@skinny85
Copy link
Contributor Author

Yes, this is already handled by scrutinizableResourceChanges() here:

Damn that sounds weird

I think that's because you can't really handle the replacement of an entire resource on the level of the property change, so that's why you can't do it from scrutinizablePropertyChanges ().

StevePotter pushed a commit to StevePotter/aws-cdk that referenced this pull request 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
bug This issue is a bug. contribution/core This is a PR that came from AWS. effort/medium Medium work item – several days of effort p1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot get .resourceType, because the type was changed
3 participants