hashicorp / terraform-provider-aws

The AWS Provider enables Terraform to manage AWS resources.
https://registry.terraform.io/providers/hashicorp/aws
Mozilla Public License 2.0
9.82k stars 9.17k forks source link

[Enhancement]: "aws_lb" data lookup by tags could be more efficient #36696

Open jasonzhao6 opened 7 months ago

jasonzhao6 commented 7 months ago

Description

Terraform Version

1.7.4

Use Cases

When performing a data lookup by tags on aws_lb, like below:

data "aws_lb" "shared_alb" {
  tags = {
    env      = local.tags.env
    region   = local.tags.region
    shard_id = local.tags.shard_id
  }
}

It first downloads all load balancers, then it performs filtering by tags. The time it takes to download all load balancers grows with the number of load balancers. E.g For ~400 load balancers, it's taking 42 seconds:

module.this.module.alb_listener_rule.data.aws_lb.shared_alb: Still reading... [20s elapsed]
module.this.module.alb_listener_rule.data.aws_lb.shared_alb: Still reading... [30s elapsed]
module.this.module.alb_listener_rule.data.aws_lb.shared_alb: Still reading... [40s elapsed]
module.this.module.alb_listener_rule.data.aws_lb.shared_alb: Read complete after 42s [id=arn:aws:elasticloadbalancing:us-east-1:...]

Is there anyway to filter by tags first, then download only the relevant ones?

Attempted Solutions

To avoid the extra 42 seconds per terraform plan command, we are working around by filtering by name addition to tags, but this means we are restricted to using name instead of name_prefix when creating aws_lb.

Proposal

Is there anyway to filter by tags first, then download only the relevant ones?

Affected Resource(s) and/or Data Source(s)

No response

Potential Terraform Configuration

No response

References

No response

Would you like to implement a fix?

None

github-actions[bot] commented 7 months ago

Community Note

Voting for Prioritization

Volunteering to Work on This Issue