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

Please include folders in search for network_interface labels in vsphere_virtual_machine provider #5843

Closed
xantheran opened this issue Mar 24, 2016 · 10 comments

Comments

@xantheran
Copy link

I have been running into an issue with the vsphere_virtual_machine provider. My networks are in a folder off of root so I need to included the folder with the label field under network_interface.

  network_interface {
    label = "Hosted_Network/VL74_dvPortGroup"
    ipv4_address = "10.X.Y.Y"
    ipv4_prefix_length = "24"
  }

The VM gets provisioned just fine, however the folder not taken into account when returning the label for the network_interface. This results in the error below if I taint the resource

Error applying plan:

1 error(s) occurred:

* vsphere_virtual_machine.base: network '*VL74_dvPortGroup_IAP' not found

If I leave the folder in the label field terraform forces a new resource since it detects a change in the rendered plan

-/+ module.stage.couchbase-data.vsphere_virtual_machine.base
    cluster:                                "TerraformTest Hosting Cluster" => "TerraformTest Hosting Cluster"
    datacenter:                             "ZZ Datacenter" => "ZZ Datacenter"
    disk.#:                                 "1" => "1"
    disk.0.datastore:                       "Hosted_Datastores/VMSTOR.1" => "Hosted_Datastores/VMSTOR.1"
    disk.0.template:                        "devops/zz/Templates/ubuntu1404-template" => "devops/zz/Templates/ubuntu1404-template"
    disk.0.type:                            "thin" => "thin"
    dns_servers.#:                          "2" => "2"
    dns_servers.0:                          "10.X.X.X" => "10.X.X.X"
    dns_servers.1:                          "10.X.X.Y" => "10.X.X.Y"
    domain:                                 "devops.internal" => "devops.internal"
    folder:                                 "devops/zz/VMs/Staging/DATA" => "devops/zz/VMs/Staging/DATA"
    gateway:                                "10.X.Y.1" => "10.X.Y.1"
    memory:                                 "8192" => "8192"
    name:                                   "STAGE-COUCHBASE112" => "STAGE-COUCHBASE112"
    network_interface.#:                    "1" => "1"
    network_interface.0.ip_address:         "" => "<computed>"
    network_interface.0.ipv4_address:       "10.X.Y.Y" => "10.X.Y.Y"
    network_interface.0.ipv4_prefix_length: "24" => "24"
    network_interface.0.ipv6_address:       "<scrubbed>" => "<computed>"
    network_interface.0.ipv6_prefix_length: "<scrubbed>" => "<computed>"
    network_interface.0.label:              "VL74_dvPortGroup" => "Hosted_Network/VL74_dvPortGroup (forces new resource)
    network_interface.0.subnet_mask:        "" => "<computed>"
    time_zone:                              "America/Chicago" => "America/Chicago"
    vcpu:                                   "4" => "4"
@chrislovecnm
Copy link
Contributor

chrislovecnm commented Apr 16, 2016

@xantheran this is a duplicate issue, just asked for advice on how to handle this from a couple of gurus.
Adding required folder names would be a breaking change. If we force that people would have to update existing TF files to meet the new standard.

Please comment on: #5607

@chrislovecnm
Copy link
Contributor

chrislovecnm commented Apr 16, 2016

@xantheran actually you opened this issue first :) I just run into the other one first ... lol. Appreciate you submitting the issue. Are you able to assist?

Also if you change the network to just VL74_dvPortGroup it should work.

@xantheran
Copy link
Author

Yep. commented on issue #5607 and would be happy to assist.

@Shruti29
Copy link

Shruti29 commented Jun 15, 2016

@chrislovecnm I think the wildcard searching is not causing this particular issue.
Like @xantheran has mentioned, the VM gets created just fine under the right label.

The issue is happening when terraform uses govmomi api to read the resource information once it is created.
https://github.com/hashicorp/terraform/blob/master/builtin/providers/vsphere/resource_vsphere_virtual_machine.go#L991

networkInterfaces := make([]map[string]interface{}, 0)
    for _, v := range mvm.Guest.Net {
        if v.DeviceConfigId >= 0 {
            log.Printf("[DEBUG] v.Network - %#v", v.Network)
            networkInterface := make(map[string]interface{})
            networkInterface["label"] = v.Network

I think v.Network is returning just the label name and not the full path.

For a sample network resource creation,

network_interface {
    label = "Hosted_Network/VL74_dvPortGroup"
    ipv4_address = "10.X.Y.Y"
    ipv4_prefix_length = "24"
  }

Terraform creates the VM network under the right network adapter VL74_dvPortGroup which is under the folder Hosted_Network.

Not completely sure about this, but when it tries to save the resource info into state file, the function resourceVSphereVirtualMachineRead is called.
This function reads resource info using the govmomi API and this is when the govmomi API returns just VL74_dvPortGroup for network label, instead of Hosted_Network/VL74_dvPortGroup.

I have run some basic tests by overriding the line 991 with

if label_temp, ok := d.GetOk("network_interface.0.label"); ok {
   log.Printf("[DEBUG] Network label temp root %v", label_temp.(string))
   label_root = label_temp.(string)
} else {
   log.Printf("[DEBUG] Could not get network label for %s", d.Id())
}
networkInterface["label"] = label_root
// networkInterface["label"] = v.Network

The state file then saves the entire path of network label Hosted_Network/VL74_dvPortGroup.
And terraform plan runs just fine the next time.

The problem doesnt lie in the terraform code.
I guess we should figure out a way for govmomi to return the full path of network label when there is a folder hierarchy.

@xantheran Can you please test the above changes and let me know if it works as expected. I feel obligated to mention here that this is not a fix but a way to see where the problem lies 😅

@git4sroy
Copy link

when terraform plan says network_interface.0.label: "VL74_dvPortGroup" => "Hosted_Network/VL74_dvPortGroup (forces new resource). Does that mean it will try to create the resource if I do ansible apply. Even though the resource already exists.

@chrislovecnm
Copy link
Contributor

@git4sroy force new resource means create new, because we do not have an update, it creates new

@ktham
Copy link

ktham commented Nov 7, 2016

is anyone still looking into this issue?

@bpoland
Copy link

bpoland commented Nov 30, 2016

I was able to work around this with ignore_changes in my vsphere_virtual_machine resource. Would still be nice if this were fixed though.

lifecycle {
    ignore_changes = ["network_interface"]
  }

@jcarterch
Copy link

Does anyone know the status of this issue? Seems to still affect 0.9.6.

@ghost
Copy link

ghost commented Apr 11, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Apr 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

9 participants