Terraform apply the destroy plan

Team,

Am using the terraform plan output to apply/destroy the infra. While using the destroy with the plan output, it’s throwing an error due to the output.conf. Is there a way to avoid executing output.tf when applying the destroy plan output?

FYI: output.tf is working fine with the plan and apply and throwing error with the apply with the destroy.out.

Work flow:

terraform plan -destroy --out=destroy.plan

> > Solicit Approval <<

terraform apply destroy.plan --auto-approve

Error:

+ terraform apply -auto-approve destroy.tfplan
local_file.render-vars: Destroying... [id=d3c23a19203e951f3c5b487bea62f35ae9689b40]
local_file.render-inventory: Destroying... [id=975618cb35e11872b89e50e8586fcc1b7cdbbe3b]
local_file.render-inventory: Destruction complete after 0s
local_file.render-vars: Destruction complete after 0s
module.server_vm.vsphere_virtual_machine.generic_vm[0]: Destroying... [id=42198817-56e4-f954-1f6b-486cf1fd434a]
module.client_vm.vsphere_virtual_machine.generic_vm[0]: Destroying... [id=42199433-7acb-ce1f-cb80-2e18ef8e6737]
module.client_vm.vsphere_virtual_machine.generic_vm[0]: Destruction complete after 9s
module.server_vm.vsphere_virtual_machine.generic_vm[0]: Destruction complete after 9s

Error: Error in function call

  on .terraform/modules/client_vm/output.tf line 4, in output "server_details":
   4:   value = zipmap(
   5: 
   6: 
   7: 
    |----------------
    | var.generic_vm_type is tuple with 1 element
    | vsphere_virtual_machine.generic_vm is empty tuple

Call to function "zipmap" failed: number of keys (1) does not match number of
values (0).


Error: Error in function call

  on .terraform/modules/server_vm/output.tf line 4, in output "server_details":
   4:   value = zipmap(
   5: 
   6: 
   7: 
    |----------------
    | var.generic_vm_type is tuple with 1 element
    | vsphere_virtual_machine.generic_vm is empty tuple

To add more info for my question. When i use plan output to do terraform apply which is working perfect.

When I use terraform plan -destroy -out=destroy.tfplan```` and terraform apply destroy.tfplan``` it’s throwing the below-mentioned error.

The output conf which am using in the module and calling code is printed below.

In module:

output "server_details" {
  description = "This will print the type of the server and the ipadress(Based on the selection in the calling code)"
  value = zipmap(
    var.generic_vm_type.*.name,
    vsphere_virtual_machine.generic_vm.*.default_ip_address
  )
}

In calling code:

output "server_details" {
  description = "This will print the server type along with the ip"
  value       = module.server_vm.server_details
} 

Error: Error in function call

  on .terraform/modules/client_vm/output.tf line 4, in output "server_details":
   4:   value = zipmap(
   5:     var.generic_vm_type.*.name,
   6:     vsphere_virtual_machine.generic_vm.*.default_ip_address
   7:   )
    |----------------
    | var.generic_vm_type is tuple with 1 element
    | vsphere_virtual_machine.generic_vm is empty tuple

Call to function "zipmap" failed: number of keys (1) does not match number of
values (0).

That’s helped. Thank you very much