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

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

Open
dmicheneau opened this issue Feb 28, 2023 · 12 comments
Open
Labels
can't reproduce The issue cannot be reproduced

Comments

@dmicheneau
Copy link

dmicheneau commented Feb 28, 2023

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
Copy link
Collaborator

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
Copy link
Collaborator

@dmicheneau why do you need another provider?

@dmicheneau
Copy link
Author

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
Copy link
Collaborator

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
Copy link
Author

dmicheneau commented Mar 3, 2023

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

@fmaitrot
Copy link

fmaitrot commented Aug 1, 2023

Hello :) Any update about this issue?

@dataclouder
Copy link
Contributor

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.

@dataclouder dataclouder added can't reproduce The issue cannot be reproduced and removed bug Something isn't working labels Aug 1, 2023
@valentin-dubreuil
Copy link

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
Copy link
Contributor

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

@valentin-dubreuil
Copy link

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

@dataclouder
Copy link
Contributor

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
can't reproduce The issue cannot be reproduced
Projects
None yet
6 participants