Terraform VMware Infrastructure as Code for vSphere and VMware Cloud Foundation

Terraform provides a consistent workflow for provisioning and maintaining infrastructure and services. Terraform allows organizations to take a programmatic approach to infrastructure management. By logging, auditing, and versioning infrastructure changes, organizations gain better insight into the current state of their infrastructure.

VMware is a key component of many organizations' on-premises and private cloud infrastructure. The vSphere provider enables operators to adopt Terraform to build, change, and manage common VMware resources. The workflow moves beyond manual console operations to declarative configuration that can be versioned, reviewed, and reproduced.

This article covers the official vSphere provider, the VMware Cloud Foundation providers, and practical patterns for using Terraform with vCenter and ESXi.

Terraform and VMware vSphere Overview

Terraform, HashiCorp's infrastructure as code offering, provides a consistent workflow for provisioning and maintaining infrastructure and services. Terraform allows organizations to take a programmatic approach to infrastructure management. By logging, auditing, and versioning infrastructure changes, organizations gain better insight into the current state of their infrastructure.

VMware is a key component of many organizations' on-premises and private cloud infrastructure. The vSphere provider enables operators to adopt Terraform to build, change, and manage common VMware resources.

A typical tutorial path creates a vSphere template using Packer and provision a virtual machine from that template using Terraform. The same workflow then uses Terraform to modify the VM's name and resource allocations and create a snapshot of the VM. This tutorial assumes you are familiar with the standard Terraform workflow.

HashiCorp Terraform expands on the previously mentioned Packer tool, by not only deploying virtual machines but also storage, networking and security entities across multiple infrastructures, clouds and vendors. Packer provided the ability to create and manage virtual machines from a template written as a code. Terraform expands on this by not only deploying virtual machines but also storage, networking and security entities across multiple infrastructures, clouds and vendors.

The Terraform Provider for VMware vSphere

The Terraform Provider for VMware vSphere is a plugin for Terraform that allows you to interact with VMware vSphere. The provider supports versions in accordance with the Broadcom Product Lifecycle.

The Terraform Provider for VMware vSphere is a Partner tier provider. Partner tier providers are owned and maintained by a partner in the HashiCorp Technology Partner Program. HashiCorp verifies the authenticity of the publisher and the provider are listed on the Terraform Registry with a Partner tier label.

To use a released version of the Terraform provider in your environment, run terraform init and Terraform will automatically install the provider from the Terraform Registry. Unless you are contributing to the provider or require a pre-release bugfix or feature, use a released version of the provider.

See Installing the Terraform Provider for VMware vSphere for additional instructions on automated and manual installation methods and how to control the provider version. For either installation method, documentation about the provider configuration, resources, and data sources can be found on the Terraform Registry.

The provider does not upgrade automatically. After each new release, you can run the following command to upgrade the provider:

terraform init -upgrade

The Terraform Provider for VMware vSphere is the work of many contributors and the project team appreciates your help. If you discover a bug or would like to suggest an enhancement, submit an issue. If you would like to submit a pull request, please read the contribution guidelines to get started. In case of enhancement or feature contribution, we kindly ask you to open an issue to discuss it beforehand.

Because this Terraform provider is developed as an open-source project and follows standard GitHub community practices, we encourage customers to submit bug reports and enhancement requests directly in the project's GitHub repository. However, we recognize that some situations may require formal technical support through our Global Support Services process. In those cases, please open a case through the Broadcom support portal, referencing the provider, the provider version, and any related GitHub issue(s). When opening your case, please select VMware ESXi as the Product and choose VCF Terraform from the components drop-down menu.

The Terraform Provider for VMware vSphere is available under the Mozilla Public License, version 2.0 license.

Provider Configuration and Authentication

The official hashicorp/vsphere Terraform provider lets you create datacenters, clusters, resource pools, port groups, and virtual machines from templates with cloud-init customization — the same workflow you use for cloud VMs.

Configure the hashicorp/vsphere provider with user, password, and vsphereserver, your vCenter FQDN. Keep allowunverifiedssl = false in production and pass credentials via environment variables VSPHEREUSER, VSPHERE_PASSWORD or a secrets manager rather than hardcoding them.

The vsphere provider is built around vCenter — most resources, resource pools, distributed port groups, content libraries require it. A standalone ESXi host works for only a limited subset, so for real automation point Terraform at vCenter, not the ESXi host directly.

Look up the template with a vspherevirtualmachine data source, then reference its id in the clone block of your vspherevirtualmachine resource.

A minimal provider block pattern is:

provider "vsphere" { user = var.vsphere_user password = var.vsphere_password vsphere_server = var.vsphere_server allow_unverified_ssl = false }

VMware vSphere / ESXi remains the dominant on-prem hypervisor in 2026. The official hashicorp/vsphere Terraform provider lets you create datacenters, clusters, resource pools, port groups, and virtual machines from templates with cloud-init customization.

For Windows Sysprep, customize block options can be used.

customize { windows_options {} }

vsphere_tag can be used so you can drive backup, snapshot, and patching policies.

VMware Cloud Foundation and VCF Provider

Using the VMware Terraform providers offers several advantages for organizations looking to automate and manage their cloud infrastructure. IaC allows you to define your VMware Cloud Foundation environment in code, making it easier to manage, version, and reproduce your infrastructure. Declarative Syntax enables you to define the desired state of your infrastructure. While, State Management keeps track of the state of your infrastructure, allowing for accurate updates and rollbacks if necessary. Terraform configurations can be versioned and shared via Git, facilitating collaboration and review processes.

By leveraging the VCF Terraform provider, organizations can streamline their infrastructure management, improve operational efficiency, and enhance governance while reducing the complexity associated with traditional infrastructure provisioning.

A VCF provider configuration example:

terraform { required_providers { vcf = { source = "vmware/vcf" version = "x.y.z" } } } provider "vcf" { sddc_manager_host = var.sddc_manager_host sddc_manager_username = var.sddc_manager_username sddc_manager_password = var.sddc_manager_password allow_unverified_tls = var.allow_unverified_tls }

In today’s fast-paced digital landscape, organizations continuously seek ways to optimize their IT infrastructure while maintaining agility and control. Unlocking the Power of Automation: Benefits of Using the VMware Terraform Providers.

Terraform is a tool that expands on the previously mentioned Packer tool, by not only deploying virtual machines but also storage, networking and security entities across multiple infrastructures, clouds and vendors. In this blog article, Nico Vibert walks you through what Terraform is and how it works with VMware Cloud on AWS.

This blog post will walk through what Terraform is and how to set up Terraform with VMware, including a few examples with VMware Cloud on AWS.

Here are a few things about Terraform:

  • Part of Hashicorp DevOps Tool suite

Provider Comparison and Capabilities

Provider Scope Typical Use Case
hashicorp/vsphere VMware vSphere, vCenter, ESXi Virtual machines, datacenters, clusters, resource pools, port groups, content libraries
vmware/vcf VMware Cloud Foundation SDDC Manager, vSphere, NSX, Tanzu components
VMware Cloud on AWS VMware Cloud on AWS VMs, storage, networking, security entities across VMware Cloud on AWS
Capability vSphere Provider VCF Provider
Declarative syntax Yes Yes
State management Yes Yes
Versioning via Git Yes Yes
Template cloning Yes Via SDDC Manager
Snapshot management Yes Yes

The provider supports versions in accordance with the Broadcom Product Lifecycle.

Terraform Enterprise on VMware vSphere

Terraform Enterprise can be deployed on VMware vSphere with high availability requirements.

We recommend a setup with the following:

  • A load balancer to route traffic to both Terraform Enterprise virtual machines.
  • Both virtual machines located in the same physical datacenter and on the same network

For more information about high-speed and highly available storage, please see your storage vendor. We recommend that each of these VMs be deployed as immutable architecture to enable one to easily redeploy the secondary VM when the primary has been upgraded or changed. If this is not possible a snapshot methodology inherent to Terraform Enterprise along with examples of restoring those snapshots is available at Terraform Enterprise Automated Recovery.

For more information about Terraform Enterprise's disk requirements, see Before Installing: Disk Requirements.

The Active/Active mode provides a higher level of availability and failover as well as horizontal scaling. It requires additional external services, and all of the requirements and instructions are available on the Terraform Enterprise Active/Active page.

We have tested Active/Active on VMware vSphere internally, with ESXi version 7.0.1 and vCenter Server version 7.0.2.00200, but should work on any version supported by the vSphere Provider for Terraform.

Best Practices for VMware Terraform Automation

  • Point Terraform at vCenter, not directly at an ESXi host, for full resource coverage.
  • Store credentials in environment variables or a secrets manager. Never hardcode VSPHEREUSER and VSPHEREPASSWORD.
  • Keep allowunverifiedssl = false in production.
  • Use vspherevirtualmachine data source to look up templates and reference template_uuid in the clone block.
  • Version provider pins in required_providers blocks.
  • Use vsphere_tag for backup, snapshot, and patching policy automation.
  • Use immutable VM architecture for Terraform Enterprise deployments and rely on snapshots for recovery when needed.

Terraform for Hyper-V Virtualization shows the broader pattern. Automate Microsoft Hyper-V with Terraform: taliesins/hyperv provider, VM provisioning, virtual switches, and Windows Server-based hypervisor management.

VMware vSphere / ESXi remains the dominant on-prem hypervisor in 2026.

Conclusion

Terraform with VMware delivers infrastructure as code for both traditional vSphere estates and VMware Cloud Foundation environments. The hashicorp/vsphere Partner tier provider enables declarative management of virtual machines, datacenters, clusters, resource pools, port groups and content libraries with vCenter as the control plane. The vmware/vcf provider extends this model to VMware Cloud Foundation, allowing SDDC Manager-driven definitions to be versioned, reviewed and reproduced via Git.

Operational discipline matters. Authentication should use environment variables or secrets managers, allowunverifiedssl should remain false in production, and provider versions should be pinned and upgraded with terraform init -upgrade. State management, declarative syntax and Git-based collaboration provide accurate updates and rollbacks while reducing provisioning complexity.

With Packer for image building and Terraform for deployment, storage, networking and security entities, organizations can treat VMware infrastructure with the same programmatic rigor applied to cloud workloads, improving governance, efficiency and auditability across on-premises and VMware Cloud on AWS environments.

Sources

  1. developer.hashicorp.com/terraform/tutorials/virtual-machine/vsphere-provider
  2. github.com/vmware/terraform-provider-vsphere
  3. blogs.vmware.com/cloud-foundation/2019/11/19/infrastructure-code-terraform-vmware-vmware-cloud-aws/
  4. blogs.vmware.com/cloud-foundation/2024/12/09/vmware-cloud-foundation-infrastructure-as-code-iac-using-the-vmware-terraform-providers/
  5. terraformpilot.com/articles/terraform-vmware-vsphere-esxi/
  6. developer.hashicorp.com/terraform/enterprise/deploy/replicated/architecture/reference-architecture/vmware

Related Posts