# Migrate from count to for\_each

**URL:** <https://discuss.hashicorp.com/t/migrate-from-count-to-for-each/6380>\
**Category:** Terraform\
**Created:** [February 28, 2020, 8:20am UTC](https://discuss.hashicorp.com/t/migrate-from-count-to-for-each/6380 "2020-02-28T08:20:04Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![logicminds](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/logicminds/32/32026_2.png) [@logicminds](https://discuss.hashicorp.com/u/logicminds)\
**Post date:** [November 15, 2022, 4:18pm UTC](https://discuss.hashicorp.com/t/migrate-from-count-to-for-each/6380/5 "2022-11-15T16:18:34Z")

</div>

I was referring to the original question and suggestion of possible resolutions via the links. Currently I have 0.13.4 and a module that uses count for one of the resources and need to switch to the each method.

Question is how to update my state at the same time as updating my code? Because switching just the code causes havoc.

Looks like I can do  
terraform state mv ‘packet\_device.worker[0]’ ‘packet\_device.worker[“device\_name”]’ ?

---

_[View the full topic](https://discuss.hashicorp.com/t/migrate-from-count-to-for-each/6380)._
