-
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
Logical Resources for Random Values #6672
Conversation
This provider will have logical resources that allow Terraform to "manage" randomness as a resource, producing random numbers on create and then retaining the outcome in the state so that it will remain consistent until something explicitly triggers generating new values. Managing randomness in this way allows configurations to do things like random distributions and ids without causing "perma-diffs".
This resource generates a cryptographically-strong set of bytes and provides them as base64, hexadecimal and decimal string representations. It is intended to be used for generating unique ids for resources elsewhere in the configuration, and thus the "keepers" would be set to any ForceNew attributes of the target resources, so that a new id is generated each time a new resource is generated.
random_shuffle takes a list of strings and returns a new list with the same items in a random permutation. Optionally allows the result list to be a different length than the input list. A shorter result than input results in some items being excluded. A longer result than input results in some items being repeated, but never more often than the number of input items.
@apparentlymart I am pro on this idea - one question: should it be a data source in the new world? |
@jen20 I think these along with most of the resources in the If they were data sources they would generate a fresh random number on each run, which would then fail to address the requirement that the values remain stable most of the time. |
👍 agree with your thinking there. This LGTM! |
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. |
This PR introduces a new provider called "random" that provides a generic way for Terraform to work with random values while avoiding "perma-diffs", by modelling the random values as resources themselves and thus allowing the random values to be retained between runs until configuration directs them to change.
This provider starts off with two resources that are each directed at a different use-case:
random_id
allows the generation of unique ids in a generic way, primarily for use in adding uniqueness to the names of resources that havecreate_before_destroy
set but whose implementations do not have built-in support for such "uniqing".random_shuffle
allows the generation of random permutations of lists, primarily for shuffling the results of data sources likeaws_availability_zones
(see [WIP]: provider/aws: Add aws_availability_zones data source #6671) to distribute resources "randomly" within the available availability zones. This is intended to avoid the need to build randomness into multiple data sources individually.There's more exposition and examples of this in the documentation updates that you can find in the diff of this PR.