// Tutorial Series //
How To Manage Infrastructure with Terraform
By
How To Manage Infrastructure with Terraform

Introduction

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.

Summary View
detailed View
// Conceptual-article //

Infrastructure as Code Explained

Published on October 13, 2020 · Updated on October 15, 2020

In this article, we define Infrastructure as Code (IaC) and explain the benefits of IaC in development and deployment workflows. We also start to learn about Terraform’s role in the IaC workflow and understand “what is ‘state’?” in IaC.

// Tutorial //

How To Use Terraform with DigitalOcean

Published on August 7, 2014 · Updated on March 11, 2022

Terraform is a tool for building and managing infrastructure in an organized way. In this tutorial, you’ll install and use Terraform to create an infrastructure on DigitalOcean that consists of two Nginx servers that are load balanced by a DigitalOcean Load Balancer.

// Tutorial //

How To Structure a Terraform Project

Published on September 1, 2020 · Updated on July 27, 2021

Structuring Terraform projects appropriately according to their use cases and perceived complexity is essential to ensure their maintainability and extensibility in day-to-day operations. In this tutorial, you’ll learn about structuring Terraform projects according to their general purpose and complexity. Then, you’ll create a project with a simple structure using the more common features of Terraform: variables, locals, data sources, and provisioners.

// Tutorial //

How To Improve Flexibility Using Terraform Variables, Dependencies, and Conditionals

Published on September 10, 2020 · Updated on August 30, 2021

Hashicorp Configuration Language (HCL), which Terraform uses, like other programming languages provides a few different types of loops. In this article, we’ll review the data structures HCL provides, its looping features for resources (the count key, for_each, and for), writing conditionals to handle known and unknown values, as well as explicitly specifying dependency relationships between resources.

// Tutorial //

How To Manage Infrastructure Data with Terraform Outputs

Published on September 21, 2020 · Updated on September 20, 2021

Terraform outputs are used to extract information about the infrastructure resources from the project state. In this tutorial, you’ll learn about Terraform outputs their syntax and parameters by creating a simple infrastructure that deploys Droplets. You’ll also learn about parsing the outputs programmatically, by converting them to JSON.

// Tutorial //

How To Build a Custom Terraform Module

Published on October 29, 2020 · Updated on April 6, 2022

Terraform modules encapsulate distinct logical components of your infrastructure by grouping their resources together. In this tutorial, you’ll create a Terraform module that will set up multiple Droplets behind a Load Balancer for redundancy. You’ll also use the for_each and count looping features of the Hashicorp Configuration Language (HCL) to deploy multiple customized instances of the module at the same time.

// Tutorial //

How To Create Reusable Infrastructure with Terraform Modules and Templates

Published on November 18, 2020 · Updated on October 26, 2021

One of the main benefits of Infrastructure as Code is reusing parts of the defined infrastructure. In this tutorial, we’ll consider some of the ways of defining and reusing code in Terraform projects. You’ll reference modules from the Terraform Registry, separate development and production environments using modules, learn about templates and how they are used, and how to specify resource dependencies explicitly using the depends_on meta argument.

// Tutorial //

How To Protect Sensitive Data in Terraform

Published on November 30, 2020 · Updated on November 2, 2021

Terraform provides automation to provision your infrastructure in the cloud. To do this, Terraform authenticates with cloud providers to deploy the resources and perform the planned actions. However, the information Terraform needs for authentication is very valuable. In this tutorial, you’ll hide sensitive data in outputs during execution and store your state in a secure cloud object storage, which encrypts data at rest. You’ll also use tfmask to censor values in the Terraform execution.

// Tutorial //

How To Use Ansible with Terraform for Configuration Management

Published on January 7, 2021 · Updated on November 15, 2021

Ansible and Terraform are not competing solutions, as they resolve different phases of infrastructure and software deployment. In this tutorial, you’ll deploy Droplets using Terraform, and then immediately after their creation, you’ll bootstrap the Droplets using Ansible.

// Tutorial //

How To Deploy Multiple Environments in Your Terraform Project Without Duplicating Code

Published on January 11, 2021 · Updated on November 18, 2021

Some advanced features Terraform offers become useful when your project grows in size and complexity. It’s possible to alleviate the cost of maintaining complex infrastructure definitions for multiple environments by structuring your code to minimize repetitions and by introducing tool-assisted workflows for easier testing and deployment. In this tutorial, you’ll first deploy multiple infrastructure instances using different workspaces.

// Tutorial //

How To Troubleshoot Terraform

Published on January 21, 2021 · Updated on November 23, 2021

Similarly to developing with other programming languages and frameworks, setting log levels in Terraform to gain insight into its internal workflows with the necessary verbosity is a feature that can help you when troubleshooting. In this tutorial, you’ll verify that variables always have sensible values and you’ll specify exactly which versions of providers and modules you need to prevent conflicts.

// Tutorial //

How To Use Terraform With Your Team

Published on February 2, 2021 · Updated on March 29, 2022

In this tutorial, you’ll create an organization in Terraform Cloud to which you’ll connect your project. You’ll then use your orgnanization to set up workspaces and resources. You will store your state in the managed cloud so it is always available. You’ll also set up the pg backend with an accompanying managed Postgres database.

Check out all our Tutorial Series

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in our Questions & Answers section, find tutorials and tools that will help you grow as a developer and scale your project or business, and subscribe to topics of interest.

Sign up now

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up