Iam testing out various scenarios with Terraform using Vsphere virtual machine as a backend.
I am able to do green field deployments and able to change settings, but I am now testing to import existing vm’s.
I am using a variable collection to handle my organisation of VMs. So for example I have this as my resource.
resource "vsphere_virtual_machine" "worker" {
for_each = {for vm , vm_data in var.worker: vm => vm_data }
name = each.value.name
resource_pool_id = data.vsphere_compute_cluster.cluster.resource_pool_id
datastore_id = data.vsphere_datastore.datastore.id
folder = vsphere_folder.folder.path
num_cpus = var.vm-cpu-worker
memory = var.vm-ram-worker
guest_id = var.vm-guest-id
cpu_hot_add_enabled = true
cpu_hot_remove_enabled = true
memory_hot_add_enabled = true
network_interface {
network_id = data.vsphere_network.network.id
}
disk {
label = "disk0"
size = 100
}
clone {
template_uuid = data.vsphere_virtual_machine.template.id
timeout = 60
customize {
timeout = 0
linux_options {
host_name = each.value.name
domain = var.vm-domain
}
network_interface {
ipv4_address = each.value.ip_address
ipv4_netmask = 24
}
ipv4_gateway = "192.168.1.203"
dns_server_list = [ "192.168.1.234", "192.168.1.235" ]
}
}
}
and I have this in my terraform.tfvars.
worker = [
{
ip_address = "192.168.1.239"
name = "KUBE-WORKER1"
},
{
ip_address = "192.168.1.237"
name = "KUBE-WORKER2"
},
{
ip_address = "192.168.1.127"
name = "KUBE-WORKER3"
}
]
I have the variables in my variables.tf
So i import in my machine from VMware like so:
terraform import vsphere_virtual_machine.worker[“2”] “/Prometheus/vm/Kubernetes Applications/KUBE-WORKER3”
When I do a plan it shows that it will remove this VM and recreate it.
I am trying to figure out why.
Many thanks in advance for any help for any help. ]
regards,
WY