Teaching Terraform: How I used my volunteer day

Amine Maalej | Last updated on August 30, 2024 | 4 minute read

As DevOps engineers at Rewind, we’re encouraged to use our paid volunteer day to live our value of Giving Back. I spent some time really thinking about how best to use my volunteer day, so when I got the chance to visit my hometown in Tunisia, it seemed like the perfect opportunity to volunteer at my alma mater, the International Institute of Technology in Sfax (IIT).

I reached out IIT and arranged to host an introductory session for their computer engineering students about a tool we use daily at Rewind, Terraform. I use it almost every day, as Terraform is how we code our infrastructure and deploy it to the cloud. Whenever we need to update or create new resources in AWS, we use Terraform to do it. 

The first project I ever completed as a DevOps at Rewind used Terraform: I was tasked with backing up a resource called Route 53, which logs all activity between Rewind domains. If it’s possible to have a favorite DevOps tool, Terraform might just be mine– it was the first tool I learned at Rewind, so it holds a special place. 

I took the initiative and coordinated with my manager, and I arranged everything with the university to present a course about Terraform – Infrastructure as Code.

Preparing the Terraform lesson

For me, preparation is crucial as it gives me a sense of confidence and, in my opinion, is the key to success. So, I spent a few days developing resources and planning the session. 

I prepared lesson materials, found an introductory video about Terraform to share, and prepared some quizzes to ensure the students were understanding the tool (and its potential) correctly. I planned out some small projects for the students to complete to get their feet wet and gain experience actually using Terraform, not just hearing about it. 

Teaching Terraform and Infrastructure as Code

On the day of the lesson, I was feeling excited and nervous in equal measure. We started the session with a short animated video to give an overview of Terraform. Then, I went into some detail about the benefits of learning the tool, and how Rewind uses Terraform in real-life use cases. 

After this, I moved forward with the course, explaining the foundations and the basics. The course was divided into modules, and at the end of each part, I made a short quiz to make sure that all the students understood the content of the lesson correctly. 

Here’s a basic outline of the lesson:

  • Chapter 1: I started by introducing the Terraform workflow and explaining the key concepts in each phase; init, plan, and apply/destroy.
  • Chapter 2: I gave some real-world examples of how Terraform is used, especially at Rewind.
  • Chapter 3: We covered how to install Terraform and the necessary providers.
  • Chapter 4: I introduced the concept of Terraform states, and explained why state matters when it comes to resource tracking. 
  • Chapter 5: Next, we discussed Terraform variables and outputs. Students learned what different types of variables and outputs are allowed by HCL, the Terraform coding language.
  • Chapter 6: I introduced CLI (command line interface) commands and how to use them to interact with Terraform projects.
  • Chapter 7: We covered the pros and cons of local and remote storage, and how to use both using Terraform.
  • Chapter 8: The students learned about Terraform modules and how to interact with the tool’s inputs and outputs.
  • Chapter 9: Finally, I demonstrated how to use a few of Terraform’s built-in functions. 

Getting our hands dirty

Once we finished the theoretical part of the course, it was time to get our hands dirty with a demonstration of Terraform in action. This hands-on example helped get all the students familiar with the technical aspects of working with the tool. 

Demo: Creating AWS resources in Terraform

Of course, the beauty of Terraform is quickly and easily creating new resources. So, how do we actually do that?

We begin like this:

provider "aws" {
  region     = "us-east-1"
  access_key = "<YOUR_ACCESS_KEY>"
  secret_key = "<YOUR_SECRET_KEY>"
}

terraform {
  backend "s3" {
    region = "us-east-1"
    key    = "terraform.tfstate"
    bucket = "mybucketiit2022"
  }
}

As you can see in the code snippet above, we use HCL to define our main, our credentials, our provider, and our cloud where the resource will be created.

Next, we define the resource that we want Terraform to create. This snippet creates a virtual machine known as EC2, where we can store a variety of resources and ensure everything remains organized and professional. 

resource "aws_instance" "first-vm" {
  ami           = "ami-0b0dcb5067f052a63"
  subnet_id     = "subnet-057b8cba63b84405b"
  instance_type = "t3.micro"
  tags = {
    Name = "my first VM in terraform"
  }
}

Next, we create an S3 bucket in the virtual machine defined above. S3 buckets are great to use because they can be properly secured as a private bucket easily. This means we can control permissions such as who can access, view, or delete it. In this example, the bucket is also used as our backend, where we are going to store our state file known as “tfstate”.

resource "aws_s3_bucket" "b" {
  bucket = "my-tf-test-bucket-iit-2022"

  tags = {
    Name        = "My bucket"
  }
}

resource "aws_s3_bucket_acl" "example" {
  bucket = aws_s3_bucket.b.id
  acl    = "private"
}

Also, we must tell Terraform what version we are using. We do so like this:

terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 3.0"
    }
  }
}

I hope the session was beneficial to the students, but I can confidently say it was extremely beneficial for me. Sharing my knowledge helped to validate my own expertise as a professional developer and increased my confidence in my skills. Teaching is not just good for the students; it benefits the teacher as well. Hopefully, my students-for-a-day will be inspired to keep learning more about different tools after being exposed to a new trend in the DevOps world.


Profile picture of Amine Maalej
Amine Maalej
Amine Maalej is a Cloud Engineer at Rewind. He holds degrees from the International Institute of Technology in Sfax and the University of Sherbrooke. Amine is an AWS Certified Cloud Practitioner and a Hashicorp Certified Terraform Associate. As a former pro, Amine can typically be found keeping his basketball skills sharp and refueling with harissa poutine.