DEV Community

ECS Fargate Service Auto Scaling with Terraform

Kieran Jennings on October 10, 2020

Note: This is my first blog post! Any feedback is totally welcome. You can access the completed code for this blog here. Introduction ...
Collapse
 
sathyabhat profile image
Sathyajith Bhat • Edited

Hey, pretty good write up. I have only couple of suggestions:

  • better tags. I'm glad to see at-least one tag, adding some extra tags (for ex, I add a "used_for" tag for every stack I built) helps me analyze and possible revise stacks for cost savings/analysis
  • Terraform variable blocks can accept description, default and type constraints modifiers. Description is useful for documentation (alternatively, it prompts the description when used as an input variable), defaults can help set some sane default values and type constraints ensure you enter the right type.
  • For new folks, I really don't recommend touching the NACLs - the defaults are good and security groups provide a good enough firewall and updating NACLs without understanding the "stateless" mechanism can lead to lot of head-scratching on why something is broken.
  • Given DockerHub's new rate limiting policies, I think storing images in ECR is definitely worth it Great post overall!
Collapse
 
kieranjen profile image
Kieran Jennings

Thanks for the feedback!

I tend to add a "Billing" tag to the resources so then they can be grouped in Cost Explorer. I will add that in!

I always seem to forget about variable descriptions and types!

I did mention the cost aspect of NAT gateways but I will make sure it's clearer.

I was so hesitant about putting in NACLs! I think everyone has been burned by NACLs at some point 😁 I will take them out to avoid confusion.

Again thanks for the feedback! I'm new to blogging and trying to make the call on what can be too confusing for people when reading. It's great to have someone else's opinion.

Collapse
 
dosaki profile image
Tiago Correia

Maybe put a note at the top of the NACLs section just to warn people "You can do this if you want, but the defaults are ok if you're a beginner"?

Thread Thread
 
sathyabhat profile image
Sathyajith Bhat

Yep, totally

Collapse
 
sathyabhat profile image
Sathyajith Bhat

Kieran,

I missed reading up about the NAT gateways and its quite clear, hence I edited out my post. Your first post is quite impressive and look forward to reading more. Cheers

Thread Thread
 
kieranjen profile image
Kieran Jennings

Thank you!

Collapse
 
spodalov profile image
Sergey Podalov

Hi, thank you for great post!
I've found a lot of posts related to Terraform, ECS and Fargate, but this one is the best!

Collapse
 
kieranjen profile image
Kieran Jennings

Thank you. That means a lot!

Collapse
 
primadi profile image
Primadi Setiawan

There always low alarm for CPU and Memory in the cloudwatch. Is there anyway to prevent low alarm when instance number is 1 ? Thanks.

Collapse
 
kieranjen profile image
Kieran Jennings

Hi! Sorry for the late reply. There isn't a way to prevent that but there is a tick box option in the cloud watch alarms panel to hide auto scaling alarms. I hope this helps.

Collapse
 
maestre3d profile image
A. Ruiz

So after a couple of days searching how to exactly do this process, I finally found the gold mine. Thanks a lot, Kieran!! You nailed it.

Collapse
 
kieranjen profile image
Kieran Jennings

Thank you for reading! I'm glad it was useful

Collapse
 
praveenha profile image
Praveen HA

Its too nice.. I have seen many blogs this is too neat .. we are trying to migrate from EC2 based ECS to Fargate....it took me 2 hours to migrate my entire code to to go with Fargate

Collapse
 
kieranjen profile image
Kieran Jennings

I'm a confused as to what you mean by too neat. This is the process I used at the time to create an auto-scaling ECS Fargate service, nothing more, nothing less. If this is too difficult to do in your codebase I would consider refactoring it down to make it easier to manage, then work from there

Collapse
 
vilelalabs profile image
Henrique Vilela

Seems to have an error on first line starting Load balance explanation:

There are a few more variables we need to add in ecs/variables.tf.

shouldn't be elb/variables.tf?