I know that DigitalOcean still does not have auto scaling for Droplets, but I’m using Terraform to manage my infrastructure and want to set up an auto-scaling group for Droplets based on CPU usage.
Ideally, when CPU usage exceeds a certain threshold, new Droplets should be created automatically, and when the usage decreases, they should be removed. What’s the best way to approach this with Terraform and DigitalOcean, and are there any limitations or additional services I need to integrate to achieve this?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Hey!
Great question! Indeed, as you mentioned, while DigitalOcean doesn’t have native auto-scaling for Droplets, you can still achieve something similar by combining Terraform with monitoring tools like DigitalOcean’s Monitoring and external automation for scaling.
Here’s an example of how you can use a variable in Terraform to control the number of Droplets:
In this case, the
droplet_count
variable will control how many Droplets are created. You can modify this value dynamically based on the CPU usage and then trigger a Terraform apply.This will provide a way to “auto-scale” your Droplets based on demand, even though it’s not built into DigitalOcean’s platform natively.
On another note, if you’re just getting started with Terraform and DigitalOcean, this ebook might be helpful: Introduction to Terraform ebook.
Let me know if you have any other questions, and good luck with your project!
- Bobby