Packer, Vagrant, and Terraform – DevOps Automation Tools – Terraform, Ansible, Packer, and More

Share this post on:

Packer, Vagrant, and Terraform

Packer is a tool used for automating the creation of machine images, Vagrant is used for managing the lifecycle of virtual machines, and Terraform is an infrastructure-as-code tool. Packer, Vagrant, and Terraform are all products of HashiCorp, but they work well on Oracle Linux.

We’re going to install Packer, Vagrant, and Terraform directly from HashiCorp:
$ sudo dnf install -y dnf-plugins-core
$ sudo dnf config-manager –add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo
$ sudo dnf install -y packer vagrant terraform

Once that’s finished, let’s go ahead and install Oracle VM VirtualBox, as we’ll be using VirtualBox with Packer and Vagrant:
$ sudo dnf install -y oraclelinux-developer-release-el8
$ sudo dnf install -y VirtualBox-7.0

Finally, along with Terraform, we’ll also want to create an Oracle Cloud Infrastructure (OCI) account. If you prefer, you may opt to use a different cloud, but use OCI if you want to follow this tutorial directly.

Important note

Be sure to remember your Cloud Account Name as this is an important detail required in order to access your OCI account.

Downloading the source code

The source code for the recipes in this chapter can be found at https://github.com/PacktPublishing/Oracle-Linux-Cookbook/tree/main/ch8.

Do it once manually – rinse and repeat with Terraform

Terraform is an infrastructure-as-code (IaC) tool that lets you build, change, and version infrastructure safely and efficiently. This recipe will provide a general overview of a good technique for automating the ugly with Terraform. What do I mean by ugly? Well, it’s anything that’s being done manually. We want to cut out the manual steps and automate as much as possible. In the case of Terraform specifically, this means we’re going to automate the deployment of cloud infrastructure. Thanks to Terraform, we no longer need to click around through a hundred different menu settings. Instead, we’re going to define our infrastructure as code. This results in faster and more consistent deployments. Additionally, it’s also much easier to make changes to your infrastructure since it can all be edited via code.

Getting started

You will need the following for this recipe:

  • Oracle Linux
  • Terraform

Refer to the Technical requirements section at the beginning of this chapter if you need help installing Terraform.

How to do it…

Any time you set out to automate something, it’s always a good idea to have a solid grasp on what needs to be done under the hood. Can you guess what that means? Yep, you’ve got to perform all the manual steps at least once before trying to automate it.

First, do it once manually…

The goal for this recipe is to use Terraform to deploy a simple VM in the cloud. It’s an easy enough task, but before we jump into how this can be done using code, it’s generally best to do it manually first. So, with that being said, let’s go ahead and deploy a virtual machine using the OCI web GUI:

  1. Log in to the Oracle Cloud Infrastructure Console (https://cloud.oracle.com/).

Figure 8.1 – OCI Console Login Page

2. Click on the hamburger menu icon at the top left:

Figure 8.2 – OCI Console main screen

Then click on Compute | Instances:

Figure 8.3 – OCI Cloud Compute menu

Verify you are in the desired Compartment, and finally, click on Create instance:

Figure 8.4 – OCI Cloud Compute Instances

Share this post on:

Author: Stacy Atkins Prince

View all posts by Stacy Atkins Prince >

Leave a Reply

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