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

terraform 0.6.16 - Vmware Vsphere Provider - ipv4_gateway not saved in tfstate file #6590

Closed
totojack opened this issue May 10, 2016 · 13 comments

Comments

@totojack
Copy link

totojack commented May 10, 2016

Terraform Version

v0.6.16

Affected Resource(s)

  • vpshere_virtual_machine
  • network_interface
  • ipv4_gateway

Terraform Configuration Files

define variable from terraform.tvars

variable "vsphere_user" {}
variable "vsphere_password" {}
variable "vsphere_server" {}
variable "vsphere_cluster" {}
variable "vsphere_datacenter" {}
variable "vsphere_domain" {}
variable "vsphere_dns" {}
variable "vsphere_timezone" {}

Configure the VMware vSphere Provider

provider "vsphere" {
user = "${var.vsphere_user}"
password = "${var.vsphere_password}"
vsphere_server = "${var.vsphere_server}"
allow_unverified_ssl = true
}

Create a folder

resource "vsphere_folder" "testfolder" {
path = "TEST/Vms"
datacenter = "${var.vsphere_datacenter}"
}

Create a virtual machine within the folder

resource "vsphere_virtual_machine" "web" {
name = "terraform-web"
folder = "${vsphere_folder.testfolder.path}"
vcpu = 2
memory = 2048
datacenter = "${var.vsphere_datacenter}"
cluster = "${var.vsphere_cluster}"
domain = "my.custom.domain.com"
dns_servers = ["${var.vsphere_dns}"]
#resource_pool = ""
time_zone = "${var.vsphere_timezone}"

network_interface {
label = "virtualwire_Template"
ipv4_address = "172.16.1.19"
ipv4_prefix_length = "28"
ipv4_gateway = "172.16.1.17"
}

disk {
template = "TEMPLATE/Centos7_tmpl_20160422_01"
datastore = "VPLEX-SAS"
}
disk {
size = "20"
datastore = "VPLEX-SAS"
}
disk {
size = "10"
datastore = "VPLEX-SAS"
}
}

Debug Output

https://gist.github.com/totojack/4db892bf6d9b03b3b982401fedd8c2f6

Expected Behavior

After applying the configuration, ipv4_gateway value is set on tfstate file.

Actual Behavior

ipv4_gateway value is not saved to tfstate file, and plan command shows another time changes to be applied for network_interface ipv4_gateway. Plan output is:
(...)
network_interface.0.ipv4_gateway: "" => "172.16.1.17" (forces new resource)
(...)
Plan: 1 to add, 0 to change, 1 to destroy.

tfstate file is:

(...)
"network_interface.#": "1",
"network_interface.0.adapter_type": "",
"network_interface.0.ip_address": "",
"network_interface.0.ipv4_address": "172.16.1.19",
"network_interface.0.ipv4_gateway": "",
"network_interface.0.ipv4_prefix_length": "28",
"network_interface.0.ipv6_address": "",
"network_interface.0.ipv6_gateway": "",
"network_interface.0.ipv6_prefix_length": "0",
"network_interface.0.label": "virtualwire_Template",
"network_interface.0.subnet_mask": "",
"skip_customization": "false",
"time_zone": "Europe/Rome",
"vcpu": "2"
(...)

Steps to Reproduce

  1. add ipv4_gateway to network_interface configuration
  2. terraform apply
  3. terraform plan
@stack72
Copy link
Contributor

stack72 commented May 10, 2016

@chrislovecnm this may be worth looking into

P.

@chrislovecnm
Copy link
Contributor

@stack72 I think this is resolved. #6522

@thetuxkeeper please confirm

@thetuxkeeper
Copy link
Contributor

@chrislovecnm : Yes, it's fixed by #6522. Just confirmed it by testing and checking the code.
In resourceVSphereVirtualMachineRead the networkInterfaces map is rebuilt and replaces the one in the ResourceData object. All networkInterfaces subsettings not set in resourceVSphereVirtualMachineRead will be gone like the gateway setting. => setting the gateway fixes the behavior.
But that then we have the same problem with ipv6_gateway which is not covered by #6522.

@chrislovecnm
Copy link
Contributor

@totojack this is fixed in the master branch. Can you test?

@totojack
Copy link
Author

Hi Chris.

Yes, it's closed on the master branch.

Thanks,
Luca

@jare19
Copy link

jare19 commented Jul 21, 2016

This problem has not been solved for me. I am on v0.6.16, I may need to open another bug but the machine deploys fine with ipv4_gateway and it looks correct in the plan. Once the plan is applied and the machine is built, the statefile does not populate the address. On the next plan to 'fix' the issue, it shows that the machine needs to be destroyed and rebuilt due to a missing ipv4_gateway.

@kenerwin88
Copy link

Same as jare19, I'm still seeing this in v0.6.16 :(. Is there a beta available with the fix applied that we can use? Thank you!

@stack72
Copy link
Contributor

stack72 commented Jul 25, 2016

Hi @kenerwin88

There is an RC3 currently available https://releases.hashicorp.com/terraform/0.7.0-rc3/

Paul

@kenerwin88
Copy link

In recent news I love you, thanks Paul! :D

@jare19
Copy link

jare19 commented Nov 15, 2016

So this seems to now be an issue again in v0.7.10 is there a work around that can be applied? (sorry I have been away from TF for a while so I am unsure if it ever started working again)
edit it appears that if I use the deprecated option 'gateway' it works but not as suggested/warned in the plan.
vsphere_virtual_machine.vm: "gateway": [DEPRECATED] Please use network_interface.ipv4_gateway

@FartParty
Copy link

This is also a problem in terraform v0.7.11. ipv4_gateway is not saved in tfstate.

@thetuxkeeper
Copy link
Contributor

thetuxkeeper commented Nov 18, 2016

Can you please check if the gateway is set in the vsphere API? You can use the browser:

  1. https://vcenter_address/mob/
  2. "content"
  3. "rootFolder"
  4. the datacenter under "childEntity"
  5. "vmFolder"
  6. "childEntity" (multiple layers if you have them organized in folders) until you get to the vm
  7. "guest"
  8. "ipStack"
    then GuestStackInfo->ipRouteConfig->ipRoute should contain the default gateway route somewhere.
    If not, then terraform doesn't have a chance to get the information over the vsphere API.
    If it's present, please verify the DeviceID if it matches the network interface index in the tfstate. Perhaps it's Terraform 0.7.0-dev built in vsphere network interface out of order #7673 which hasn't been fixed yet.

I don't see any reason why the settings should work different ("gateway" will be copied to "network_interface[].ipv4_gateway"). Just the one detail that "gateway" is set on all interfaces and network_interface[].ipv4_gateway only on the specified one (that could "workaround" #7673 or any "DeviceID <-> tfstate index"-mismatch).
I don't have time to test since I don't get much time for terraform (many other things with higher prio), but I'll try to help if possible.

@ghost
Copy link

ghost commented Apr 19, 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 19, 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

7 participants