-
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
Support unique id generation with user-defined prefixes #2269
Comments
👍 this would be very useful for us. |
++1 |
have a specific situation right now, once created it shouldn't change until destroyed. not sure if there is better way to do this at moment, having uuid() as interpolation function would work great given that ignore_changes is there as well +1 |
I had previously left a comment over in #494 that seems to be more relevant over here. To restate it in a manner that's more applicable to this issue, I'd like to propose/discuss the idea of "resource metadata" that can, unlike resource data, be interpolated into the resource itself. Resource metadata is updated by Terraform as part of the planning process, and could include:
The design I had in mind is that Terraform records all of the above values in a new section of the instance state so that they'll persist between runs, and then Terraform itself will manage them to ensure that they get set to the right values during plan/apply. Unique Id generation can then look something like this: resource "aws_security_group" "foo" {
name = "example-${meta.self.unique_id}"
// ...
} But you could also do something like this, using metadata between resources (using the proposal from #2696 as an example, just because it's the simplest example of such a construction that sprang to my mind): resource "something" "anything" {}
resource "something_else" "anything_else" {}
// Run a provisioner when either of the above resources is updated.
resource "stateful_provisioning" "foo" {
state_key = "${meta.something.anything.updated_time} ${meta.something_else.anything_else.updated_time}"
provisioner "whatever" {
// ...
}
} I think this model makes a better building block within Terraform than relying on |
yes, above suggestion looks very promising for enhancing terraform workflow |
Landed a simple |
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. |
Right now we have
resource.UniqueId()
which is a feature that provider authors can use to generate guaranteed-unique values for attributes.These values have a static prefix of
terraform-
and a blob of alphanumeric characters.It'd be helpful if we could give users a bit more control over unique ID generation:
We can implement this as an interpolation function
uuid()
, but we don't currently have any way of preventing the identifier from being regenerated on every plan and apply (thereby creating a perpetual diff). Theignore_changes
meta-parameter proposed in #2018 should help with this, and is basically a prerequisite to any sane UX. (Not sure if I missed any other caveats of the implications of a constantly changing interpolation function.)Comments on this proposed feature are welcome!
The text was updated successfully, but these errors were encountered: