Desired State monitoring with Terraform?
Some time ago, I wrote a post about Terraform and vSphere. In this post, I showed how appliances (.ova files) can be deployed with Terraform. Another use case for Terraform is deploying virtual machines from templates.
But with this, we would almost forget the most important use of Terraform, deploying vSphere Infrastructure, in Terraform terminology resources like Clusters, vSwitches, Datastores and more. In doing so, I discovered an interesting feature of Terraform.
I’ve long been interested in configuration management for vSphere, see older posts on Vester and DSC Resources for VMware.
In a nutshell, Configuration Management is a systematic process for setting and maintaining the configuration of a resource over its lifetime.
In my experience, maintaining it during its lifetime is the trickiest part.
And that is where Terraform differs from other tools I have seen in recent years. As an example, we compare the configuration of a Compute Cluster in a vCenter Server using “DSC Resources for VMware” (see the example in this post) on the one hand and Terraform on the other.
A simple DSC configuration for creating a Cluster may look like this:
Configuration DCKoedood { Import-DscResource -ModuleName VMware.vSphereDSC -ModuleVersion 2.2.0.84 vSphereNode $AllNodes.NodeName { Datacenter "DCKoedood" { Name = 'DCKoedood' Location = [string]::Empty Ensure = 'Present' } Cluster "Cluster-02" { Name = 'Cluster-02' Location = [string]::Empty DatacenterName = 'DCKoedood' DatacenterLocation = [string]::Empty Ensure = 'Present' HAEnabled = $true DrsEnabled = $true DependsOn = "[Datacenter]DCKoedood" } } }