hashicorp / terraform-provider-vsphere

Terraform Provider for VMware vSphere
https://registry.terraform.io/providers/hashicorp/vsphere/
Mozilla Public License 2.0
622 stars 452 forks source link

NICs being configured twice on Rocky Linux 9 #2271

Open bab5470 opened 1 month ago

bab5470 commented 1 month ago

Community Guidelines

Terraform

1.6.3

Terraform Provider

2.9.2

VMware vSphere

8.0.3

Description

I have a terraform script that performs a clone operation on a VMware template created with packer. In the terraform script I add two NICs to the existing VM (for a total of 3) and then configure IP information on all three.

What I see is that the new NICs in Rocky Linux are configured but duplicated:

ens256 VMware customization ens256 ens224 VMware customization ens224 ens192 VMware customization ens192

I am running openvmtools on the system. It seems like network connections are getting created in two places:

The ens connections are created in /etc/sysconfig/network-scripts, and the "Vmware Customizations" connections are created in /etc/Network-Manager/system-connections

I don't think connections are supposed to be created in both locations and obviously, we don't want our NIC/connections named "VMware customization xxxx"

Is this a bug in the VMware terraform provider, openvmtools, Rocky Linux?

Affected Resources or Data Sources

resource/vsphere_virtual_machine

Terraform Configuration

Variable file:

variable "vsphere_user" {
  type    = string
  default = "terraform@mydomain.local"
}

variable "vsphere_password" {
  type        = string
  description = "Terraform AD password"
}

variable "vm_template_name" {
  type        = string
  description = "The template to clone to create the VM"
  default     = "ROCKY9"
}

variable "root_password" {
  type        = string
  description = "Local linux root password"
}

variable vsphere_server {
  type        = string
  description = "VMware Server DNS Name"
}

variable vsphere_datacenter {
  type        = string
  description = "VMware Datacenter"
}

variable "vsphere_networks" {
  type = map(string)
  description = "A map of VM Networks for different NICs (e.g., nic1, nic2, nic3)"
}

variable vmware-hostnames {
  type        = map(string)
  description = "List of VM Names"
}

variable datastores {
  type        = map(string)
  description = "List of datastores"
}

variable vm_ips {
  type        = map(map(string))
  description = "List of VM IPs"
}

variable vm-count {
  description = "Number of VMs to create"
  type        = number
}

variable vsphere_resource_pool {
  description = "VMware Resource Pool"
  type        = string
}

variable ipv4_netmasks {
  description = "IPv4 Netmask"
  type        = map(number)
}

variable dns_server_list {
  description = "DNS Server List"
  type        = list(string)
}

variable ipv4_gateway {
  description = "IPv4 Gateway"
  type        = string
}

variable firmware {
  description = "EFI or BIOS"
  type        = string
}

variable dns_domain {
  description = "DNS Domain"
  type        = string
}

Terraform script

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

  # Allow self signed certs
  allow_unverified_ssl = true
}

data "vsphere_datacenter" "dc" {
  name = var.vsphere_datacenter
}

data "vsphere_datastore" "datastore" {
  name          = var.datastores[0]
  datacenter_id = data.vsphere_datacenter.dc.id
}

data "vsphere_network" "nic1" {
  name          = var.vsphere_networks["nic1"]
  datacenter_id = data.vsphere_datacenter.dc.id
}

data "vsphere_network" "nic2" {
  name          = var.vsphere_networks["nic2"]
  datacenter_id = data.vsphere_datacenter.dc.id
}

data "vsphere_network" "nic3" {
  name          = var.vsphere_networks["nic3"]
  datacenter_id = data.vsphere_datacenter.dc.id
}

data "vsphere_virtual_machine" "template" {
  name          = var.vm_template_name
  datacenter_id = data.vsphere_datacenter.dc.id
}

data "vsphere_resource_pool" "pool" {
  name          = var.vsphere_resource_pool
  datacenter_id = data.vsphere_datacenter.dc.id
}

resource "vsphere_virtual_machine" "vm" {
  count            = var.vm-count
  name             = var.vmware-hostnames[count.index]
  resource_pool_id = data.vsphere_resource_pool.pool.id
  datastore_id     = data.vsphere_datastore.datastore.id

  wait_for_guest_net_timeout = 20

  num_cpus = 4
  memory   = 4096
  guest_id = "rockylinux_64Guest"

  scsi_type = "pvscsi"
  firmware  = var.firmware

  network_interface {
    network_id   = data.vsphere_network.nic1.id
    adapter_type = "vmxnet3"
  }

  network_interface {
    network_id   = data.vsphere_network.nic2.id
    adapter_type = "vmxnet3"
  }

  network_interface {
    network_id   = data.vsphere_network.nic3.id
    adapter_type = "vmxnet3"
  }

  disk {
    label            = "disk0"
    size             = 40
    eagerly_scrub    = false
    thin_provisioned = true
  }

  cdrom {
    client_device = true

  }

  clone {
    template_uuid = data.vsphere_virtual_machine.template.id
    timeout       = "180"
    customize {
      timeout = "180"
      linux_options {
        host_name = var.vmware-hostnames[count.index]
        domain    = var.dns_domain
      }

      network_interface {
        ipv4_address = var.vm_ips[count.index]["nic1"]
        ipv4_netmask = var.ipv4_netmasks["nic1"]
        dns_server_list = var.dns_server_list
      }

      network_interface {
        ipv4_address = var.vm_ips[count.index]["nic2"]
        ipv4_netmask = var.ipv4_netmasks["nic2"]
      }

      network_interface {
        ipv4_address = var.vm_ips[count.index]["nic3"]
        ipv4_netmask = var.ipv4_netmasks["nic3"]
      }

      ipv4_gateway    = var.ipv4_gateway
    }
  }
}

Debug Output

I am happy to provide this privately but not post debug output with sensitive information about our environment in a public place. Please let me know how I send this safely/securely.

Panic Output

No response

Expected Behavior

A single set of interfaces are connected and configured.

Actual Behavior

Multiple nics show up in nmtui or nmcli with different names but identical configs.

Steps to Reproduce

Run the above scripts

Environment Details

Rocky Linux 9.4 Open-VM-Tools 12.3.5

Screenshots

image image image image

References

No response

github-actions[bot] commented 1 month ago

Hello, bab5470! 🖐

Thank you for submitting an issue for this provider. The issue will now enter into the issue lifecycle.

If you want to contribute to this project, please review the contributing guidelines and information on submitting pull requests.