Best Terraform Tutorial Guides: An Overview

Raphael Socher
FAUN — Developer Community 🐾
6 min readOct 19, 2020

--

An lightbulb with math, science, and technology images

If you want to effectively deploy your infrastructure on the cloud using Terraform, you’ll need an effective Terraform tutorial. According to DevOps expert Pavan Belagatti and Faun, Terraform is revolutionizing the way organizations think of Infrastructure as Code, as well as DevOps. But, learning a new language can seem like an uphill battle if you’re late to the game. And, as DevOps organizations continue to decide to adopt it, diving into a strong Terraform tutorial can help you learn quickly and efficiently. Note: This article is intended for beginners.

Many DevOps trends have included Infrastructure as Code as areas to watch in 2020, and we’re not seeing any slowing of growth in these areas. In fact, training and learning are ranked as high-priority for DevOps organizations. With over 55% of organizations looking to hire internally, acquiring the skillset for changing organizations is a necessity. Of course, there’s an abundance of information online about Terraform, but where do you begin? In this article, we’re looking at the must-know information to get started, as well as other resources you can consider as you continue to learn. In addition, we encourage you to join our InfraCode Slack to gain more DevOps resources and 1-on-1 help.

In this article, we’ll go over resources for you to get started, including:

  • Terraform Tutorial Basics: What is it?
  • What are the commands to deploy infrastructure?
  • Configuration Overview
  • Other Resources

Let’s dive in.

Terraform Tutorial Basics: What is it?

Any useful Terraform tutorial starts with the question: “What is it?” So, let’s begin our resource list with the answer to this question.

Terraform is an open-source tool that is specifically dedicated to creating, modifying, and even deleting infrastructure on the cloud, focusing on “Infrastructure as Code.” Users who attempt to build their infrastructure use a declarative language known as HashiCorp Configuration Language (HCL).

You may also wonder “what is Infrastructure as Code?” Infrastructure as Code (IaC) is the management of infrastructure in a descriptive model, where the same source code generates the same binary. An Infrastructure as Code model generates the same environment every time it is applied. For a more in-depth Terraform tutorial (going over the basics), check out HashiCorp’s introduction.

If you’re a newcomer, it’s also important to know that like all other products, there are version-by- version releases. The latest version available is 0.14. However, any version from 0.12 is considered good enough for you to download and have a hands-on Terraform tutorial.

What are the commands to deploy infrastructure?

Everything is controlled by a Command Line Interface (CLI) with very simple-to-remember commands. For a complete list of commands, bookmark this page.

A Terraform tutorial will refer to the following as the most-used commands:

  • Init
  • Plan
  • Apply
  • Destroy

Here’s a brief summary of the commands:

An image describing the top 4 Terraform commands to use when deploying infrastructure

Init: When you have all your terraform configuration files ready in a directory, the “init” command can be used to initialize your working directories. Note that there is no restriction on how many times you may initialize the working directory, so you can use the command as many times as you’d like. However, remember to initialize your working directory every time you make a change to the configuration file.
Usage: terraform init [options] [DIR]

Plan: The “plan” command is used to set up an execution plan. It conveniently helps you to determine the actions that would be required to move to the state defined in your configuration file. What makes this command useful? It does not make changes to the real-world state but helps you see if the changes are up to your expectations and as per the configuration file. In other words, the “plan” command is your guide in setting up a strong structure to execute on.
Usage: terraform plan [options] [DIR]

Apply: The “apply” command is used to apply the changes to the current state to reach the desired state as per your configuration file. You may either use the command to scan the current configuration directory to apply the changes or you may specify the path to another directory where you have the configuration files. Note that confirmation is prompted when you use the command, to apply the changes.
Usage: terraform apply [options] [DIR-or-PLAN]

Destroy: Any infrastructure that has been set up can be destroyed or terminated by using the command “destroy.” Note that this command prompts your confirmation before terminating the infrastructure.
Usage: terraform destroy [options] [DIR]

Configuration Overview

Once you’ve familiarized yourself with the commands, it’s always good to know how to write configuration files. Any practical Terraform tutorial will guide you through this process.

As described earlier, there is a declarative configuration language, which allows you to write a description of your infrastructure requirements. All configuration files are given the .tf extension. You may also choose to write your configuration files in JSON format which will have the extension .tf.json. It is also important to know that all configuration files, irrespective of the format, should be UTF-8 encoded.

Configuration files are always a group of modules. But, what exactly are modules? Well, let’s try to explain this as simply as possible. When you define and set up an infrastructure, the most important objective is to declare resources that need to be made available. Every resource block describes objects concerning the infrastructure, such as virtual networks, DNS records, etc. Now, when such resources are grouped and relationships are defined between these resources, they form a module.

A configuration file always contains at least a root module, where the execution always begins. This root module, may or may not call other child modules.

Now that we know about resources and modules, let’s consider the syntax. There are 3 very basic elements: Blocks, Arguments, and Expressions.

Blocks: These act like containers that hold onto the configuration of objects or resources. Each block can have its own type and also arguments. A block may even contain one or more blocks.

Arguments: These always occur within blocks. They are just basic statements where a particular value is being assigned to a particular identifier.

Expressions: Expressions are just values that are either assigned directly or by referring and combining different values. They may appear either as value for arguments or may appear as a subset of other expressions.

Other Resources

While reading HashiCorp’s documentation section may be helpful, there are other ways to learn as well. For example, check out this video where Armon Dadgar, co-founder of HashiCorp, introduces and provides a basic Terraform tutorial. For a quick, 15-minute tutorial, TechWorld with Nana has a great overview as well. Regardless of your preferred learning method, we encourage you to get out there and practice, hands-on.

If you still have questions after reading and watching resources, join our InfraCode Slack community to gain expert insight and 1-on-1 help for all of your Terraform questions. We’re a community of Terraform experts and enthusiasts and have lively debates and discussions. We welcome both beginners and experts alike. Happy learning!

👋 Join FAUN today and receive similar stories each week in your inbox! Get your weekly dose of the must-read tech stories, news, and tutorials.

Follow us on Twitter 🐦 and Facebook 👥 and Instagram 📷 and join our Facebook and Linkedin Groups 💬

If this post was helpful, please click the clap 👏 button below a few times to show your support for the author! ⬇

--

--

Founder at InfraCode — customizable, reliable Infrastructure as Code tools. Simplifying the lives of DevOps professionals. www.infrastructurecode.io