We have bastion hosts managed via the CDK. A pen test required they have DisableApiTermination=true set on them, and we do that via a cloud formation override as so:
var cfnBastion = (CfnInstance) bastion.getNode().getDefaultChild().getNode().getDefaultChild();
cfnBastion.addPropertyOverride("DisableApiTermination", true);```
However, now whenever Amazon update the kernel version cloudformation decides to add a new bastion and delete the old one - which fails because of the api termination protection!
Is there a hook to allow the CDK specifically to allow api termination?
The DisableApiTermination attribute does not prevent you from terminating an instance by initiating shutdown from the instance (using an operating system command for system shutdown) when the InstanceInitiatedShutdownBehavior attribute is set
I’m thinking that using an auto scaling group is the best option for a bastion, and then cdk just needs to deal with the autoscaling group configuration and the launch template
But as a quick workaround you can just sequentially disable the termination protection and terminate it, but still spin up new instances with the termination protection enabled :man-shrugging: