Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ovf_mapping ForceNew prevents adding new interfaces to VMs created from content library #1313

Open
4 tasks done
axelrtgs opened this issue Jan 18, 2021 · 8 comments
Open
4 tasks done
Labels
acknowledged Status: Issue or Pull Request Acknowledged area/ovf Area: OVA/OVF bug Type: Bug confirmed Issue: Confirmed
Milestone

Comments

@axelrtgs
Copy link

axelrtgs commented Jan 18, 2021

Community Guidelines

  • I have read and agree to the HashiCorp Community Guidelines .
  • Vote on this issue by adding a 👍 reaction to the original issue initial description to help the maintainers prioritize.
  • Do not leave "+1" or other comments that do not add relevant information or questions.
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment.

Description

"ovf_mapping": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Description: "Mapping of network interface to OVF network.",
},

When adding a new network interface to a VM created from a content library OVF template it tries to replace the VM. This behaviour is not desired for us.

Once the VM is up and running, adding an interface should not recreate the entire VM. When creating a VM from an OVF template you need to specify an OVF Mapping field. This field is ignored once the VM is created. There is no validation on the vmware side that the mappings actually exist in the OVF only that they are unique. It is possible to use random strings in the ovf_mapping property VMware will still create the VM for you.

Is there a possibility of changing this to not force the vm recreation when adding interfaces to VMs created from OVF? This is useful when using the content library to store templates for distribution. We expect them to behave like regular templates where we can add interfaces without recreating the VM.

Thanks

EDIT::

A proposed solution might be to keep the ForceNew but when deploying from content library OVF template and ovf_mapping is not set initialize it to some unique value when generating the API call to satisfy the vsphere api. This would be both compatible with the current behaviour to force recreation when the value changes but also be compatible with templates that don't have rigid mappings and assign additional interfaces at creation time.

@joerr1
Copy link

joerr1 commented Oct 14, 2021

We're currently experiencing this problem. Has a fix been found for this? @axelrtgs

@tenthirtyam tenthirtyam added the bug Type: Bug label Jan 28, 2022
@tenthirtyam tenthirtyam added acknowledged Status: Issue or Pull Request Acknowledged needs-triage Status: Issue Needs Triage labels Feb 9, 2022
@tenthirtyam tenthirtyam added the area/ovf Area: OVA/OVF label Feb 22, 2022
@tenthirtyam
Copy link
Collaborator

Community Note:

Vote on this issue by adding a 👍 reaction to the original issue initial description to help the maintainers prioritize.


I took some time to test this scenario today using the following:

provider "vsphere" {
  vsphere_server       = var.vsphere_server
  user                 = var.vsphere_username
  password             = var.vsphere_password
  allow_unverified_ssl = var.vsphere_insecure
}

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

data "vsphere_network" "network" {
  name          = var.vsphere_network
  datacenter_id = data.vsphere_datacenter.datacenter.id
}

data "vsphere_compute_cluster" "cluster" {
  name          = var.vsphere_cluster
  datacenter_id = data.vsphere_datacenter.datacenter.id
}

data "vsphere_resource_pool" "pool" {
  name          = format("%s%s", data.vsphere_compute_cluster.cluster.name, "/Resources")
  datacenter_id = data.vsphere_datacenter.datacenter.id
}

data "vsphere_datastore" "datastore" {
  name          = var.vsphere_datastore
  datacenter_id = data.vsphere_datacenter.datacenter.id
}

data "vsphere_content_library" "content_library" {
  name = var.vsphere_content_library
}

data "vsphere_content_library_item" "content_library_item" {
  name       = var.vsphere_content_library_ovf
  type       = "ovf"
  library_id = data.vsphere_content_library.content_library.id
}

resource "vsphere_virtual_machine" "vm" {
  name                    = var.vm_name
  folder                  = var.vsphere_folder
  num_cpus                = var.vm_cpus
  memory                  = var.vm_memory
  firmware                = var.vm_firmware
  efi_secure_boot_enabled = var.vm_efi_secure_boot_enabled
  datastore_id            = data.vsphere_datastore.datastore.id
  resource_pool_id        = data.vsphere_resource_pool.pool.id
  network_interface {
    network_id = data.vsphere_network.network.id
  }
  disk {
    label            = "disk0"
    size             = var.vm_disk_size
    thin_provisioned = true
  }
  clone {
    template_uuid = data.vsphere_content_library_item.content_library_item.id
    customize {
      linux_options {
        host_name = var.vm_hostname
        domain    = var.vm_domain
      }
      network_interface {
        ipv4_address = var.vm_ipv4_address_0
        ipv4_netmask = var.vm_ipv4_netmask
      }

      ipv4_gateway    = var.vm_ipv4_gateway
      dns_suffix_list = var.vm_dns_suffix_list
      dns_server_list = var.vm_dns_server_list
    }
  }
  lifecycle {
    ignore_changes = [
      clone[0].template_uuid,
    ]
  }
}

After deployment of the OVF Template from the content library, add additional network interfaces...

resource "vsphere_virtual_machine" "vm" {
  name                    = var.vm_name
  folder                  = var.vsphere_folder
  num_cpus                = var.vm_cpus
  memory                  = var.vm_memory
  firmware                = var.vm_firmware
  efi_secure_boot_enabled = var.vm_efi_secure_boot_enabled
  datastore_id            = data.vsphere_datastore.datastore.id
  resource_pool_id        = data.vsphere_resource_pool.pool.id
  network_interface {
    network_id = data.vsphere_network.network.id
  }
  network_interface {
    network_id = data.vsphere_network.network.id
  }
  disk {
    label            = "disk0"
    size             = var.vm_disk_size
    thin_provisioned = true
  }
  clone {
    template_uuid = data.vsphere_content_library_item.content_library_item.id
    customize {
      linux_options {
        host_name = var.vm_hostname
        domain    = var.vm_domain
      }
      network_interface {
        ipv4_address = var.vm_ipv4_address_0
        ipv4_netmask = var.vm_ipv4_netmask
      }
      network_interface {
        ipv4_address = var.vm_ipv4_address_1
        ipv4_netmask = var.vm_ipv4_netmask
      }

      ipv4_gateway    = var.vm_ipv4_gateway
      dns_suffix_list = var.vm_dns_suffix_list
      dns_server_list = var.vm_dns_server_list
    }
  }
  lifecycle {
    ignore_changes = [
      clone[0].template_uuid,
    ]
  }
}

Running terraform apply results in destruction.

Plan: 1 to add, 0 to change, 1 to destroy.
vsphere_virtual_machine.vm: Destroying... [id=4202838d-ba9c-bb0a-01bf-c595e95fa00c]
vsphere_virtual_machine.vm: Destruction complete after 8s

However, simply removing the ForceNew from the ovf_deploy for the sub-resources does not address the issue and the results are the same. _(I performed some tests with this, too.).

This aside, this is not an ideal scenario as the content library is used to redistribute baseline machine images that may or may not need additional interfaces based on the use case.

Marking as confirmed.

Ryan Johnson
Staff II Solutions Architect | VMware, Inc.

@tenthirtyam tenthirtyam added confirmed Issue: Confirmed and removed needs-triage Status: Issue Needs Triage labels Mar 4, 2022
@tenthirtyam tenthirtyam added this to the Backlog milestone Mar 21, 2022
@jakegroves
Copy link

Any further information on this being picked up?

@joedwards32
Copy link

Also having this issue.

@Ilhaame
Copy link

Ilhaame commented Nov 21, 2022

Hello,
Any news ? Because we have the same problems...

@tenthirtyam
Copy link
Collaborator

Community Note

  • Vote on this issue by adding a 👍 reaction to the original issue initial description to help the maintainers prioritize.
  • Do not leave "+1" or other comments that do not add relevant information or questions.
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment.

@tenthirtyam tenthirtyam self-assigned this Jun 15, 2024
@tenthirtyam tenthirtyam modified the milestones: Backlog, On Deck Jun 15, 2024
@tenthirtyam tenthirtyam modified the milestones: On Deck, Backlog Jun 28, 2024
@tenthirtyam tenthirtyam removed their assignment Aug 20, 2024
@burnsjared0415
Copy link
Collaborator

i looked at this and it does not even create a new interface on recreate, i believe there might be other issues here.

@lado936
Copy link

lado936 commented Dec 12, 2024

Any news? After adding ovf_mapping to already created vms, it tries to force replace servers, as per docs ovf_mapping should be ignored after server creation, but that not the case

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
acknowledged Status: Issue or Pull Request Acknowledged area/ovf Area: OVA/OVF bug Type: Bug confirmed Issue: Confirmed
Projects
None yet
Development

No branches or pull requests

8 participants