# Terraform testate not refreshing

**URL:** <https://discuss.hashicorp.com/t/terraform-testate-not-refreshing/22835>\
**Category:** Terraform\
**Tags:** azure\
**Created:** [April 6, 2021, 11:16am UTC](https://discuss.hashicorp.com/t/terraform-testate-not-refreshing/22835 "2021-04-06T11:16:59Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![ElAouane](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/elaouane/32/6825_2.png) [@ElAouane](https://discuss.hashicorp.com/u/ElAouane)\
**Post date:** [April 6, 2021, 11:16am UTC](https://discuss.hashicorp.com/t/terraform-testate-not-refreshing/22835/1 "2021-04-06T11:16:59Z")

</div>

I am experiencing a weird behaviour with terraform. I have been working on an infra. I have a backend state configured to state my state file in a storage account in azure. Until yesterday everything was fine, this morning when I tried to update my infra, the output from `terraform plan` was weird as its trying to create all the resources as new, when I checked my local testate…it was empty.

I tried `terraform pull` and `terraform refresh` but nothing, still same result. I checked my remote state and I have all the resources still declared.

So I went for plan b, copy and paste my remote state into my local project and run terraform once again, but nothing, seems that terraform is ignoring my terraform state on my local and doesn’t wanna pull the remote one.

Any help please?

---

<div class="post-metadata">

**Author:** ![TjeuKayim](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/tjeukayim/32/17769_2.png) [@TjeuKayim](https://discuss.hashicorp.com/u/TjeuKayim)\
**Post date:** [April 6, 2021, 2:05pm UTC](https://discuss.hashicorp.com/t/terraform-testate-not-refreshing/22835/2 "2021-04-06T14:05:58Z")

</div>

Hi,  
Weird that the backend got disconnected in your config.  
If I understand correctly, the state is empty while it should not be empty and `terraform state list` returns nothing.  
How did you configure the backend in the first place, hard coded in `.tf` files or with `terraform init -backend-config=...`?  
Depending on how you configured it, you can try to reconfigure like this:  
`terraform init -reconfigure`

---

<div class="post-metadata">

**Author:** ![ElAouane](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/elaouane/32/6825_2.png) [@ElAouane](https://discuss.hashicorp.com/u/ElAouane)\
**Post date:** [April 6, 2021, 2:08pm UTC](https://discuss.hashicorp.com/t/terraform-testate-not-refreshing/22835/3 "2021-04-06T14:08:55Z")

</div>

This is how I configured my backend

```auto
terraform {
  backend "azurerm" {
    resource_group_name = "<resource-group-name>"
    storage_account_name = "<storage-name>"
    container_name = "<container-name>"
    key = "terraform.tfstate"
  }
}

```

When I run `terraform state list` the only thing that prints out, are my `output` everything else is ignored.

Is there any overriding risk if I run `terraform init -reconfigure`?

---

<div class="post-metadata">

**Author:** ![TjeuKayim](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/tjeukayim/32/17769_2.png) [@TjeuKayim](https://discuss.hashicorp.com/u/TjeuKayim)\
**Post date:** [April 6, 2021, 2:12pm UTC](https://discuss.hashicorp.com/t/terraform-testate-not-refreshing/22835/4 "2021-04-06T14:12:16Z")

</div>

The reconfigure command won’t overwrite the remote state, it might clear the local state but that is empty in your case anyways.  
But it is a good idea to create backups of your remote state.

You can get the help info like this:

```auto
terraform init --help
Usage: terraform init [options] [DIR]
(...)
  -reconfigure Reconfigure the backend, ignoring any saved
                       configuration.

```

Looking at your backend block, it seems like you already specified everything in that .tf file. The reconfigure command might do nothing then, I’m not entirely sure. If you didn’t hard code for example the container\_name and key, it promts you for that when running reconfigure.

---

<div class="post-metadata">

**Author:** ![ElAouane](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/elaouane/32/6825_2.png) [@ElAouane](https://discuss.hashicorp.com/u/ElAouane)\
**Post date:** [April 6, 2021, 2:18pm UTC](https://discuss.hashicorp.com/t/terraform-testate-not-refreshing/22835/5 "2021-04-06T14:18:43Z")

</div>

I tried to use the reconfigure too but nothing. I even tried to copy and paste my remote state into my local, but terraform just ignores my local tfstate completely.

---

<div class="post-metadata">

**Author:** ![TjeuKayim](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/tjeukayim/32/17769_2.png) [@TjeuKayim](https://discuss.hashicorp.com/u/TjeuKayim)\
**Post date:** [April 6, 2021, 2:24pm UTC](https://discuss.hashicorp.com/t/terraform-testate-not-refreshing/22835/6 "2021-04-06T14:24:26Z")

</div>

The local tfstate is ignored because you specified a remote state, that is expected. If you want to use that local state, you need to remove / comment out that backend block.

Any clue what change caused your configuration to stop working? Did you upgrade the terraform version or modified some configuration?

Another thing you could try is making a backup of the working directory (containing your Terraform root module) and remove the `.terraform` directory and initialize again.

---

<div class="post-metadata">

**Author:** ![ElAouane](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/elaouane/32/6825_2.png) [@ElAouane](https://discuss.hashicorp.com/u/ElAouane)\
**Post date:** [April 6, 2021, 2:26pm UTC](https://discuss.hashicorp.com/t/terraform-testate-not-refreshing/22835/7 "2021-04-06T14:26:16Z")

</div>

The only thing I have done this morning, was to upgrade Lua rock… which I don’t believe has anything to do with terraform.

I tried to remove .terraform and terraform.lock and run `init` didn’t change anything.

---

<div class="post-metadata">

**Author:** ![TjeuKayim](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/tjeukayim/32/17769_2.png) [@TjeuKayim](https://discuss.hashicorp.com/u/TjeuKayim)\
**Post date:** [April 6, 2021, 2:29pm UTC](https://discuss.hashicorp.com/t/terraform-testate-not-refreshing/22835/8 "2021-04-06T14:29:37Z")

</div>

Maybe the connection to Azure fails without reporting an error message.  
You could try enabling trace logs (as explained here [https://www.terraform.io/docs/internals/debugging.html](https://www.terraform.io/docs/internals/debugging.html)) and run `terraform state list` again, then inspect the log file.

---

<div class="post-metadata">

**Author:** ![ElAouane](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/elaouane/32/6825_2.png) [@ElAouane](https://discuss.hashicorp.com/u/ElAouane)\
**Post date:** [April 6, 2021, 2:41pm UTC](https://discuss.hashicorp.com/t/terraform-testate-not-refreshing/22835/9 "2021-04-06T14:41:11Z")

</div>

Done, the only thing that I can find that is strange is this:

```auto
2021/04/06 15:35:48 [TRACE] Meta.Backend: BackendOpts.Config not set, so using settings loaded from backend.tf:2,3-20
2021/04/06 15:35:48 [TRACE] Meta.Backend: using already-initialized, unchanged "azurerm" backend configuration
Meta.Backend: instantiated backend of type *azure.Backend

```

But the response from my backend is `200 OK`

---

<div class="post-metadata">

**Author:** ![TjeuKayim](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/tjeukayim/32/17769_2.png) [@TjeuKayim](https://discuss.hashicorp.com/u/TjeuKayim)\
**Post date:** [April 6, 2021, 2:45pm UTC](https://discuss.hashicorp.com/t/terraform-testate-not-refreshing/22835/10 "2021-04-06T14:45:34Z")

</div>

Hm, the response is 200 OK, but it doesn’t return the blob that you expected. Are you sure that the container and blob key are the same?  
You said you checked the remote state.

Sorry, I’m out of ideas then.

---

<div class="post-metadata">

**Author:** ![ElAouane](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/elaouane/32/6825_2.png) [@ElAouane](https://discuss.hashicorp.com/u/ElAouane)\
**Post date:** [April 6, 2021, 2:50pm UTC](https://discuss.hashicorp.com/t/terraform-testate-not-refreshing/22835/11 "2021-04-06T14:50:11Z")

</div>

So I tried to use terraform to create new resources and spin them up. Terraform behaved correctly. Created the resource, pushed the tfstate to my storage account. After terraform completion, I run a `terraform plan` and it worked, printing that the infrastructure is up to date.  
And I am using the same backend configuration (of course changing the name of the blob).

I really have no idea what is happening.

---

<div class="post-metadata">

**Author:** ![TjeuKayim](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/tjeukayim/32/17769_2.png) [@TjeuKayim](https://discuss.hashicorp.com/u/TjeuKayim)\
**Post date:** [April 6, 2021, 2:53pm UTC](https://discuss.hashicorp.com/t/terraform-testate-not-refreshing/22835/12 "2021-04-06T14:53:35Z")

</div>

Good to hear that your problem is solved. I can imagine it’s unsatisfying that you still have no clue what was going wrong.  
Have a nice day!

---

<div class="post-metadata">

**Author:** ![ElAouane](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/elaouane/32/6825_2.png) [@ElAouane](https://discuss.hashicorp.com/u/ElAouane)\
**Post date:** [April 6, 2021, 2:55pm UTC](https://discuss.hashicorp.com/t/terraform-testate-not-refreshing/22835/13 "2021-04-06T14:55:28Z")

</div>

Sorry mate is not solved. It works if I create a new project, but still the old one don’t work. But thank you so much for your help and time. I really appreciate it 🙂

---

<div class="post-metadata">

**Author:** ![TjeuKayim](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/tjeukayim/32/17769_2.png) [@TjeuKayim](https://discuss.hashicorp.com/u/TjeuKayim)\
**Post date:** [April 6, 2021, 2:57pm UTC](https://discuss.hashicorp.com/t/terraform-testate-not-refreshing/22835/14 "2021-04-06T14:57:47Z")

</div>

Oh, I read it another time, so you essentially created a copy now of the environment, with another key for the remote state, and the state management for that second environment works correctly. But your original environment state is still not working.

---

<div class="post-metadata">

**Author:** ![ElAouane](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/elaouane/32/6825_2.png) [@ElAouane](https://discuss.hashicorp.com/u/ElAouane)\
**Post date:** [April 6, 2021, 3:00pm UTC](https://discuss.hashicorp.com/t/terraform-testate-not-refreshing/22835/15 "2021-04-06T15:00:04Z")

</div>

Yep, I had to spin up another infra for a project. I created a whole new folder with all the resources and configuration. Runned:  
`terraform init`  
`terraform plan`  
`terraform apply`

And everything when smooth. It did created 7 resources and saved the tfstate to my newly created backend.

But concerned to the other 80 projects I have, nothing…still don’t work

---

<div class="post-metadata">

**Author:** ![TjeuKayim](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/tjeukayim/32/17769_2.png) [@TjeuKayim](https://discuss.hashicorp.com/u/TjeuKayim)\
**Post date:** [April 6, 2021, 3:06pm UTC](https://discuss.hashicorp.com/t/terraform-testate-not-refreshing/22835/16 "2021-04-06T15:06:39Z")

</div>

So, the old state files behave differently than new ones, maybe something with metadata? It almost sounds like a change from Azure Blob Storage, but I don’t expect that to be the case.  
What happens if you copy the tfstate blob to another blob with a different key and use that in the backend config?

---

<div class="post-metadata">

**Author:** ![ElAouane](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/elaouane/32/6825_2.png) [@ElAouane](https://discuss.hashicorp.com/u/ElAouane)\
**Post date:** [April 6, 2021, 3:18pm UTC](https://discuss.hashicorp.com/t/terraform-testate-not-refreshing/22835/17 "2021-04-06T15:18:04Z")

</div>

Yes same behaviour. I noticed that even if I copy and paste my remote state into my local, and than run a `plan` terraform just destroys all the content in my local terraform.tfstate. Is this a normal behaviour?

---

<div class="post-metadata">

**Author:** ![CaioBauab](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/caiobauab/32/43348_2.png) [@CaioBauab](https://discuss.hashicorp.com/u/CaioBauab)\
**Post date:** [October 7, 2024, 11:51pm UTC](https://discuss.hashicorp.com/t/terraform-testate-not-refreshing/22835/18 "2024-10-07T23:51:03Z")

</div>

Thank you so much. This solved my issue!

---

<div class="post-metadata">

**Author:** ![wyardley](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/wyardley/32/21845_2.png) [@wyardley](https://discuss.hashicorp.com/u/wyardley)\
**Post date:** [October 8, 2024, 10:57pm UTC](https://discuss.hashicorp.com/t/terraform-testate-not-refreshing/22835/19 "2024-10-08T22:57:29Z")

</div>

Side note: while there are some considerations in the case where some sensitive data gets accidentally included in the state file, you may want to consider making sure versioning and / or soft delete are enabled for the bucket you’re using for remote state.

This will give you some additional options in the case where something gets wiped out or corrupted, even if you don’t have a local copy.
