Part 2 – Configure VMware vSphere Provider in Terraform Prod

In this blog, we will just add a new prod cluster. Except some very few changes, this is pretty simple to do.

A new cluster is created for our prod

Lets conect to ansible and just copy all files from dev and place into prod , we dont need the terraform.tfstate terraform.tfstate.backup tfplan as they belong to the dev so it looks like this now.

Make changes to data.file..

  • Name change – Cluster 01 to Cluster 02
  • Datastore cluster name – Change to Prod-DataStore Cluster

Under main.tf, change from prod to dev

Under the organise.tf file, this is where we have one chnage .. It tries to create the “Environment” tag category again. Dev already created it, and vCenter allows only one category with that name, so prod’s apply would fail with “already exists”. In prod it must be a lookup (data), not a resource so it should like

We can remove the above and replace with as shown

Nothing to change in providers.tf file

Under variables, we change the folder to Terraform-Prod and this is the default folder were all VM’s land initially.

Under the teraform.tfvars we also are going to add these new VM’s for our prod

Ok, let’s create the new Prod cluster

Apply the plan

First run this command to check-in our vCenter credentials

awk@ansible:/etc/ansible/terraform$ source env.sh
Password

Now, navigate to prod directory and run terraform init – this downloads the vSphere plugin

terraform init

terraform plan -out=tfplan shows what Terraform is about to do and it says 3 VM’s are going to be deploye d

Run terraform apply tfplan to deploy the VM

After few minutes, the VM are live in Cluster 02

All VM’s in prod land in

ansible -i “172.16.19.160,” all -m ping to check if The VM is reachable

Once everything is running smoothly git it.

References

How to Configure VMware vSphere Provider in Terraform

(Visited 8 times, 1 visits today)

By Ash Thomas

Ash Thomas is a seasoned IT professional with extensive experience as a technical expert, complemented by a keen interest in blockchain technology.