VOOZH about

URL: https://www.digitalocean.com/community/tutorials/how-to-use-terraform-with-digitalocean?comment=18568

⇱ How To Use Terraform with DigitalOcean | DigitalOcean


👁 How To Use Terraform with DigitalOcean

Introduction

Terraform is a tool for building and managing infrastructure in an organized way. You can use it to manage DigitalOcean Droplets, Load Balancers, and even DNS entries, in addition to a large variety of services offered by other providers. Terraform uses a command-line interface and can run from your desktop or a remote server.

Terraform works by reading configuration files that describe the components that make up your application environment or datacenter. Based on the configuration, it generates an execution plan that describes what it will do to reach the desired state. You then use Terraform to execute this plan to build the infrastructure. When changes to the configuration occur, Terraform can generate and execute incremental plans to update the existing infrastructure to the newly described state.

In this tutorial, you’ll install Terraform and use it to create an infrastructure on DigitalOcean that consists of two Nginx servers that are load balanced by a DigitalOcean Load Balancer. Then, you’ll use Terraform to add a DNS entry on DigitalOcean that points to your Load Balancer. This will help you get started with using Terraform, and give you an idea of how you can use it to manage and deploy a DigitalOcean-based infrastructure that meets your own needs.

Note: This tutorial has been tested with Terraform 1.1.3.

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Learn more about our products

Tutorial Series: How To Manage Infrastructure with Terraform

Terraform is a popular open source Infrastructure as Code (IAC) tool that automates provisioning of your infrastructure in the cloud and manages the full lifecycle of all deployed resources, which are defined in source code. Its resource-managing behavior is predictable and reproducible, so you can plan the actions in advance and reuse your code configurations for similar infrastructure.

In this series, you will build out examples of Terraform projects to gain an understanding of the IAC approach and how it’s applied in practice to facilitate creating and deploying reusable and scalable infrastructure architectures.

About the author(s)

Software Engineer @ DigitalOcean. Former Señor Technical Writer (I no longer update articles or respond to comments). Expertise in areas including Ubuntu, PostgreSQL, MySQL, and more.

Managed the Write for DOnations program, wrote and edited community articles, and makes things on the Internet. Expertise in DevOps areas including Linux, Ubuntu, Debian, and more.

Managed the Write for DOnations program, wrote and edited community articles, and makes things on the Internet. Expertise in DevOps areas including Linux, Ubuntu, Debian, and more.

Still looking for an answer?

Was this helpful?

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!

Perfect Start for 0.1 of Terraform!!!

I am confused why in the examples you pass the SSH fingerprint, private, and public key locations. Shouldn’t the Digital Ocean API key be sufficient if you have configured “global” SSH keys with DO?

That’s a good article. I’d applied configuration, then added a couple of strings to remote-exec. After that terraform plan shows me nothing has changed. My question is what would be an approach when I want to re-provision existing node. Will terraform recreate it or something else ?

To calculate the hex hash of a key, as on newer systems this might default to sha256 which is not accepted…

ssh-keygen -l -E md5 f ~/.ssh/id_rsa.pub | awk ‘{print $2}’

Minor correction: export PATH=$PATH:~/opt/terraform/bin should be export PATH=$PATH:/opt/terraform since we extracted terraform in /opt/terraform

Terraform is meant for infrastructure management… So I am thinking maybe running the remote-exec provisioners is probably not the most ideal way of managing the software on these systems.

I know Terraform comes with a Chef provisioner, so I don’t see why I couldn’t use local-exec to run Ansible against either a digital_ocean or a terraform dynamic inventory ansible script.

digitalocean_droplet.www-1: Error creating droplet: POST https://api.digitalocean.com/v2/droplets: 422 90:91:*********************************************:4a:ed are invalid key identifiers for Droplet creation.

I got the fingerprint by running the command above, and the key is on my DO account. What am I missing?

Is Terraform still a good CM/deployment tool? Would love any thoughts on the matter, including any alternate suggestions. Thanks!

👁 Creative Commons
This work is licensed under a Creative Commons Attribution-NonCommercial- ShareAlike 4.0 International License.
  • Deploy on DigitalOcean

    Click below to sign up for DigitalOcean's virtual machines, Databases, and AIML products.

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and AI-native businesses

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Start building today

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.

© 2026 DigitalOcean, LLC.Sitemap.
Dark mode is coming soon.