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

Logical Resources for Random Values #6672

Merged
merged 4 commits into from
May 29, 2016
Merged

Logical Resources for Random Values #6672

merged 4 commits into from
May 29, 2016

Conversation

apparentlymart
Copy link
Contributor

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 have create_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 like aws_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.

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.
@jen20
Copy link
Contributor

jen20 commented May 16, 2016

@apparentlymart I am pro on this idea - one question: should it be a data source in the new world?

@apparentlymart
Copy link
Contributor Author

apparentlymart commented May 16, 2016

@jen20 I think these along with most of the resources in the tls provider are interesting examples where the idea of a "logical resource" still makes sense even though data sources are supported: although the random resources exist entirely within Terraform's logic, they still have a create/delete lifecycle and retain state.

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.

@jen20
Copy link
Contributor

jen20 commented May 29, 2016

👍 agree with your thinking there. This LGTM!

@ghost
Copy link

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

Successfully merging this pull request may close these issues.

2 participants