DEV Community

Cover image for Working With Terraform As A Noob - A Brief Overview
Airah Yusuff for AWS Community Builders

Posted on • Originally published at khairahscorner.hashnode.dev

Working With Terraform As A Noob - A Brief Overview

If you are relatively new to cloud infrastructure, you've probably heard of Terraform and how it's a great Infrastructure-as-Code tool to learn. I recently started a Terraform course on Cloud Academy (courtesy AWS CB program!), and I picked up some foundational concepts.

There's no better way to learn than by doing though, so in upcoming posts, I'll share my notes from working on the labs in the course (and other labs on Cloud Academy).

However, for this post, let's get to know Terraform a bit!

What is Terraform?

Terraform is an infrastructure-as-code (IaC) tool by HashiCorp that lets you build, change, and version infrastructure safely and efficiently.

I've worked with AWS CloudFormation and Terraform basically works the same - automate the deployment and configuration (to some extent) of cloud infrastructure.

It can also be used for on-premises resources.

Like other IaC tools, it's a declarative language (aka describe what you want rather than detailing the steps on how to get it).

It is available for use in three different editions: Terraform Open Source, Terraform Cloud and Terraform Enterprise.
You can use the first two but the first one is my current choice since you can download and set it up for use on your local machine.

There are lots of tutorials on their website detailing how to use Terraform for different cloud providers, and I think I'm going to actually try them out on random days. It can even be used for Docker!

P.S I know it can seem like there are so many resources and it's overwhelming to know which to try or where to get started.

However, I also know that no one is ever truly alone in their learning journey, so we just need to keep learning.

So breathe, and keep learning whatever you can.

A Question About Terraform

I'll be honest, I haven't quite gotten to the part where I understand the "write once, run everywhere" catchphrase.

One question I had at the back of my mind was "Is Terraform really cloud agnostic?". I had to Google it of course, and it was a relief that I was not the only one who had thought about it.

From what I've seen so far, you still have to tailor your configuration files to each cloud provider. Maybe it's because the syntax and overall approach is still somewhat similar?

I guess I'll learn more and understand it better as I progress further.

General Overview of a Terraform Project

If you come from a frontend development background like me, one thing to note is there are no tools to bootstrap and magically set up your environment for you (as far as I know).

Yes, I'm looking at you CRA, vue-cli, etc 😂

You'd need to set up the files and working environment yourself, based on your requirements or what you need to achieve.

To set up a basic Terraform project, there are some files you need to create in your project folder:

  • main.tf: This file contains your core Terraform code; the one that specifies your choice of provider, the resources to be deployed, etc.
  • variables.tf: This contains and describes variables you might have declared in the main.tf file. The values can be initialised as defaults or provided with a *.tfvars file.
  • outputs.tf: If you have values you'd like to export (for viewing purposes or to be used in other files), this is where you declare them.

You can actually also write everything in one file, but they are separated for better structure and readability.

There are other files like state files (Terraform is stateful, so it keeps track of all configuration and infrastructure changes; this is useful when you need to retrace your steps or roll back deployments).

It can also have directories e.g modules but the files above are pretty much the basics needed to get started with using Terraform.

Other Notes

- Terraform Workspaces: In my opinion, this works similar to Visual Studio Code workspaces. You can set up different environments, switch between projects and configurations without affecting one another. It's ideal for managing development and production workloads.

- Terraform Registry: This is your go-to section to tailor Terraform for whatever you are working on. It includes different providers, their official modules and documentation on how to integrate with their platforms.

Conclusion

Terraform is pretty much like any other IaC tool, only more robust and of course, "platform-agnostic". It seemed similar to CloudFormation and that's most likely the case with the IaC tools from other cloud providers.

I was able to understand the files provided by the instructor and navigate my way around trying things out.

The key point to note would be to study the documentation and make it your best friend.

There are several documentation to check out:

Then, you move on to the documentation for the specific cloud provider you work with (in my case, AWS).

Once you know the infrastructure you need to deploy and how to configure them, you'd just have to navigate through the documentation till you get the syntax you need.


Let's try out the labs next!

Top comments (0)