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

Count future plans #17885

Closed
eredi93 opened this issue Apr 17, 2018 · 3 comments
Closed

Count future plans #17885

eredi93 opened this issue Apr 17, 2018 · 3 comments

Comments

@eredi93
Copy link

eredi93 commented Apr 17, 2018

this issue doesn't actually highlight a bug but more a question about the future plans of changing how count works.

as right now if you are creating a resource with count, for example a user:

variable "users" {
  type     = "list"
  default = ["user_1", "user_2", "user_4"]
}

data "aws_iam_user" "user" {
  count = "${length(var.users)}"

  user_name = "${element(var.users, count.index)}"
}

^^ will create 3 users with the names described in the list.

everything works perfectly until you change the list.
I intentionally didn't add user_3 to the list to highlight the fact that is common for people to forget to add a value to a list.
adding the missing user_3 after user_2 will make the users after that to shift, causing the destroy/recreate of those resources as the index changed.
you would see the same behavior if you delete an item from the list (except if it is the last one)

what I would like to know is if there are any plans to change this logic as it is quite disruptive.
I'm wondering if terraform could figure out that the other items in the list did not change inserting or shifting the list based on the operation (delete or add of an item).

if there are no plans on changing/improving this logic could you give the good use cases of count? I see this being used in several modules (even from Hashicorp partners).
should we discourage people from using it? or at least highlight the potential danger?

@apparentlymart
Copy link
Contributor

Hi @eredi93! Thanks for reporting this use-case.

A potential solution to this problem is being discussed in #17179. While we're not working on this immediately, what I shared there is our current plan to address the problem and -- unless we find problems with the design during prototyping/implementation -- we're intending to address that once we've dealt with some other changes that are required first before it is possible to implement that solution. In particular, our current work to improve the configuration language in other ways is laying some foundations for this by changing some of our internal data structures to support instances that are identified by string keys rather than numeric indices, which is a prerequisite for using a map as the basis for multiple instances.

Since we already have #17179 open tracking this, I'm going to close this one just to consolidate the discussion over there. Thanks again for raising this!

@eredi93
Copy link
Author

eredi93 commented Apr 18, 2018

@apparentlymart thanks a million for getting back to me.
Looking forward to seeing improvements around this!

@ghost
Copy link

ghost commented Apr 3, 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 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants