Skip to content

Sort should retain length of list #31035

@Nuru

Description

@Nuru

Current Terraform Version

Terraform v1.1.9
on darwin_amd64

Use-cases

Given a list of items, e.g. subnet IDs, I want to create a corresponding list of resources, e.g. route tables. Since the subnet IDs will not be known at plan time, this will not work:

resource "aws_route_table_association" "public" {
  for_each = var.subnet_ids

OK, I understand, the key values are unknown, so then I switch to

resource "aws_route_table_association" "public" {
  count = length(var.subnet_ids)

which works, but now every time the order of the list of subnets changes (which may be generated by an API beyond my control), all the route table associations change. I want to keep the associations consistent as long as the set of subnet IDs remains the same (which is what I was attempting with for_each), so I try sorting the list:

resource "aws_route_table_association" "public" {
  count = length(sort(var.subnet_ids))

Unfortunately, this breaks, too.

Proposal

It appears that at present, sort returns a list of unknown length. It should return a list of known length of unknown values.

References

#30937 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementnewnew issue not yet triagedunknown-valuesIssues related to Terraform's treatment of unknown values

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions