hashicorp / terraform

Terraform enables you to safely and predictably create, change, and improve infrastructure. It is a source-available tool that codifies APIs into declarative configuration files that can be shared amongst team members, treated as code, edited, reviewed, and versioned.
https://www.terraform.io
Other
42.76k stars 9.56k forks source link

Add function to sort based on IP addresses #31749

Open snuggie12 opened 2 years ago

snuggie12 commented 2 years ago

Terraform Version

v0.13.5 though I don't see it mentioned in the documentation so pretty sure any version is impacted.

Use Cases

sort sorts lexicographically as you know which puts 11.x.y.z before 3.x.y.z. I'm using toset which unorders things as well.

It'd be nice if there was a function to sort IP addresses.

Attempted Solutions

For now I think I will use sort(tolist(toset())) which although not sorted does return a consistent ordering.

Proposal

Whether there's any advantage to making IPv4 and IPv6 official types I'm not sure, but if that's one easy way to achieve a sort via sort (i.e. not making ipsort but instead enhancing sort) then that's great.

References

No response

HariVamsiK commented 2 years ago

Hi I want to work on this issue. Could you please assign it to me, it would be beneficial for my academics too. I have experience working on docker and vagrant. Thanks

crw commented 2 years ago

Hi @HariVamsiK, it is possible to assign this to you, however an implementation PR would be unlikely to be accepted at this time. The reason is that an ipsort function would need to be built as a plugin function provider, as opposed to a function built into Terraform. As such it is waiting for the implementation of plugin function providers. Please see:

I will bring this issue to triage to double-check whether this could be considered a core function or not. Thanks for your patience and interest in contributing to Terraform!

crw commented 2 years ago

Hi @HariVamsiK, I confirmed this functionality would not be considered "core" to Terraform and thus would need to wait for the future function provider framework. Thanks for your interest in this issue!

crw commented 8 months ago

Thank you for your continued interest in this issue.

Terraform version 1.8 launches with support of provider-defined functions. It is now possible to implement your own functions! We would love to see this implemented as a provider-defined function.

Please see the provider-defined functions documentation to learn how to implement functions in your providers. If you are new to provider development, learn how to create a new provider with the Terraform Plugin Framework. If you have any questions, please visit the Terraform Plugin Development category in our official forum.

We hope this feature unblocks future function development and provides more flexibility for the Terraform community. Thank you for your continued support of Terraform!