CloudFormation drift detection - can you automatically "fix" the drift?

Here is what I’m guessing is a pretty common scenario, I have a stack, new guy went in and deleted something inside the stack manually, now clearly I have “drift” detected. But is there a way to re-create this deleted resource automagically? Or does drift detection just tell me it’s missing, but I have to go recreate it manually (if I want it to be outside the stack), or I have to recreate the entire stack?


Related discussions:

No, although they said in a re:Invent talk that they plan to add this functionality over time.

Well considering Drift detection was announced at 2017 re:invent and came out like a week before 2018 re:invent… We might be waiting a little while.

You can remove the resource from the template, update, get the resource back in the template, (git checkout) then update again.

lame, thanks. do you know if termination protection applies to any resource in the stack, or only if you try to delete the entire stack? docs say it only protects the entire stack.. which seems like another big limitation imo

From the other angle, if the stack has drifted because of manual deletion of assets/services no longer used, is there any way to delete the stack without it deleting any remaining stray resources?

Yes, there now appears to be an option to “retain” resources when deleting the stack. To trigger the dialog in the console, you first have to get the delete to fail - it will then prompt you with a list of resources it failed to delete, and give you the option to retain each one while deleting the stack. Might be a way through the cmdline to just “dissolve” the stack and keep the resources.

!RemindMe 1week

Hi there! I see you used the remind me bot

This is the MsgMe Bot!If you don’t want a reminder, and just want to save a post, then this bot will help you send you a message with the post details

How it works:

Just type !MsgMe or !MessageMe (case insensitive) and you will get a message with the subject ‘Saved Post’

If you want a custom title then write !MsgMe (or !MessageMe) followed by the subject you want

For example, !MessageMe Cool Post will send you a message with the subject ‘Cool Post’

I will be messaging you on [2019-01-30 09:12:28 UTC](http://www.wolframalpha.com/input/?i=2019-01-30 09:12:28 UTC To Local Time) to remind you of this link.

[CLICK THIS LINK](http://np.reddit.com/message/compose/?to=RemindMeBot&subject=Reminder&message=[https://www.reddit.com/r/aws/comments/aiu0vv/cloudformation_drift_detection_can_you/] RemindMe! 1week) to send a PM to also be reminded and to reduce spam.

^(Parent commenter can ) [^(delete this message to hide from others.)](http://np.reddit.com/message/compose/?to=RemindMeBot&subject=Delete Comment&message=Delete! eer8px0)


^(FAQs) [^(Custom)](http://np.reddit.com/message/compose/?to=RemindMeBot&subject=Reminder&message=[LINK INSIDE SQUARE BRACKETS else default to FAQs]%0A%0ANOTE: Don’t forget to add the time options after the command.%0A%0ARemindMe!) [^(Your Reminders)](http://np.reddit.com/message/compose/?to=RemindMeBot&subject=List Of Reminders&message=MyReminders!) ^(Feedback) ^(Code) ^(Browser Extensions)

It’s only for deleting the entire stack. For individual resources you use a stack policy

I dont believe this is true.. you described why the drift detection is needed. Cloudformation will reapply things if the new template info differs from the last template info. If in the real world someone deletes a port on a security group, and you re-run the template it says “NEW:443, LAST: 443 - NO ACTION!” and doesn’t re-apply them.. i.e. drift.

Apologies, yes I just tested this and you’re right - I must have been getting it confused with something else, possibly Terraform behaviour. Deleted the original comment so there’s no confusion!

What would your next step be, though? Until CF has some option like Terraform’s ‘import’ to bring a pre-existing resource under control of a stack definition, you’re just making the problem worse by deleting the stack and leaving behind all the resources with the names you want to use.

A little while indeed

I am still waiting for this feature…

I am from the future and I have bad news.