Terraform spec.identity.hostName error with vSphere provider

Today I’ve got a short post. It is especially dedicated to the new Terraform users, who use this tool for automation vSphere virtual machines. It is simply a matter of time till you face this problem. I mean, Terraform spec.identity.hostName error when you try to deploy your vSphere infrastructure. Why? Let me explain.

What is the problem?

At first I’ll show you the problem. After applying Terraform build, virtual machine is cloning and when a customization operation should start, you see something like this:

Terraform spec.identity.hostName error

When does Terraform spec.identity.hostName error appear?

I met this problem once and it was caused by my habit and – shame on me – ignorance. Let’s take a closer look on the resource example from the Terraform Docs:

This is version visible today, 19.02.2017. I want to make fix and add information from this post, but I do not know when (and whether) it will be merge. It is a huge project, so they have lots of work. 🙂

Anyway, the problem is in the name. It is a variable used in the process of cloning AND customization a Virtual Machine. If you look at the Terraform sources, you see in the “resource_vsphere_virtual_machine.go” that:

Everything above is the Go implementation of the VMware vSphere API. CustomizationLinuxPrep is a Data Object which has, among others, domain and hostName properties. Enough theory, now it’s time for practice. When I was looking for resolution, I found an issue #5448 made by Supernomad on the Terraform Github. He noticed that there is a VMware KB (2009820) which has a resolution for “\nspec.identity.userData.computerName” error. We can see there that:

To resolve this issue:
1) Reconfigure the parent virtual machine or template and ensure that:

  • The name is less than 15 characters
  • There are no underscores in the name

And of course it is the resolution for Terraform spec.identity.hostName error when you use vSphere provider. You should avoid any underscores in the name variable and be sure that the name is less than 15 characters. That’s all.

TL;DR version

If you get spec.identity.hostName error while using the vSphere provider, ensure yourself that:

  • The “name” variable in the resource section does not contain underscores.
  • The “name” variable in the resource section is less than 15 characters.

I hope you will find this post helpful and have fun with Terraform and vSphere!


6 Replies to “Terraform spec.identity.hostName error with vSphere provider”

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.