# Resources removed from tfstate after upgrade of my provider

**URL:** <https://discuss.hashicorp.com/t/resources-removed-from-tfstate-after-upgrade-of-my-provider/10783>\
**Category:** Plugin Development\
**Created:** [June 29, 2020, 7:53pm UTC](https://discuss.hashicorp.com/t/resources-removed-from-tfstate-after-upgrade-of-my-provider/10783 "2020-06-29T19:53:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![smutel](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/smutel/32/2687_2.png) [@smutel](https://discuss.hashicorp.com/u/smutel)\
**Post date:** [June 29, 2020, 7:53pm UTC](https://discuss.hashicorp.com/t/resources-removed-from-tfstate-after-upgrade-of-my-provider/10783/1 "2020-06-29T19:53:21Z")

</div>

Hello,

I am writing my own terraform provider for netbox: [https://github.com/smutel/terraform-provider-netbox](https://github.com/smutel/terraform-provider-netbox).

I created some resources with the version 0.1.0.  
Now I released a new version 0.2.1.

For now I didn’t change any tf code. When I execute a plan with the same code 4 resources need to be created instead of zero.

I have also there errors in the log:

```auto
2020/06/29 21:39:45 [DEBUG] Resource instance state not found for node "module.tenant_infra-test_netbox_tenant.netbox_tenancy_tenant.tenant", instance module.tenant_infra-test_netbox_tenant.netbox_tenancy_tenant.tenant
2020/06/29 21:39:45 [DEBUG] Resource instance state not found for node "module.tenant_infra_netbox_tenant.netbox_tenancy_tenant.tenant", instance module.tenant_infra_netbox_tenant.netbox_tenancy_tenant.tenant
2020/06/29 21:39:45 [DEBUG] Resource instance state not found for node "module.tenant_infra-test_netbox_tenant.netbox_ipam_prefix.prefix", instance module.tenant_infra-test_netbox_tenant.netbox_ipam_prefix.prefix
2020/06/29 21:39:45 [DEBUG] Resource instance state not found for node "module.tenant_infra_netbox_tenant.netbox_ipam_prefix.prefix", instance module.tenant_infra_netbox_tenant.netbox_ipam_prefix.prefix

```

What I did wrong in my provider ?  
Is-it related to the consul backend I am using ?

Thanks.

---

<div class="post-metadata">

**Author:** ![paddy](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/paddy/32/4484_2.png) [@paddy](https://discuss.hashicorp.com/u/paddy)\
**Post date:** [July 9, 2020, 8:09pm UTC](https://discuss.hashicorp.com/t/resources-removed-from-tfstate-after-upgrade-of-my-provider/10783/2 "2020-07-09T20:09:00Z")

</div>

Either something happened to your state file and you lost those four resources, or something happened in the provider to remove them from your state file silently. Without more information, it’s hard to tell.

---

<div class="post-metadata">

**Author:** ![smutel](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/smutel/32/2687_2.png) [@smutel](https://discuss.hashicorp.com/u/smutel)\
**Post date:** [July 10, 2020, 6:33am UTC](https://discuss.hashicorp.com/t/resources-removed-from-tfstate-after-upgrade-of-my-provider/10783/3 "2020-07-10T06:33:59Z")

</div>

I found the issue. For some reason due to the targeted API, the exists function and read function of my provider didn’t found anymore the resources present in the tfstate.

So I assume that terraform remove items in the tfstate if the provider does not found them, right ?

---

<div class="post-metadata">

**Author:** ![paddy](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/paddy/32/4484_2.png) [@paddy](https://discuss.hashicorp.com/u/paddy)\
**Post date:** [July 10, 2020, 4:30pm UTC](https://discuss.hashicorp.com/t/resources-removed-from-tfstate-after-upgrade-of-my-provider/10783/4 "2020-07-10T16:30:44Z")

</div>

The exists function will automatically. The read function will only if you call `ResourceData.SetId("")`.
