Skip to content
Luca Dell'Oca Principal Cloud Architect @Veeam
Virtual To The Core Virtual To The Core

Virtualization blog, the italian way.

  • Media
  • About me
Virtual To The Core
Virtual To The Core

Virtualization blog, the italian way.

Learning how to use terraform in vCloud Director

Luca Dell'Oca, April 2, 2019April 3, 2019

Lately, I took the decision to do not have anymore a physical lab, even if it was already hosted and managed at a service provider, but to completely nest it inside a vCloud Director tenancy. But while I was planning the rebuild operation, I also decided it was time to make its creation process as automated as possible, and while doing so, I learned a bit about how to use Terraform.

Some basics

No, I’m not going to write yet another blog post about Hashicorp Terraform and how to use it. You can look for this at the official userguide, or search around for many articles. Here, I’m going to describe the way “I” used it, from the point of view of a total newbie.

Terraform is a powerful tool to make your own “Infrastructure as code”: that is, a language where you can describe your infrastructure in any detail, and then build it, modify it, or even destroy it, without having to do anything manually, but by simply executing the tool and using the configuration as the input.

Initial configuration for vCloud Director

The first thing we have to do is to download the software, for Windows in my case. It comes in a single executable file that is around 70 MB, and for my ease of use I’ve placed it into a dedicated folder, that is c:\terraform.

Once we have the software, we need to initialize the environment by telling Terraform which platform we want to use. Terraform has plugins (or “providers” in Terraform terms) for many environments, like AWS, Google Cloud, Azure. In our case, we need the official provider for vCloud Director. but also for providers, we don’t have to do anything manually, we just configure the system to consume vCloud Director, and during the first initialization, Terraform will download automatically the needed software.

So, let’s talk about the configuration. Terraform uses files where the code is written in a specific language, and they have to be saved with a .tf extension. All files in a folder are parsed and applied, so we can split the description of the infrastructure into multiple files. The first files are variable.tf (where i list all the main variables I use):

variable “vcd_user” {

description = “vCloud user”

}

variable “vcd_pass” {

description = “vCloud pass”

}

variable “vcd_org” {

description = “vCloud org”

}

variable “vcd_vdc” {

description = “vCloud VDC”

}

variable “vcd_url” {

description = “vCloud url”

}

And terraform.tfvars where I store all the parameters of the main variables:

vcd_user = “user”

vcd_pass = “password”

vcd_org = “org”

vcd_vdc = “vdc”

vcd_url = “https://vcloud.provider.com/api”

(I’ve replaced the real login information with fake data)

With these files in the folder, we can open a command prompt and already initialize Terraform, by using the command terraform init:

As you can see, Terraform downloaded the plugin for the vCloud Director provider. You can also initialize the environment using terraform init -upgrade so that Terraform will always check for new versions of the plugin and download them:

Let’s create some networks

Exactly like during a manual configuration, the first operation inside vCloud Director will probably be to create the needed networks. I describe this network in my configuration, like this:

provider “vcd” {

user = “${var.vcd_user}“

password = “${var.vcd_pass}“

org = “${var.vcd_org}“

vdc = “${var.vcd_vdc}“

url = “${var.vcd_url}“

}

resource “vcd_network_routed” “net1” {

name = “vcc-management”

edge_gateway = “VeeamLab_Edge”

gateway = “10.10.51.254”

netmask = “255.255.255.0”

dns1 = “10.10.51.21”

dns2 = “10.10.51.22”

dns_suffix = “cloudconnect.local”

dhcp_pool {

start_address = “10.10.51.101”

end_address = “10.10.51.120”

}

}

It’s finally time to execute the code. This is done by running terraform apply (I’m using Terraform 0.12, versions before 0.11 use the plan command):

I answer yes, and I let Terraform complete the task.

And we have our first vCloud Organization Network, routed via a new NSX Edge firewall:

And all of this, without having to do a single click in the vCloud director interface!

Next time, I will start to build my virtual machines.

Share this:

  • Twitter
  • Facebook
  • LinkedIn
  • Email
  • Tumblr
  • Pinterest
  • Reddit
  • WhatsApp
  • Pocket
Tech automationcodedirectorinfrastructureterraformvcloudvmware

Post navigation

Previous post
Next post

Search

Sponsors

Latest Posts

  • My Automated Lab project: #2 Create a Ubuntu template in VMware vSphere with Packer
  • My Automated Lab project: #1 Install and configure the needed tools
  • Calculate space savings of a XFS volume with reflink and Veeam fast clone
  • A new whitepaper: Veeam Backup & Replication V12 enhanced security and scalability with object storage Secure Mode
  • Enable EVC mode in an existing vSphere Cluster with VCSA and VSAN in it
©2023 Virtual To The Core | WordPress Theme by SuperbThemes