-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
Define resources by iterating over a list #4410
Comments
Note: The doc mentions the count method that can solve that problem (iterations), in a more concise but arguably less declarative way. If |
I was thinking about something like this over in #3310, originally with a more complex design but eventually concluding that iterating over a list was sufficient. Just linking that here because there are some use-cases in it that might be helpful when thinking about the design for this. |
I think there might be some use cases for this - but you can achieve effectively the same thing right now with an (untested) construct like this: variable "list_of_users" {
default = "username1,username2"
}
resource "aws_iam_user" "user-${value}" {
count = "${len(split(",", var.list_of_users))}"
name = "${element(split(",", var.list_of_users), count.index}"
path = "/"
}
# repeat for the other resource I'll leave this issue open tagged for future attention for now - as @apparentlymart says this is something that has been considered before and we will come back to soon. |
@jen20 the issue here is that the resource gets stored with the The construct your posted above also doesn't work because the I'm running into this issue when trying to manage a list of users for Github. |
👍 Consider this use case:
If I delete repository |
Indeed that happens. And although "normally" it would not be a problem, it is a huge mess in other cases. Sometimes the resource is expensive to re-create, or even worse, it can trigger a recreation of dependent resources in cascade which would destroy your deployment. For instance: a AWS subnet, if we create the subnets based on a list, deleting one subnet might trigger the recreation in cascade of security groups, DBs, instances, etc. Even a simple case of a list of users to create: Deleting one user would recreate all the users in parallel, causing problems like errors due duplicated user names. |
Hi all! I'm just looking through some older issues that weren't using our latest labeling scheme and so were missed on previous issue gardening expeditions. This seems to be covering the same sort of use-case as #17179. Although this is the older of the two, there is some more discussion and updates over there so I'm going to close this one just to consolidate the discussion. Sorry for the long silence! |
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. |
Feature idea: a
resources
declaration to declare several resources, possibly by iterating over variables (list or map)Say you want to manage IAM users with Terraform, but DRY-up their groups (or other attributes)
* map refers the map function in functional programming, not the map data structure. It could be named otherwise, it's just a way to leave the door for several resources collection method.
The text was updated successfully, but these errors were encountered: