netscaler / terraform-provider-netscalersdx

Manage (Configure) SDX via this terraform provider
https://registry.terraform.io/providers/netscaler/netscalersdx/latest/docs
1 stars 3 forks source link

SDX VPX provisioning resource returning error if the resource in the state file is missing rather than re-deploying it #10

Open ksashokumar opened 1 year ago

ksashokumar commented 1 year ago

If a resource deployed using SDX VPX provisioning resource gets deleted in the SDX, the provider is not creating the resource again when we do terraform apply. It responds with the following error.

Plan: 0 to add, 1 to change, 0 to destroy. ╷ │ Error: failed: 404 Not Found ({ "errorcode": 10011, "message": "Resource does not exist", "severity": "ERROR" }) │ │ with module.dut_provision_sdx2.citrixsdx_provision_vpx.dut, │ on ../modules/dut_sdx/main.tf line 1, in resource "citrixsdx_provision_vpx" "dut": │ 1: resource "citrixsdx_provision_vpx" "dut" { │ ╵

Steps to reproduce:

  1. Provision a VM in the SDX using SDX provider.
  2. Delete the VM directly in the SDX GUI.
  3. Now re-run the terraform apply command.
  4. Typically, the resource should re deploy the VM as per in the state file but it is throwing the error, "Resource does not exists".
  5. The resource code returns the error when the resource doesn't exists rather than setting it to NULL.
HS1542 commented 1 year ago

I would say this is by design and exactly what you would expect.

If you provision something through terraform, then you need to de-provision it aswell, by running terraform destroy or removing/commenting out that resource in your configuration. As long as your state file knowns that a resource should exist, it will fail when it is unable to check the running state of that resource.

If you manually delete something, then you need to remove that resource from the state file, for instance by running terraform state rm <resource.name>