'Terraform - AWS Auto-Scaling-Group not deleting when using Suspended-Policy option for 'Terminate'
I've searched online and not found an answer to this anywhere, so apologies if it is a replicate of another question.
I've created a CloudFormation Template from scratch (that I've carried over to Terraform) that entirely creates a cluster of instances with specific requirements input at the start. A part of this is an Auto-Scaling-Group of which, for reasons, I want to suspend the Terminate policy. Now in CFT land, there is no way (or wasn't) to create an ASG with this setting, and instead I had to use a Lambda function to do it after creation as part of the CFT. This, though complex considering the little it did, works a charm!
Over in Terraform, for whatever reason, I cannot, for the life of me, make the Lambda Function do its thing. It creates, and it exists, I can see the code in Lambda perfectly. But it doesn't do anything - This is a separate issue - As such, I discovered that the, "aws_autoscaling_group" with Terraform actually has a "suspended_processes" option (See code below). This creates the ASG as required, with the policy suspended, but then when I try and 'Destroy' the cluster created by Terraform, it hangs and cannot actually do it - Like the Terminate policy is stopping it from doing this (which makes sense, I guess...). Now AWS CloudFormation is clever enough to go around that, but it seems Terraform is not. Is there a sensible way to get this system doing what I need without causing issues? I love Terraform, but for this specific tiny task I've had nothing but issues and difficulties.
My code:
resource "aws_autoscaling_group" "Cluster_Example" {
name = <Stuff>
launch_configuration = <Stuff>
vpc_zone_identifier = <Stuff>
desired_capacity = <Stuff>
placement_group = <Stuff>
min_size = <Stuff>
max_size = <Stuff>
suspended_processes = [ "Terminate" ]
}
To clarify, I am trying to automate all of this (reasons). So yes, just going into the ASG at the time I want to delete it and just removing the suspension manually is an option, but definitely not the one I want.
Cheers in advance for any assistance! Vinny
Solution 1:[1]
Okaaaaay took me a while longer to solve this than I wanted, but I do have a 'solution'... Sort of... Basically, it is as simple as adding one extra condition to the group, 'force-delete', as follows:
resource "aws_autoscaling_group" "Cluster_Example" {
<Stuff>
suspended_processes = [ "Terminate" ]
force_delete = "true"
}
This ensures that nothing blocks the deletion of the group, HOWEVER, it can cause resources to be left hanging afterwards un-intentionally. Fortunately, in my case, the instances are always deleted as they are asked to be deleted, but only cannot be because of the suspension. So as soon as the group dies, so too do they!
Considering this option isn't really meant for this purpose, it isn't the nicest solution, I'll be honest, but it is a solution at this point as far as I'm concerned.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Vinny Pem |