Sunday, June 30, 2024

Terraform script to add a new vmxnet3 network adapter to a VM in vCenter

 Using this script add a new vmxnet3 network adapter to a VM in vCenter


Replace "your-vcenter-username", "your-vcenter-password", "your-vcenter-server", "your-datacenter-name", "your-cluster-name", and "your-vm-name" with your actual vCenter details.


"network-id" should be replaced with the ID of the network to which you want to connect the new vmxnet3 adapter.


Make sure you have the required Terraform provider for vSphere installed. 

You can run the script using the terraform apply command once everything is set up


provider "vsphere" {

  user           = "your-vcenter-username"

  password       = "your-vcenter-password"

  vsphere_server = "your-vcenter-server"


  # If you have a self-signed cert

  allow_unverified_ssl = true

}


data "vsphere_datacenter" "dc" {

  name = "your-datacenter-name"

}


data "vsphere_compute_cluster" "cluster" {

  name          = "your-cluster-name"

  datacenter_id = data.vsphere_datacenter.dc.id

}


data "vsphere_virtual_machine" "vm" {

  name          = "your-vm-name"

  datacenter_id = data.vsphere_datacenter.dc.id

}


resource "vsphere_virtual_machine_network_interface" "vmxnet3" {

  type         = "vmxnet3"

  network_id   = "network-id"  # Replace with your network id

  virtual_machine_id = data.vsphere_virtual_machine.vm.id

}


No comments:

Post a Comment

RAV migration cutover was failing after sync

 Issue: HCX RAV migration was failing after base sync and while cutover the VM. Noticed below error in hcx connector app logs. TxId: 4cda256...