I’m setting up a multi-tier architecture on DigitalOcean and want to provision several Droplets with Terraform.
Each Droplet will have a unique configuration (different sizes, regions, and tags). Additionally, I need to assign a floating IP to each Droplet for easier management and failover.
How can I structure my main.tf
file to handle this efficiently, and what’s the best way to manage floating IPs in Terraform?
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! With the recent updates, DigitalOcean has renamed Floating IPs to Reserved IPs. So, you’ll want to use the
digitalocean_reserved_ip
resource instead.Here’s a quick example of how you can create multiple Droplets with different configurations and assign Reserved IPs using Terraform.
You can define each Droplet with different sizes, regions, and tags by using a
for_each
or creating separate resources for each Droplet in yourmain.tf
.To assign a Reserved IP to each Droplet, you need to replace the deprecated
floating_ip
resource withreserved_ip
. Here’s an updated example:map
or a variable in yourvariables.tf
like this:This will create multiple Droplets with different configurations and assign each one a Reserved IP.
If you need to expand this further, you can adjust the
for_each
loop or add more configurations as needed.On another note, if you’re just getting started with Terraform and DigitalOcean, this ebook here might be helpful: Introduction to Terraform ebook.
- Bobby