Chapter 2. Deploying and Configuring Virtual Machines

This chapter introduces our first working example of Terraform for your vSphere environment. You learn how to create declarative configurations to deploy and manage the life cycle of virtual machines (VMs), and VM snapshots.

Using Terraform alone does not create DevOps processes. The tool simply allows you to modify your existing processes to adopt more DevOps methods and processes.

Terraform, as it is used here, is more for life cycle management and continuous and repeated uses.

Configuring Your Terraform Environment

Your environment requires a minimal set of configurations to attach to and manage your VMware infrastructure. This includes configuring your VMware provider, environment variables, and data sources that will be used during Terraform-controlled resource management.

Following are example snippets of the code required. The full code samples for these scenarios are available here.

Setting Up Your Variables

Variable definition assigns a type to variables you will use, which can be simple variables (string, integer, bool) or complex variables (list, set, map, object, tuple) for more advanced scenarios. Descriptions are optional but always helpful for others who will be reading and collaborating with your code. You must define variables prior to having values assigned in your Terraform resource configuration:

variable "vsphere_user" { type = "string" description = "vCenter/vSphere user" } variable "vsphere_password" ...

Get DevOps Automation with Terraform and VMware now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.