I have been using CloudFormation for the past 3 years to manage AWS infrastructure which consists of multiple auto-scaling groups with immutable AMIs (amongst other things). I am trying to rewrite around 5 CloudFormation stacks to Terraform now. Most of if it is not a problem.
The difficult part is the auto-scaling groups, specifically the part where I want to make sure that when a new auto-scaling group replaces the old one, all EC2 and ELB (or target group) health checks must pass before retiring the old auto-scaling group.
With CloudForamtion this was very easy. The stack would create an auto-scaling group with EC2 health check type, ensuring that EC2 checks pass. CloudFormation (with some configuration bits) waits (with a timeout) for a signal from the EC2 instance, indicating that everything is up and running. Sending a signal via EC2s (
cfn) is possible to send via userdata, where I could continuously ping health status from the target group using AWS CLI.
With Terraform there is no signaling mechanism as the signaling mechanism is exclusive to CloudForamtion. I have seen a solution that uses a mix of both CloudFormation and Terraform, where the auto-scaling group is managed via CloudFormation that is set up via Terraform
aws_cloudformation_stack resource. I have seen Spinnaker being used in this case as well, which I particularly don't like because it involves creating an auto-scaling group via Terraform and then commenting it out in Terraform. But, I am looking for a pure Terraform native solution.
The closest I have come to a Terraform native solution is to use ELB health check instead of EC2 health check while creating auto-scaling group via Terraform. My questions are:
- Is it recommended to use ELB health checks instead of EC2 health checks? Advantages/disadvantages? If anyone could share their experience in this regard it would be very helpful.
- Is it possible to use both EC2 and ELB or target group health checks in native Terraform?