How To Manage Infrastructure with Terraform

164.3k views

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.

  • 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.
  • 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.
  • 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.
  • 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.
  • 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.
  • 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.