infobloxopen / terraform-provider-infoblox

Infoblox NIOS Terraform Provider
https://github.com/infobloxopen/terraform-provider-infoblox
Mozilla Public License 2.0
68 stars 77 forks source link

Redeploy of deleted networks or network containers fails #320

Closed isivertsen closed 5 months ago

isivertsen commented 11 months ago

If a network or network container object in IPAM is deleted in GUI (by accident or mistake), i expect the object to be reprovisioned at the next terraform apply (based on terraform state information) This does not happen, but instead the terraform plan will fail because it cannot find the object in IPAM

Error message: _Planning failed. Terraform encountered an error while generating this plan. ╷ │ Error: getting Network block from network view (skypro_dev) failed : WAPI request error: 404('404 Not Found') │ Contents: │ { "Error": "AdmConDataNotFoundError: Reference network/ZG5zLm5ldHdvcmskMTAuMS4zLjAvMjQvODU:10.1.3.0/24/skypro_dev not found", │ "code": "Client.Ibap.Data.NotFound", │ "text": "Reference network/ZG5zLm5ldHdvcmskMTAuMS4zLjAvMjQvODU:10.1.3.0/24/skyprodev not found" │ }

Is this by design? Normal behavior for Terraform should be to reastablish the object in IPAM based on terraform state. Tested with infoblox_ipv4_network_container and infoblox_ipv4_network with same result.

JkhatriInfobox commented 8 months ago

Hi @isivertsen, I had a look into the plugin code, this is the expected behaviour as per the design.

As resource is accidentally deleted from the UI, terraform is not aware with the change. So with the terraform apply or terraform plan it tries to refresh the data based on reference saved in state file. The Base WAPI will raise an error when user tries to search with the non exit resources Error: getting Network block from network view (test) failed : WAPI request error: 404('404 Not Found')

To fix this you can remove the resource from the state file using terraform state rm <resource.object>. So it no longer contains the invalid reference and on re-apply it will re-create the resource with the variables or values defined in to the resource block.

Assuming this will solve your issue. Let us know more if anything for the same.

isivertsen commented 8 months ago

@JkhatriInfobox

Im surprised that this is considered as expected behaviour. All other Terraform Providers I am familiar with, will rebuild the applied infrastructure if something has been deleted or destroyed (Azure / AWS /ACI ). Being able to redeploy lost configuration by reapplying the code, is a basic logic of IAC.

I am aware of (and have taken advantage of) the option to manually edit the Terraform State, but it is not an acceptable approach in long term. In the situation of a major deviation from IPAM and Code, it will be a large and complex job to make the required and correct manual changes in Terraform State.

Requests that it be reassessed whether there is a weakness in the Terraform Provider that should be improved.

SanjeevManurkar commented 8 months ago

Hello @isivertsen , This is the current design of our plugin. We have taken your feedback into consideration and will add this to our backlog for future enhancement.

roald007 commented 7 months ago

Hi.

It seems that a very similar problem has been solved in a previous issue some years ago: https://github.com/prudhvitella/terraform-provider-infoblox/issues/19

Could this be the key in this matter as well?

JkhatriInfobox commented 5 months ago

Hi @isivertsen and @roald007, we fixed this issue with v2.6.0

Hence closing the issue, fill free to re-open if issue persist for you.