This is a feature request to ask for adding the "tags" argument into aws lb data source.
Quoting exactly from @mbyrdziak in https://github.com/terraform-providers/terraform-provider-aws/pull/6458:
Some tools, like kubernetes, creates cloud resources with random names hence you are unable to find them by current possibilities of this data source. Finding load balancers by specifying tags will solve this issue.
There is already a PR for this, but I'm creating an issue as it seems that this PR is lost in the wild without an issue to track this.
data "aws_lb" "k8s_ingress_lb" {
tags = "k8s-ingress-lb"
}
https://github.com/terraform-providers/terraform-provider-aws/pull/6458
When will be available this feature?
I would be very interested in helping getting this done if @mbyrdziak does not have time.
We absolutely need this to get the ARN of a LB created by Kubernetes and to create a VPC link (for API Gateway) that points to that LB...
Currently we are blocked to automate this part.
any update on this?
We also need this very urgently
I found a workaround:
data "kubernetes_service" "nginx-ingress" {
metadata {
namespace = "ingress-nginx"
name = "ingress-nginx-controller"
}
}
data "aws_lb" "ingress_nlb" {
name = regex("^(?P<name>.+)-.+\\.elb\\..+\\.amazonaws\\.com", data.kubernetes_service.nginx-ingress.load_balancer_ingress[0].hostname)["name"]
depends_on = [module.eks]
}
It's a bit ugly bug seems to work
@hameno
Not sure you were using 'tags' correctly. This worked for me:
data` "aws_lb" "alb_ingress" {
tags = {"kubernetes.io/ingress-name" = "istio-alb-ingressgateway"}
}
@jasgeo75 Are you sure? Do you have more than one NLB/ALB? The official documentation also does not suggest, that tags are supported: https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/lb
As soon as I had more than one NLB the resource errors out with:
Error: Search returned XX results, please revise so only one is returned
@hameno
Apologies, it appears I was wrong here. On a clean run it failed with the same error about XX results.
Odd that this feature never materialized, in fact there is a PR: https://github.com/terraform-providers/terraform-provider-aws/pull/6458/files but looks like it was ignored.
For now at least, your suggestion above seems the only solution.
Most helpful comment
We absolutely need this to get the ARN of a LB created by Kubernetes and to create a VPC link (for API Gateway) that points to that LB...
Currently we are blocked to automate this part.