TeKanAid

Dark

Table of Contents
HashiCorp Vault 101 - Certified Vault Associate
Get started with HashiCorp Vault and prepare for your Vault Associate Exam
Terraform 101 - Certified Terraform Associate
Learn all you need to know to ace the Terraform Associate Exam and go beyond the certification

HashiCorp Packer for VMware Ubuntu Templates and Terraform for building VMs


Stop using clickops and start automating with Infrastructure as Code concepts. In this video blog post you will learn how to use Packer to create Ubuntu 18.04 template images in vSphere then use Terraform to deploy these VMs.

IaCHashiCorpTerraformPackerVMwareLinuxUbuntu
Created: October 9, 2020 | Updated: January 27, 2023

Video

Below is a video explanation and demo.

HashiCorp Packer for VMware Ubuntu 18.04 Templates and Terraform for building VMs

Video Chapters

You can skip to the relevant chapters below:

  • 00:00 - Introduction
  • 01:32 - Packer Ubuntu Explanation
  • 08:28 - vCenter View of Template Created
  • 09:31 - Build the VM using Terraform
  • 16:31 - vCenter View of VMs Created
  • 17:02 - Conclusion

Overview

This video blog post is similar to the one we created for Windows 2019 server images. However, it builds Ubuntu 18.04 images instead.

The two main steps to achieve this are listed below:

  1. First create a Ubuntu 18.04 template and save it in a templates folder in vCenter using Packer.
  2. Then create a VM from this template using Terraform.

Code

Get FREE access to the source code by subscribing to my newsletter
You only need to subscribe once. Already subscribed? Enter your email to get instant access to the code.

Pre-requisites

The following is required to follow along:

  • Packer (tested on Packer v1.6.6)
  • Terraform
  • Access to a vSphere instance (tested on vSphere v6.7)

Setup

Below is our setup diagram.

Setup Diagram

Troubleshooting Tips

  • If packer gets stuck on Waiting for IP you may want to check your DHCP server. I'm using a home router and it had too many leases from running packer many times. I had to flush inactive DHCP clients or reboot the router which is faster.
  • Open the vSphere web console and take a look at the output as the VM is getting created. This can give you some hints as to what is going on.

Conclusion

In this video blog post, we demonstrated two main things:

  1. How to create a Ubuntu 18.04 image in VMware using HashiCorp Packer. As you saw, our configuration is all defined in code. There is no need to click around inside the vSphere client to generate this image. We've automated the task of building gold images in VMware. This makes the process repeatable and self-documented, just a couple of benefits of IaC.
  2. We used Terraform to provision the Ubuntu 18.04 VM by cloning this Packer generated image.

We also created a post on doing the same for a Ubuntu 20.04 image. Then another post to use this image to Build a Kubernetes k3s Cluster in vSphere with Terraform and Packer.

References


Other Posts
Terraform for Beginners - A Beginner's Guide to Automating Cloud Infrastructure
Terraform vs Ansible - Demo the Differences - Part 2
Terraform vs Ansible - Learn the Differences - Part 1
HashiCorp Vault Backup and Restore Raft Snapshots from Kubernetes to AWS S3
AWS Lambda - Terraform Configuration Example with API Gateway
Securing the Future - DevSecOps Trends for 2023
36 Top DevOps Questions to Get You Started in 2023
Terraform to Create a Ubuntu 22.04 VM in VMware vSphere ESXi
HashiCorp Packer to Build a Ubuntu 22.04 Image Template in VMware vSphere
Migrate Secrets from AWS Secrets Manager to HashiCorp Vault with Python, Docker, and GitLab
Migrate Secrets from AWS Secrets Manager to HashiCorp Vault with Terraform
env0 - A Terraform Cloud Alternative
Terraform Import Example - AWS EC2 Instance
DevOps Engineer NOT on Linux? You're MISSING OUT!
HashiCorp Vault API Tutorial and Pro Tips
HashiCorp Vault Tutorial for Beginners
Create a Pihole Docker Ad Blocker with Ansible and Terraform
Terraform vSphere Windows Example to Join an AD Domain
Build a Kubernetes k3s Cluster in vSphere with Terraform and Packer
HashiCorp Packer to Build a Ubuntu 20.04 Image Template in VMware
Consul-Template to Automate Certificate Management for HashiCorp Vault PKI
HashiCorp Vault PKI Secrets Engine Demo for Certificate Management
Jenkins, Vault, Terraform, Ansible, and Consul Delivering an End-to-End CI/CD Pipeline
Secret Zero Problem Solved for HashiCorp Vault
Hashicorp Packer, Terraform, and Ansible to Set Up Jenkins
Hashicorp Vault Azure Secrets Engine - Secure Your Azure Resources
HashiCorp Waypoint - Will it Replace Your CI/CD?
HashiCorp Boundary - Make Sure Your Human To Machine Access Is Secure
HashiCorp Packer for VMware Ubuntu Templates and Terraform for building VMs
HashiCorp Packer VMware Windows Templates and Terraform for VMs
Webblog App Part 4 – HashiStack – Nomad Consul Vault Terraform
Webblog App Part 3 - Consul Connect Service Mesh
Webblog App Part 2 - Secrets Development Phases with Vault
Webblog App Part 1 - Infrastructure as Code with Terraform
Microservices Applications'​ Life Cycle
HashiCorp Vault 201 - Vault for Apps in Kubernetes
Learn how to use HashiCorp Vault for your applications in Kubernetes