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

Introduce new 'random_integer' provider #12

Merged
merged 4 commits into from
Nov 7, 2017

Conversation

bitbrain
Copy link
Contributor

@bitbrain bitbrain commented Nov 3, 2017

This provider allows the random generation of integer values in a given inclusive range. This Pull Request aims to close #4.

Feedback welcome. 🙈

This provider allows the random generation of integer values in a given inclusive range.
@bitbrain bitbrain changed the title [#4] Introduce new 'random_range' provider Introduce new 'random_range' provider Nov 3, 2017
min = 1
max = 99999
keepers = {
# Generate a new pet name each time we switch to a new AMI id
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix documentation.

Copy link
Contributor

@apparentlymart apparentlymart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this, @bitbrain!

This seems like a fine idea to me. My feedback below is just some small naming questions; in terms of functionality this looks great to me.


The following attributes are supported:

* `id` - (int) The random range value.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It feels a little unintuitive to use id for this, since the result probably isn't an id in the usual sense we mean it.

We are required to call SetId to give Terraform something to track with, but I'd suggest that we consider that an undocumented implementation detail and instead publish a computed attribute called result which is documented here.

  priority     = "${random_range.priority.result}"

What do you think? (I chose result here again for consistency with random_string)

Copy link
Contributor Author

@bitbrain bitbrain Nov 7, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to stick to the notation of already existing providers (e.g. pet provider) which also populates an id attribute as a result.

Regardless, I agree with you, result should be it! 👍

@@ -15,6 +15,7 @@ func Provider() terraform.ResourceProvider {
"random_shuffle": resourceShuffle(),
"random_pet": resourcePet(),
"random_string": resourceString(),
"random_range": resourceRange(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Naming things is always tricky... when I first saw this name I expected that the result would be a random start/end segment of a list, or some such thing, since "range" makes me think of a sub-portion of a list.

What do you think about calling this random_integer, as a sibling of random_string?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a similar thought. However, random_integer gives me the impression that it does not necessarily require a range but allows me to get any integer. I could also make min and max optional and set it to min=0 and max=INTEGER_MAX. 🧐

@bitbrain
Copy link
Contributor Author

bitbrain commented Nov 7, 2017

@apparentlymart Updated!

@bitbrain bitbrain changed the title Introduce new 'random_range' provider Introduce new 'random_integer' provider Nov 7, 2017
@apparentlymart apparentlymart merged commit d97b869 into hashicorp:master Nov 7, 2017
@apparentlymart
Copy link
Contributor

Thanks, @bitbrain!

Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 31, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature Request: random number from range
2 participants