Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

State move from indexed resource to non-indexed produces a failure #23847

Closed
grimm26 opened this issue Jan 13, 2020 · 2 comments · Fixed by #24254
Closed

State move from indexed resource to non-indexed produces a failure #23847

grimm26 opened this issue Jan 13, 2020 · 2 comments · Fixed by #24254
Assignees

Comments

@grimm26
Copy link

grimm26 commented Jan 13, 2020

Terraform Version

Terraform v0.12.19

Terraform Configuration Files

https://gist.github.com/grimm26/e973a686526f9d054224d251b713aae6

Expected Behavior

The outputs of the resource should still be available, i.e. the state of the resource should be correct.

Actual Behavior

The state of the resource seems incorrect and the only way forward is to manually edit the state file or move the resource back to its original place.

Steps to Reproduce

Made a bucket
Changed the s3_bucket module's aws_s3_bucket to no longer be counted. did a terraform state mv 'module.bucket.aws_s3_bucket.b[0]' module.bucket.aws_s3_bucket.b
a subsequent apply or plan will show:
Error: Unsupported attribute

  on s3_bucket/main.tf line 15, in output "id":
  15:   value = aws_s3_bucket.b.id
    |----------------
    | aws_s3_bucket.b is empty tuple

This value does not have any attributes.

In the second state file after I changed the module and moved the aws_S3_bucket resource, I think the problem is that even though I removed the count and it removed the "index_key": 0, entry from resources[0]{"instances"}[0]{"attributes"} it did not remove "each": "list" from resources[0]

Additional Context

References

#23582 seems to have introduced this.

@irl-segfault
Copy link

I hit this problem via a similar mechanism. Given a list of resources created via count, when I terraform state mv them to use for_each, the "each":"list" field does not change to "each":"map". I manually edited my state file and this seemed to work, although I don't have a deep enough understanding of why.

Steps to reproduce:

  1. Given a collection of elements created with count and a valid state file derived from that, change the source code to use for_each instead, using a map as a the for_each variable.

  2. Run terraform state mv path.to.collection[0] path.to.collection["first"] terraform state mv path.to.collection[1] path.to.collection["second"]

  3. Observe that "each":"list" is still in the state file.

@ghost
Copy link

ghost commented Apr 4, 2020

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.

@ghost ghost locked and limited conversation to collaborators Apr 4, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants