vmware / go-vcloud-director

Golang SDK for VMware Cloud Director
Other
76 stars 79 forks source link

Option eject_force do not eject media without an human intervention #552

Open dmicheneau opened 1 year ago

dmicheneau commented 1 year ago

Describe the bug

When we try to destroy the resource vcd_inserted_media we need to do a human intervention to answer Yes to force the ejection. But on Terraform side the intervention seems to be ok

vcd_inserted_media.example: Refreshing state... [id=vapp_test3_TestRomain_debian-9.9.0-amd64-netinst.iso]

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

Terraform will perform the following actions:

  # vcd_inserted_media.example will be destroyed
  - resource "vcd_inserted_media" "example" {
      - catalog     = "my-catalog_romain" -> null
      - eject_force = true -> null
      - id          = "vapp_test3_TestRomain_debian-9.9.0-amd64-netinst.iso" -> null
      - name        = "debian-9.9.0-amd64-netinst.iso" -> null
      - vapp_name   = "vapp_test3" -> null
      - vm_name     = "TestRomain" -> null
    }

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

Do you really want to destroy all resources?
  Terraform will destroy all your managed infrastructure, as shown above.
  There is no undo. Only 'yes' will be accepted to confirm.

  Enter a value: yes

vcd_inserted_media.example: Destroying... [id=vapp_test3_TestRomain_debian-9.9.0-amd64-netinst.iso]
vcd_inserted_media.example: Still destroying... [id=vapp_test3_TestRomain_debian-9.9.0-amd64-netinst.iso, 10s elapsed]
vcd_inserted_media.example: Destruction complete after 11s

Destroy complete! Resources: 1 destroyed.

However side UI vCloud Director, you need to make an action:

image

And give a answer normally manage by the option eject_force.

Reproduction steps

  1. Create a VM and power on VM
  2. Make a terraform apply with resource "vcd_inserted_media" "example"
  3. Destroy terraform resource "vcd_inserted_media"
  4. check result on vCloud Director UI

Expected behavior

The attribute eject_force (to true by default) bypass the human intervention.

Additional context

terraform version
Terraform v1.3.9
on linux_amd64
+ provider registry.terraform.io/vmware/vcd v3.8.2

On Api vcloud director 37.0

Didainius commented 1 year ago

Hello @dmicheneau , I did not really grasp the issue - does the vcd_inserted_media not handle eject_force = true for you or what exactly is the request?

If you need to handle this operation in SDK, you could check how it is done in Terraform provider for VCD - https://github.com/vmware/terraform-provider-vcd/blob/main/vcd/resource_vcd_inserted_media.go#L136-L144

BTW. I see this linked issue which got me confused.

The first impression is that the provider cloudavenue is the same VCD provider (using go-vcloud-director SDK), is it so? What is the reason for building a separate provider? Does it have any specifics?

lvirbalas commented 1 year ago

@dmicheneau why do you need another provider?

dmicheneau commented 1 year ago

Cloudavenue is a light and simplified version of VCD provider for our client. It's rebuilt with the framework terraform and not the sdk. In the example i give, the problem exist with the vcd provider. For the both problem come from api vcloud director.

Didainius commented 1 year ago

In the example i give, the problem exist with the vcd provider. For the both problem come from api vcloud director.

Could you elaborate a bit? Does the eject_force not work in vcd_inserted_media for you?

dmicheneau commented 1 year ago

Yes, It's not working with resource vcd_inserted_media and eject_force to true, you can see in example step describe above.

fmaitrot commented 11 months ago

Hello :) Any update about this issue?

dataclouder commented 11 months ago

I can't reproduce the issue. Here is what I did

resource "vcd_network_routed" "TestAccVcdVAppVmNetForInsert" {
  name         = "TestAccVcdVAppVmNetForInsert"
  org          = "datacloud"
  vdc          = "nsxt-vdc-datacloud"
  edge_gateway = "nsxt-gw-datacloud"
  gateway      = "10.10.102.1"

  static_ip_pool {
    start_address = "10.10.102.2"
    end_address   = "10.10.102.254"
  }
}

resource "vcd_vapp" "TestAccVcdVAppForInsert" {
  name       = "TestAccVcdVAppForInsert"
  org        = "datacloud"
  vdc        = "nsxt-vdc-datacloud"
}

resource "vcd_vapp_org_network" "vappNetwork1" {
  org                = "datacloud"
  vdc                = "nsxt-vdc-datacloud"
  vapp_name          = vcd_vapp.TestAccVcdVAppForInsert.name
  org_network_name   = vcd_network_routed.TestAccVcdVAppVmNetForInsert.name 
}

resource "vcd_vapp_vm" "TestAccVcdVAppVmForInsert" {
  org           = "datacloud"
  vdc           = "nsxt-vdc-datacloud"
  vapp_name     = vcd_vapp.TestAccVcdVAppForInsert.name
  name          = "TestAccVcdVAppVmForInsert"
  catalog_name  = "cat-datacloud"
  template_name = "photon-hw11"
  memory        = 1024
  cpus          = 1
  power_on      = "false"
  network {
    type               = "org"
    name               = vcd_vapp_org_network.vappNetwork1.org_network_name
    ip_allocation_mode = "POOL"
  }
}

resource "vcd_catalog_media" "TestAccVcdCatalogMediaBasicForInsert" {
  org     = "datacloud"
  catalog = "cat-datacloud-nsxt-backed"
  name    = "TestAccVcdCatalogMediaBasicForInsert"

  description          = "TestAccVcdCatalogMediaBasicDescriptionForInsert"
  media_path           = "../terraform-provider-vcd/test-resources/test.iso"
  upload_piece_size    = 5
  show_upload_progress = "true"
}

resource "vcd_inserted_media" "TestAccVcdMediaInsertBasic" {
  org     = "datacloud"
  vdc     = "nsxt-vdc-datacloud"
  catalog = "cat-datacloud-nsxt-backed"
  name    = "TestAccVcdCatalogMediaBasicForInsert"

  vapp_name  = vcd_vapp.TestAccVcdVAppForInsert.name
  vm_name    = vcd_vapp_vm.TestAccVcdVAppVmForInsert.name
  depends_on = [vcd_vapp_vm.TestAccVcdVAppVmForInsert, vcd_catalog_media.TestAccVcdCatalogMediaBasicForInsert]

  eject_force = "true"
}

After applying all and checking that the inserted media was in the VM as a "CD", I destroyed the inserted media resource

terraform destroy -target=vcd_inserted_media.TestAccVcdMediaInsertBasic
Do you really want to destroy all resources?
  Terraform will destroy all your managed infrastructure, as shown above.
  There is no undo. Only 'yes' will be accepted to confirm.

  Enter a value: yes

vcd_inserted_media.TestAccVcdMediaInsertBasic: Destroying... [id=TestAccVcdVAppForInsert_TestAccVcdVAppVmForInsert_TestAccVcdCatalogMediaBasicForInsert]
vcd_inserted_media.TestAccVcdMediaInsertBasic: Destruction complete after 10s

Destroy complete! Resources: 1 destroyed.

The inserted media was removed from the VM, and I didn't see any waiting tasks in the UI.

valentin-dubreuil commented 11 months ago

We try to recreate the bug on cloudavenue, with provider vcd 3.10.0 and the version of the vcd api on cloudavenue is 37.1.

resource "vcd_inserted_media" "TestAccVcdMediaInsertBasic" {
  org     = "XXXX"
  vdc     = "XXXX"
  catalog = "XXXXX"
  name    = "XXXXXX"

  vapp_name  = "XXXXX"
  vm_name    = "XXXXX"
  eject_force = true
}

We create the ressource then when we try to delete it on the UI, there is a task still waiting for an human interaction We searched what is respond by the api, it seems that the status of the task is queued then running then exceptedAction When we are searching on the code of vcloud director

https://github.com/vmware/go-vcloud-director/blob/main/govcd/ejecttask.go#L53-59

There is an issue with theses lines which conduct to a manual action at the end.

dataclouder commented 11 months ago

If you can't reproduce the issue in terraform-provider-vcd, there is little we can do.

valentin-dubreuil commented 11 months ago

i use the terraform-provider-vcd in version 3.10 to do this test

dataclouder commented 11 months ago

Did you try using the script I used above? If not, please provide a complete script that can reproduce the case. And if it does, please add the logs that show the operation being performed.

valentin-dubreuil commented 11 months ago
resource "vcd_inserted_media" "TestAccVcdMediaInsertBasic" {
  org     = "XXXX"
  vdc     = "XXXX"
  catalog = "XXXXX"
  name    = "XXXXXX"

  vapp_name  = "XXXXX"
  vm_name    = "XXXXX"
  eject_force = true
}

i create and delete this ressource arround 40 times and it succeed to delete it without interaction on UI 6 times. Could you try to play ur scripts multiple times in a row to see if the bug is happening