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 plan/apply followed by terraform plan returns esxi_virtual_disk changes #154

Open
rgl opened this issue Sep 25, 2021 · 1 comment

Comments

@rgl
Copy link
Contributor

rgl commented Sep 25, 2021

Describe the bug

A terraform plan/apply followed by terraform plan returns esxi_virtual_disk changes.

To Reproduce

  1. terraform plan/apply
  2. terraform plan

Expected behavior

I expected to see no changes after the first plan/apply.

Terraform files

variable "template" {
  default = "packer-esxi-7.0.2-amd64-esxi"
}

variable "name" {
  default = "esxi"
}

variable "datastore" {
  default = "datastore1"
}

provider "esxi" {
  esxi_hostname = "10.3.0.222"
  esxi_username = "root"
  esxi_password = "xxx"
}

resource "esxi_portgroup" "esxi" {
  name = var.name
  vswitch = "vSwitch0"
  vlan = 0
  promiscuous_mode = true
  forged_transmits = true
  mac_changes = false
}

resource "esxi_virtual_disk" "datastore1" {
  virtual_disk_disk_store = var.datastore
  virtual_disk_dir = var.name
  virtual_disk_size = 40
}

resource "esxi_guest" "esxi" {
  guest_name = var.name
  disk_store = var.datastore
  numvcpus = 4
  memsize = 4*1024
  clone_from_vm = var.template
  network_interfaces {
    virtual_network = esxi_portgroup.esxi.id
  }
  virtual_disks {
    virtual_disk_id = esxi_virtual_disk.datastore1.id
    slot = "0:1"
  }
}

Desktop (please complete the following information):

  • OS: Ubuntu Linux 20.04
  • Terraform Version: 1.0.6
  • Ovftool Version: 4.4.0 (build-15722219)
  • This Plugin Version: 1.8.3

Additional context

Here's the steps I've executed and the terraform output:

rgl@rgl-desktop:~/Projects/terraform-provider-esxi/rgl/port-groups$ terraform plan -out=tfplan

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the
following symbols:
  + create

Terraform will perform the following actions:

  # esxi_guest.esxi will be created
  + resource "esxi_guest" "esxi" {
      + boot_disk_size         = (known after apply)
      + boot_disk_type         = "thin"
      + clone_from_vm          = "packer-esxi-7.0.2-amd64-esxi"
      + disk_store             = "datastore1"
      + guest_name             = "esxi"
      + guest_shutdown_timeout = (known after apply)
      + guest_startup_timeout  = (known after apply)
      + guestos                = (known after apply)
      + id                     = (known after apply)
      + ip_address             = (known after apply)
      + memsize                = "4096"
      + notes                  = (known after apply)
      + numvcpus               = "4"
      + ovf_properties_timer   = (known after apply)
      + power                  = (known after apply)
      + resource_pool_name     = "/"
      + virthwver              = (known after apply)

      + network_interfaces {
          + mac_address     = (known after apply)
          + nic_type        = (known after apply)
          + virtual_network = (known after apply)
        }

      + virtual_disks {
          + slot            = "0:1"
          + virtual_disk_id = (known after apply)
        }
    }

  # esxi_portgroup.esxi will be created
  + resource "esxi_portgroup" "esxi" {
      + forged_transmits = true
      + id               = (known after apply)
      + mac_changes      = false
      + name             = "esxi"
      + promiscuous_mode = true
      + vlan             = 0
      + vswitch          = "vSwitch0"
    }

  # esxi_virtual_disk.datastore1 will be created
  + resource "esxi_virtual_disk" "datastore1" {
      + id                      = (known after apply)
      + virtual_disk_dir        = "esxi"
      + virtual_disk_disk_store = "datastore1"
      + virtual_disk_name       = (known after apply)
      + virtual_disk_size       = 40
      + virtual_disk_type       = "thin"
    }

Plan: 3 to add, 0 to change, 0 to destroy.

───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

Saved the plan to: tfplan

To perform exactly these actions, run the following command to apply:
    terraform apply "tfplan"
rgl@rgl-desktop:~/Projects/terraform-provider-esxi/rgl/port-groups$ terraform apply tfplan
esxi_portgroup.esxi: Creating...
esxi_virtual_disk.datastore1: Creating...
esxi_virtual_disk.datastore1: Creation complete after 1s [id=/vmfs/volumes/datastore1/esxi/vdisk_9AF9F813FC.vmdk]
esxi_portgroup.esxi: Creation complete after 3s [id=esxi]
esxi_guest.esxi: Creating...
esxi_guest.esxi: Still creating... [10s elapsed]
esxi_guest.esxi: Still creating... [20s elapsed]
esxi_guest.esxi: Still creating... [30s elapsed]
esxi_guest.esxi: Still creating... [40s elapsed]
esxi_guest.esxi: Creation complete after 49s [id=8]

Apply complete! Resources: 3 added, 0 changed, 0 destroyed.
rgl@rgl-desktop:~/Projects/terraform-provider-esxi/rgl/port-groups$ terraform plan -out=tfplan
esxi_portgroup.esxi: Refreshing state... [id=esxi]
esxi_virtual_disk.datastore1: Refreshing state... [id=/vmfs/volumes/datastore1/esxi/vdisk_9AF9F813FC.vmdk]
esxi_guest.esxi: Refreshing state... [id=8]

Note: Objects have changed outside of Terraform

Terraform detected the following changes made outside of Terraform since the last "terraform apply":

  # esxi_virtual_disk.datastore1 has been changed
  ~ resource "esxi_virtual_disk" "datastore1" {
        id                      = "/vmfs/volumes/datastore1/esxi/vdisk_9AF9F813FC.vmdk"
      + virtual_disk_name       = "vdisk_9AF9F813FC.vmdk"
        # (4 unchanged attributes hidden)
    }

Unless you have made equivalent changes to your configuration, or ignored the relevant attributes using ignore_changes,
the following plan may include actions to undo or respond to these changes.

───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

No changes. Your infrastructure matches the configuration.

Your configuration already matches the changes detected above. If you'd like to update the Terraform state to match,
create and apply a refresh-only plan:
  terraform apply -refresh-only
rgl@rgl-desktop:~/Projects/terraform-provider-esxi/rgl/port-groups$ 
@josenk
Copy link
Owner

josenk commented Oct 27, 2021

You are right about this... I really don't think many (if anyone) actually use this feature, but it certainly should be addressed.

Way back when I originally created this plugin, I added the ability to create a virtual disk without specifying the disk name. It would create a random virtual_disk_name... Now at this point, I think it was a bad decision to do it.

I'll need to look into this problem further, but a simple work-around would be to simply specify the virtual_disk_name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants