terraform icon indicating copy to clipboard operation
terraform copied to clipboard

Not able to refresh state for existing aw resource

Open novtor opened this issue 4 years ago • 13 comments

Terraform v0.15.4 on darwin_amd64

  • provider registry.terraform.io/hashicorp/aws v3.47.0
  • provider registry.terraform.io/hashicorp/template v2.2.0

I am trying to transfer the state from one git repo to another one. So in the old one I did terraform st rm ADDRESS which was successful

When trying to refresh the state in the target repository I have the following issue: terraform plan -refresh-only ╷ │ Error: Invalid refresh-only plan │ │ Terraform generated planned resource changes in a refresh-only plan. This is a bug in Terraform.

here is a link with logs

novtor avatar Jun 30 '21 17:06 novtor

Hi @novtor! Thanks for reporting this.

The behavior you described here seems similar to another bug we fixed in a later version of Terraform than the one you are currently using. Could you try again with the latest Terraform v1.0.x release and see if you get a better result?

(Note that Terraform v1.0.x is the continuation of v0.15.x so in spite of the numbering change it is effectively only a minor release update compared to your current v0.15.4, with no intentional breaking changes.)

apparentlymart avatar Jun 30 '21 20:06 apparentlymart

thank you for your reply, @apparentlymart . I upgraded to Terraform v1.0.1 but still have the same issue

novtor avatar Jul 01 '21 06:07 novtor

Thanks for confirming, @novtor!

Unfortunately when I tried to access the logs link you included in your comment I got a 404 error. Have you deleted the gist that you shared? :thinking:

Hopefully the logs will be enough to understand what happened here but we might well need to see your configuration in order to construct a reproduction case so we can debug locally, and so if you could include that too that will hopefully avoid another round-trip if we find that the logs haven't captured enough detail. Thanks!

apparentlymart avatar Jul 01 '21 18:07 apparentlymart

I am working with the azurerm provider. I am aware of it happening in terraform versions 1.0.0 and 1.0.1. And azurerm provider since the last version 1 of terraform came out.

I have tried the following possibilities to refresh the tfstate and none of them work:

  • terraform refresh
  • terraform plan
  • terraform plan -refresh-only
  • terraform apply

gareda avatar Jul 02 '21 17:07 gareda

I also ran into this today with an aws_elasticache_cluster that had been deleted outside of TF. Workaround is to use terraform state rm <item>.

Tested with latest modules from aws and TF 1.0.3

tomharrisonjr avatar Jul 29 '21 00:07 tomharrisonjr

I am having the same problem on Terraform 1.0.3

iaminov avatar Aug 02 '21 19:08 iaminov

@apparentlymart I think this bug is a larger issue than is being realized. I do not think Terraform is acting properly when the tfstate file is empty (e.g. in a new workspace). When I try to do refresh-only I get the referenced error message ("Terraform generated planned resource changes in a refresh-only plan. This is a bug in Terraform."). HOWEVER, it appears that even if a regular terraform apply is done, the state is not refreshing correctly. Most notably, I get errors that IAM roles already exist and therefore cannot be created, and some infrastructure is duplicated. I am on the latest version of Terraform (1.0.3).

iaminov avatar Aug 04 '21 18:08 iaminov

Same problem with Terraform 1.0.5 and vSphere.

LinzerToertchen avatar Aug 26 '21 10:08 LinzerToertchen

Hello all,

Overall this does sound like an issue being triggered by some unexpected provider behavior, but without a way to reproduce it it's going to prove very difficult to track down. If anyone can supply the information requested in the issue template it would help greatly.

Thanks!

jbardin avatar Sep 17 '21 18:09 jbardin

Hello all,

Overall this does sound like an issue being triggered by some unexpected provider behavior, but without a way to reproduce it it's going to prove very difficult to track down. If anyone can supply the information requested in the issue template it would help greatly.

Thanks! @jbardin

So I think the issue really stems from Terraform just not being able to properly handle resources it did not itself create, and also specifically requiring an unaltered statefile from the workspace that created those resources.

iaminov avatar Sep 17 '21 18:09 iaminov

I think this might be related to https://github.com/hashicorp/terraform/issues/28939#issuecomment-863611466

bmbferreira avatar Oct 08 '21 13:10 bmbferreira

I'm hitting the same in Terraform Cloud. Workspace is using Terraform 1.2.9

image

dkirrane avatar Sep 15 '22 19:09 dkirrane

Hi guys.

Any new information regarding this issue? I'm facing the same problem and I'm using Terraform v1.3.0 on windows_386

  • provider registry.terraform.io/hashicorp/archive v2.2.0
  • provider registry.terraform.io/hashicorp/aws v4.29.0
  • provider registry.terraform.io/hashicorp/random v3.4.3

Thanks

tiagoaleixosoares avatar Oct 19 '22 10:10 tiagoaleixosoares

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

github-actions[bot] avatar Dec 03 '22 02:12 github-actions[bot]