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

Allow drift detection #1723

Closed
gaffo opened this issue Feb 10, 2019 · 29 comments
Closed

Allow drift detection #1723

gaffo opened this issue Feb 10, 2019 · 29 comments
Labels
effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p1 package/tools Related to AWS CDK Tools or CLI

Comments

@gaffo
Copy link

gaffo commented Feb 10, 2019

There doesn't see to be a way to enable drift detection in CDK.

@eladb eladb added the feature-request A feature should be added or improved. label Feb 11, 2019
@rix0rrr
Copy link
Contributor

rix0rrr commented Mar 4, 2019

Do you mean, start a drift detection action on a stack?

That's right, that feature is not built into the CDK. We could conceivably add a cdk drift command to perform a drift detection cycle, but there would not be a lot of advantage over making the CloudFormation call directly.

@rix0rrr rix0rrr added the package/tools Related to AWS CDK Tools or CLI label Mar 4, 2019
@gaffo
Copy link
Author

gaffo commented Mar 4, 2019 via email

@rix0rrr
Copy link
Contributor

rix0rrr commented Mar 5, 2019

Please take this up with CloudFormation if you have any requests regarding keeping reality in sync with the template on a continuous basis.

CDK will get your application model to CloudFormation. CloudFormation will get your application model to reality, and do any and all of the work to keep it there.

@SomayaB SomayaB added the needs-cfn This issue is waiting on changes to CloudFormation before it can be addressed. label Oct 26, 2019
@SomayaB SomayaB closed this as completed Oct 26, 2019
@bpcrao
Copy link

bpcrao commented Feb 4, 2020

I think this is much needed feature

I wont be able to see the Diff of "AWS INFRA" compared with my "Stack template"
since after CDK deploy some one can modify things from AWS Console

@shivlaks
Copy link
Contributor

shivlaks commented Feb 4, 2020

@bpcrao As @rix0rrr mentioned earlier, the implementation would be to potentially add a cdk drift command, but it would still ultimately be CloudFormation that will compare templated resources against actual resources.

Although CloudFormation supports drift detection, it's limited to these resources. There is a lot of surface area that is still not covered by CloudFormation drift detection

@shivlaks shivlaks added the effort/medium Medium work item – several days of effort label Feb 4, 2020
@shivlaks shivlaks added the p2 label Aug 7, 2020
@Juberstine
Copy link

@shivlaks Is correct but I'd still like to see this feature added.

@daisuke-yoshimoto
Copy link
Contributor

@shivlaks @rix0rrr

Are there any updates to this issue? It would be great if it could be completed within the cdk toolchain like cdk diff.

@NGL321 NGL321 assigned rix0rrr and unassigned shivlaks Jan 25, 2021
@haimlit
Copy link
Contributor

haimlit commented May 25, 2021

cdk-drift-monitor, a new repo, tries to solve this issue. Looking forward for feedback and comments!

@rix0rrr rix0rrr removed their assignment Jun 3, 2021
@awworrell
Copy link

Is there an update on this issue? I would say this feature is absolutely vital to have in cdk if it's going to be used as a replacement for products like terraform. In terraform, the command terraform plan shows not only how the environment will be changed based on the changes made in the code but also the drift that exists and what will be changed back to the state of the code. Given cdk doesn't have this feature, it's a massive gap.

In every organization I've worked for, using terraform plan to understand the impacts to a production environment is how one can tell the scope of change and understand any drift. Personally, i think cdk diff should do that naturally. Sure it may need to be coordinated with the cloudformation team and the cloudformation team will need to extend what is supported beyond what already exists at https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/resource-import-supported-resources.html.

@awworrell
Copy link

cdk-drift-monitor, a new repo, tries to solve this issue. Looking forward for feedback and comments!

It's great to have a separate repo; however, cdk should do this naturally.

@dmschauer
Copy link

I agree with others who said that this is a feature in high demand.

Take a look at this thread (one of the top search results for me when googling "terraform or aws cdk). Drift detection is THE main point of critique for people who still prefer Terraform over AWS CDK. Personally I just started out with AWS CDK and like it a lot. I wouldn't like advocating for it at work only for others to shoot down its adoption with the drift detection argument...

In my limited experience AWS CDK saves so much time spent dreadfully on manually specifying permissions that it would be a shame if it wasn't adopted only because this feature needs some alignment with the CloudFormation team.

@maximillianus
Copy link

I am quite surprised as well that this drift detection feature does not exist. I kinda expect that cdk diff will do this naturally. Agree with the others that this feature will be quite vital to have in AWS CDK. It's hard to detect changes in our deployed CDK infrastructure.

@github-actions github-actions bot added p1 and removed p2 labels May 22, 2022
@github-actions
Copy link

This issue has received a significant amount of attention so we are automatically upgrading its priority. A member of the community will see the re-prioritization and provide an update on the issue.

@comcalvi comcalvi added effort/large Large work item – several weeks of effort and removed effort/medium Medium work item – several days of effort labels Jun 8, 2022
@peterwoodworth peterwoodworth removed the needs-cfn This issue is waiting on changes to CloudFormation before it can be addressed. label Jun 20, 2022
@Naumel
Copy link
Contributor

Naumel commented Aug 31, 2022

Hello all,
We have noted the community engagement on this issue and we understand its importance.
Since there are a number of such items, we need to make sure that we’re working on the most important ones.
This means that the issue will be moved into the backlog; it will be checked against the other projects for complexity, risk and effort versus benefit.
We will keep posting updates as they become available!

@pauldraper
Copy link

pauldraper commented Oct 21, 2022

CDK will get your application model to CloudFormation. CloudFormation will get your application model to reality, and do any and all of the work to keep it there.

I've seen CDK interact a lot more than that. You make it seem like a JSON generator.

I'm seen it give progress of CloudFormation applying the template.

@keoma-di
Copy link

Glad this is in the backlog now. It's an important feature.

@pauldraper
Copy link

pauldraper commented Oct 24, 2022

Note that Cloudformation (and therefore CDK) has no way of automatically resolving drift.

So this would detect and display the drift, but not be able to anything further. (That simply requires a different tool, e.g. Terraform.)

@comcalvi comcalvi added effort/medium Medium work item – several days of effort and removed effort/large Large work item – several weeks of effort labels Jan 24, 2023
@misterjacko
Copy link
Contributor

I just had an issue where an ingress rule that was added to a SG by CDK was removed SoMehOw. CDK should be able to let me know that that ingress rule is now missing on the next diff or plan or something.

Suggesting the use of the AWS tool that we are trying to avoid by using CDK is not very customer obsessive.

@tmegow
Copy link

tmegow commented Apr 19, 2023

Create a lambda function using CDK. Then delete the function. Now cdk diff and cdk deploy will never inform that the function is missing, nor will it be recreated.

@rix0rrr
Copy link
Contributor

rix0rrr commented Nov 28, 2023

The steps to perform drift reconciliation in CloudFormation are as follows:

  • Run a drift detection operation
  • For all the resources that have drift:
    • Set RemovalPolicy to RETAIN
    • Deploy
    • Remove from template
    • Deploy
    • Correct state in template to match detected drift
    • Run an IMPORT operation on the resources to get them managed by CloudFormation again

The next deployment with the actual desired state (CDK app) will now get rid of the drift.

If there is enough information in the drift report, we could streamline this process by performing these steps on behalf of the user (patching the template and redeploying).

There is a risky bit in between where we dropped the resources and we still need to do the IMPORT: if we fail in between those steps, we leave the user's stack in a state that is probably not very obvious to them how to recover from it.

Complications: changes made by Custom Resources cannot be detected in this way.

@vumdao
Copy link

vumdao commented Nov 29, 2023

@rix0rrr How is the step Remove from template? Is it done through CFN or CDK code ?

@rix0rrr
Copy link
Contributor

rix0rrr commented Nov 29, 2023

I would recommend you do this by doing surgery on the CFN template. You can also achieve it by editing your CDK app, but you want to restore your CDK app to the original state before doing the final deploy.

@misterjacko
Copy link
Contributor

misterjacko commented Nov 29, 2023

@rix0rrr are you outlining the drift reconciliation steps as an illustration of just how awkward and user hostile current methods are?

I continue to contend that people use CDK because they don't want to mess about in CloudFormation..

@rix0rrr
Copy link
Contributor

rix0rrr commented Nov 30, 2023

@misterjacko, point well-taken, and I agree that it's awkward.

From our end it's unlikely that we'll have the availability to work on this, so I'm outlining the steps so that a person who is so inclined can think about automating them; perhaps as an experimental CDK CLI feature, perhaps as a standalone tool (because none of these steps are really CDK-specific).

The overall idea seems simple enough, but I'm sure there's a long tail of problems that need to be resolved to make this work well enough for real world uses.

@evgenyka
Copy link
Contributor

evgenyka commented Feb 21, 2024

We can initiate and display the drift, but the output will be CloudFormation YAML, not CDK code. It's important to note that we cannot automatically generate CDK abstractions from CFN YAML to rectify the stack or the drift, as these are not bidirectional. Therefore, the best-case scenario is that you'll receive the same output as CFN describe-stack-resource-drifts.

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.

@dmschauer
Copy link

Question to the community: Since this issue was closed as "completed" I assume that Terraform is the superior tool for AWS users who care about drift detection. Anything wrong with this way of thinking about it? The way I see it the simple use case in #1723 (comment) wasn't resolved or am I missing something?

@misterjacko
Copy link
Contributor

Question to the community: Since this issue was closed as "completed" I assume that Terraform is the superior tool for AWS users who care about drift detection. Anything wrong with this way of thinking about it? The way I see it the simple use case in #1723 (comment) wasn't resolved or am I missing something?

100% agree that if you want declarative IaC CDK is not the right tool.

@sammcj
Copy link

sammcj commented Apr 30, 2024

It's a real shame to see this closed without any fix.

CDK remains vastly inferior to Terraform when it comes to managing state and state resolution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p1 package/tools Related to AWS CDK Tools or CLI
Projects
None yet
Development

No branches or pull requests