Datisch Personal Blog

Let's talk about tech

Terraform for Beginners

I want to start a new series about using Terraform, In this post we will learn how to start Terraform from the scratch.

What is Terraform?

Imagine, you have lots of virtual machines (VMs) in different providers, both on cloud and on premise. What happens if you loose one of this VMs, do you know what was the last configurations of it?

This is where Terraform comes to the scene! It helps us to provision our infrastructure, in a way that we can manage it in future.

Lets start

Install Terraform

By following a few steps from Hashicorp website, you can easily install Terraform on your OS. Here I’m installing it in an Ubuntu system.

The installation guide is here

After installation, check if it is properly installed:

daniel@danbook:~$ terraform --version
Terraform v1.15.9
on linux_amd64

Here, at first, I want to create a new VM in my local VirtualBox. (If you do not have VirtualBox, download and install it from Oracle official website)

Make sure, VirtualBox is installed:

daniel@danbook:~$ VBoxManage --version
7.2.4r170995

Create a new project folder:

mkdir ~/terraform-vm-create
cd ~/terraform-vm-create

Create a main.tf file and copy the following configurations in it:

terraform {
  required_providers {
    virtualbox = {
      source  = "terra-farm/virtualbox"
      version = "0.2.2"
    }
  }
}

provider "virtualbox" {}

resource "virtualbox_vm" "ubuntu" {
  name   = "terraform-ubuntu"
  folder = "Machine"

  cpus   = 2
  memory = "2048 mib"

  network_adapter {
    type = "nat"
  }

  disk {
    image  = "/path/to/ubuntu.iso"
    format = "VMDK"
  }
}

Leave a Reply

Your email address will not be published. Required fields are marked *

Navigation

About

Writing on the Wall is a newsletter for freelance writers seeking inspiration, advice, and support on their creative journey.