josenk / terraform-provider-esxi

Terraform-provider-esxi plugin
GNU General Public License v3.0
540 stars 154 forks source link

[add] Enable selection of firmware in guestCreate #129

Closed dohq closed 2 years ago

dohq commented 3 years ago

EFI is now available as a startup option.

dohq commented 2 years ago

Sorry for the lack of response for so long. All the points have been comments. It is working fine in my computer. Please check it out.

josenk commented 2 years ago

OK, thanks! No worries about how long it took... I will check.

josenk commented 2 years ago

terraform plan --> works terraform apply --> works terraform plan --> tells you it needs to add boot_firmaware. It shouldn't do this...

dohq commented 2 years ago

terraform plan --> works terraform apply --> works terraform plan --> tells you it needs to add boot_firmaware. It shouldn't do this...

oh sorry, OK, I check now...

dohq commented 2 years ago

environment

terrafrom version

Terraform v1.0.9
on linux_amd64

Your version of Terraform is out of date! The latest version
is 1.0.11. You can update by downloading from https://www.terraform.io/downloads.html

target ESXi version

ESXi Version:
6.7.0

ESXi build number:
14320388

Run

vm.tf

(*'-') < cat vm.tf
resource "esxi_guest" "dummy" {
  guest_name = "dummy"

  disk_store    = "datastore1"
  boot_firmware = "efi"
  power         = "off"
  guestos       = "centos7-64"

  network_interfaces {
    virtual_network = "VM Network"
  }
}

terraform plan

(*'-') < terraform plan
╷
│ Warning: Provider development overrides are in effect
│
│ The following provider development overrides are set in the CLI configuration:
│  - josenk/esxi in ..
│
│ The behavior may therefore not match any released version of the provider and applying changes may cause the state to become incompatible with published releases.
╵

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.dummy will be created
  + resource "esxi_guest" "dummy" {
      + boot_disk_size         = (known after apply)
      + boot_disk_type         = "thin"
      + boot_firmware          = "efi"
      + disk_store             = "datastore1"
      + guest_name             = "dummy"
      + guest_shutdown_timeout = (known after apply)
      + guest_startup_timeout  = (known after apply)
      + guestos                = "centos7-64"
      + id                     = (known after apply)
      + ip_address             = (known after apply)
      + memsize                = (known after apply)
      + notes                  = (known after apply)
      + numvcpus               = (known after apply)
      + ovf_properties_timer   = (known after apply)
      + power                  = "off"
      + resource_pool_name     = "/"
      + virthwver              = (known after apply)

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

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

Note: You didn't use the -out option to save this plan, so Terraform can't guarantee to take exactly these actions if you run "terraform apply" now.

terraform apply

(*'-') < terraform apply
╷
│ Warning: Provider development overrides are in effect
│
│ The following provider development overrides are set in the CLI configuration:
│  - josenk/esxi in ..
│
│ The behavior may therefore not match any released version of the provider and applying changes may cause the state to become incompatible with published releases.
╵

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.dummy will be created
  + resource "esxi_guest" "dummy" {
      + boot_disk_size         = (known after apply)
      + boot_disk_type         = "thin"
      + boot_firmware          = "efi"
      + disk_store             = "datastore1"
      + guest_name             = "dummy"
      + guest_shutdown_timeout = (known after apply)
      + guest_startup_timeout  = (known after apply)
      + guestos                = "centos7-64"
      + id                     = (known after apply)
      + ip_address             = (known after apply)
      + memsize                = (known after apply)
      + notes                  = (known after apply)
      + numvcpus               = (known after apply)
      + ovf_properties_timer   = (known after apply)
      + power                  = "off"
      + resource_pool_name     = "/"
      + virthwver              = (known after apply)

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

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

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

esxi_guest.dummy: Creating...
esxi_guest.dummy: Creation complete after 7s [id=2]

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
Time: 0h:00m:09s

terraform plan

(*'-') < terraform plan
╷
│ Warning: Provider development overrides are in effect
│
│ The following provider development overrides are set in the CLI configuration:
│  - josenk/esxi in ..
│
│ The behavior may therefore not match any released version of the provider and applying changes may cause the state to become incompatible with published releases.
╵
esxi_guest.dummy: Refreshing state... [id=2]

No changes. Your infrastructure matches the configuration.

Terraform has compared your real infrastructure against your configuration and found no differences, so no changes are needed.

change bios

(*'-') < sed -i 's/efi/bios/g' vm.tf

(*'-') < terraform plan
╷
│ Warning: Provider development overrides are in effect
│
│ The following provider development overrides are set in the CLI configuration:
│  - josenk/esxi in ..
│
│ The behavior may therefore not match any released version of the provider and applying changes may cause the state to become incompatible with published releases.
╵
esxi_guest.dummy: Refreshing state... [id=2]

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  ~ update in-place

Terraform will perform the following actions:

  # esxi_guest.dummy will be updated in-place
  ~ resource "esxi_guest" "dummy" {
      ~ boot_firmware          = "efi" -> "bios"
        id                     = "2"
        # (12 unchanged attributes hidden)

        # (1 unchanged block hidden)
    }

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

Note: You didn't use the -out option to save this plan, so Terraform can't guarantee to take exactly these actions if you run "terraform apply" now.

terraform apply

(*'-') < terraform apply
╷
│ Warning: Provider development overrides are in effect
│
│ The following provider development overrides are set in the CLI configuration:
│  - josenk/esxi in ..
│
│ The behavior may therefore not match any released version of the provider and applying changes may cause the state to become incompatible with published releases.
╵
esxi_guest.dummy: Refreshing state... [id=2]

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  ~ update in-place

Terraform will perform the following actions:

  # esxi_guest.dummy will be updated in-place
  ~ resource "esxi_guest" "dummy" {
      ~ boot_firmware          = "efi" -> "bios"
        id                     = "2"
        # (12 unchanged attributes hidden)

        # (1 unchanged block hidden)
    }

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

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

esxi_guest.dummy: Modifying... [id=2]
esxi_guest.dummy: Modifications complete after 5s [id=2]

Apply complete! Resources: 0 added, 1 changed, 0 destroyed.
Time: 0h:00m:10s

Re terraform plan

(*'-') < terraform plan
╷
│ Warning: Provider development overrides are in effect
│
│ The following provider development overrides are set in the CLI configuration:
│  - josenk/esxi in ..
│
│ The behavior may therefore not match any released version of the provider and applying changes may cause the state to become incompatible with published releases.
╵
esxi_guest.dummy: Refreshing state... [id=2]

No changes. Your infrastructure matches the configuration.

Terraform has compared your real infrastructure against your configuration and found no differences, so no changes are needed.

I tried to run it manually, but no changes were detected...

josenk commented 2 years ago

How to recreate:

1) Create any generic vmguest, set boot_firmware = "bios". 2) terraform plan --> works 3) terraform apply --> works 4) terraform plan --> tells you it needs to add boot_firmaware. It shouldn't do this...

BTW: I am able to fix this very easily, so no worries... I just wanted to point it out that reading the current state was not complete. This PR and the fix will be included in the next release.

dohq commented 2 years ago

Can you please try to update the latest pull request? I'm aware that guest-read.go has been updated.

https://github.com/dohq/terraform-provider-esxi/blob/d1a436915e406bb8dca86da7b5a84fcab98c30b3/esxi/guest-read.go#L250-L254

I'm not very good at English. I am sorry if I have misrecognized your point.