You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The keys(map) builtin - Returns a lexically sorted list of the map keys, the values counterpart also order based on the lexical order of keys.
The feature request is to support a 2nd parameter for keys and values, that toggles the ordering type. Default should remain lexical. But original and ascending and descending would be help.
keys(map, order)
And example of why this is needed.
I have a DNS module with the following components:
locals {
# Host Expressions
a_host_names = "${keys(var.a_records_map)}"
a_host_addresses = "${values(var.a_records_map)}"
}
# Create each A provided in map
resource "google_dns_record_set" "a_records" {
count = "${length(var.a_records_map)}"
name = "${local.a_host_names[count.index]}.${google_dns_managed_zone.dns_zone.dns_name}"
type = "A"
ttl = 300
managed_zone = "${google_dns_managed_zone.dns_zone.name}"
rrdatas = ["${local.a_host_addresses[count.index]}"]
depends_on = ["google_dns_managed_zone.dns_zone"]
}
Using the module I have a map like below:
production = {
my_record = "35.185.1.2"
this_record = "35.18.119.2"
}
This works fine on the initial deployment. How if I modifiy the map later with a new record where the record is lower in the alphabet. Terraform deletes all the values down to the new entry then rebuild. This causes errors as the builds and deletes aren't synced and causes clashes.
production = {
my_record = "35.185.1.2" # not changed
this_record = "35.18.119.2" # deleted and rebuilt
new_record = "56.23.56.7" # Added
}
The text was updated successfully, but these errors were encountered:
Working with the map elements in reverse order seems reasonable, but I'd prefer to implement it as a new function reverse that takes a list and reverses the order of the elements. This way it can be used not only with keys and values but also with any other list.
It is unfortunately not possible to support "original order" because maps do not retain ordering in Terraform's type system: the order you give in source code is lost immediately after the map expression is evaluated.
The root problem you have here is actually also covered by #17179: a first-class feature for creating a in instance of a resource for each element in a map. This would remove the ordering from consideration altogether, because the resources would be identified by the map keys rather than by indexes as with count.
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
locked and limited conversation to collaborators
Jul 26, 2019
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
The keys(map) builtin - Returns a lexically sorted list of the map keys, the values counterpart also order based on the lexical order of keys.
The feature request is to support a 2nd parameter for keys and values, that toggles the ordering type. Default should remain lexical. But original and ascending and descending would be help.
And example of why this is needed.
I have a DNS module with the following components:
Using the module I have a map like below:
This works fine on the initial deployment. How if I modifiy the map later with a new record where the record is lower in the alphabet. Terraform deletes all the values down to the new entry then rebuild. This causes errors as the builds and deletes aren't synced and causes clashes.
The text was updated successfully, but these errors were encountered: