terraform-provider-vcd icon indicating copy to clipboard operation
terraform-provider-vcd copied to clipboard

Altering a vapp recreates it and leaves associated VMs dangling.

Open cheald opened this issue 5 years ago • 4 comments

Given a resource definition like this:

{
    "vcd_vapp_vm": {
      "myvm": {
        ...
        "depends_on": [
          "vcd_vapp.app_main"
        ],
        "network": [
          {
            "type": "org",
            "name": "mynetwork",
            "ip_allocation_mode": "POOL",
            "is_primary": true
          }
        ]
      }
   },
    "vcd_vapp": {
      "app_main": {
        "name": "app_main",
        "network_name": "mynetwork"
      }
    }
}

We get a deprecation warning:

Warning: "network_name": [DEPRECATED] Creation of vApp and an implicit single VM in the same structure is deprecated. Use vcd_vapp_vm.network instead

Removing the network_name from the vapp then triggers a recreate of the vapp:

  # vcd_vapp.app_main must be replaced
-/+ resource "vcd_vapp" "app_main" {
      - network_name     = "mynetwork" -> null # forces replacement
    }

This deletes the vApp, which deletes the VMs from the vCD, but doesn't mark them as deleted in Terraform. When you then attempt to refresh the terraform state, it can't find the VMs and bombs out:

$ terraform apply
...
vcd_vapp_vm.myvm: Refreshing state... [id=myvm]

Error: error getting VM : &errors.errorString{s:"[ENF] entity not found"}

Terraform Version

# terraform -v
Terraform v0.12.9
+ provider.dns v2.1.1
+ provider.template v2.1.2
+ provider.vcd (unversioned)

Affected Resource(s)

  • vcd_vapp
  • vcd_vapp_vm

Expected Behavior

If the vapp MUST be recreated, Terraform should properly plan to destroy the contained VMs, and should remove those VMs from internal state.

Furthermore, the provider probably shouldn't crash if a VM goes missing; it should notice that the VM is missing and should recreate it.

Actual Behavior

Terraform did not remove the VM that depends on the removed vapp, and cannot refresh or apply afterwards due to the missing VM.

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

  1. Create a vapp that contains a VM, and ensure that network_name is set on the vapp
  2. terraform apply
  3. Remove the network_name from the vapp
  4. terraform apply
  5. terraform refresh

cheald avatar Oct 04 '19 19:10 cheald

Any progress on this one? Looks like I've just hit something similar

tlawrence avatar Mar 30 '20 13:03 tlawrence

Hi @tlawrence, There is work in progress to fix the read. Data source errors are already unified however VM reads are still pending. It has not yet reached PR state so far.

Didainius avatar Mar 31 '20 06:03 Didainius

Just to add. For the time being you could manually remove VMs from state with terraform state rm vcd_vapp_vm.__name__ command until this is fixed properly.

Didainius avatar Mar 31 '20 06:03 Didainius

thank you

tlawrence avatar Apr 02 '20 07:04 tlawrence

#925 should have finalized cleaning up all issues of that type in this provider

Didainius avatar Nov 28 '22 12:11 Didainius