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

ipv4_prefix_length = 0 gets "reset" on every apply #224

Closed
tmlink opened this issue Oct 25, 2017 · 2 comments
Closed

ipv4_prefix_length = 0 gets "reset" on every apply #224

tmlink opened this issue Oct 25, 2017 · 2 comments
Labels
bug Type: Bug

Comments

@tmlink
Copy link

tmlink commented Oct 25, 2017

Terraform Version

v0.10.7

vSphere Provider Version

0.4.2

Affected Resource(s)

  • vsphere_virtual_machine

Terraform Configuration Files

variable auth-password  { type = "string" }
variable auth-server    { type = "string" }
variable auth-user      { type = "string" }

provider "vsphere" {
  user           = "${var.auth-user}"
  password       = "${var.auth-password}"
  vsphere_server = "${var.auth-server}"
  allow_unverified_ssl = true
}

resource "vsphere_virtual_machine" "addr-test1" {
  name    = "addr-test1"
  cluster = "support"
  vcpu    = 1
  memory  = 2048

  network_interface {
    label = "devlab"
    ipv4_address       = ""
    ipv4_prefix_length = 0
    ipv4_gateway       = ""
  }

  disk {
    template  = "template-221"
    datastore = "datastore.34"
  }
}

output addr-test1-address { value = "${vsphere_virtual_machine.addr-test1.*.network_interface.0.ipv4_address}" }

Expected Behavior

     network_interface.0.ipv4_prefix_length: <computed>

Actual Behavior

Before an apply:

      network_interface.0.ipv4_prefix_length: "0"

After an apply:

Terraform will perform the following actions:

~ vsphere_virtual_machine.addr-test1
      network_interface.0.ipv4_prefix_length: "21" => "0"

ie:

$ terraform apply  -no-color
vsphere_virtual_machine.addr-test1: Refreshing state... (ID: addr-test1)
vsphere_virtual_machine.addr-test1: Modifying... (ID: addr-test1)
  network_interface.0.ipv4_prefix_length: "21" => "0"
vsphere_virtual_machine.addr-test1: Modifications complete after 4s (ID: addr-test1)

Apply complete! Resources: 0 added, 1 changed, 0 destroyed.

Outputs:

addr-test1-address = [
    172.27.18.76
]

$ terraform apply  -no-color
vsphere_virtual_machine.addr-test1: Refreshing state... (ID: addr-test1)
vsphere_virtual_machine.addr-test1: Modifying... (ID: addr-test1)
  network_interface.0.ipv4_prefix_length: "21" => "0"
vsphere_virtual_machine.addr-test1: Modifications complete after 4s (ID: addr-test1)

Apply complete! Resources: 0 added, 1 changed, 0 destroyed.

Outputs:

addr-test1-address = [
    172.27.18.76
]

Steps to Reproduce

  1. terraform plan
  2. terraform apply
  3. terraform plan

Important Factoids

This is really a nit about presentation.

It works, in that the host is set up as expected:

  • ifconfig looks good
  • the terraform.tfstate file has: "network_interface.0.ipv4_prefix_length": "21",

But the plan will be confusing to customers. Perhaps a value of "0" could unset the variable so that it looks like it was never set.

(The example is a simplified test of concept. I the real modules, the values of ipv4_address, ipv4_prefix_length, and ipv4_gateway will be set by variables)

References

The reply to hashicorp/terraform#5471 says:

Most resources at the moment must just be written to accept some "zero" value as unset. If a resource doesn't support this please report a bug.

@vancluever
Copy link
Contributor

Hey @tmlink, we actually have #244 in now which is a complete rewrite of the VM resource. In the new version we move all customization options to a new customize block, which never has values written in from running VM state - it's basically a fire-and-forget block that forces a new resource if it's never changed. So the spurious diff stuff that you are seeing should go away.

For more details and links to the new documentation, check out the PR. I will keep this open until it is merged to track when thing are actually fixed.

Thanks!

@vancluever vancluever added the bug Type: Bug label Nov 18, 2017
@bill-rich
Copy link
Contributor

This should be resolved in combination by #244, and by Terraform v0.12 differentiating between null and zero values.

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

No branches or pull requests

3 participants