Terraform-provider-aws: Add tags argument into aws lb data source

Created on 5 Mar 2020  路  9Comments  路  Source: hashicorp/terraform-provider-aws

Community Note

  • Please vote on this issue by adding a 馃憤 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Description

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.

New or Affected Resource(s)

  • aws_lb (or the aliased aws_alb)

Potential Terraform Configuration

data "aws_lb" "k8s_ingress_lb" {
  tags = "k8s-ingress-lb"
}

References

  • https://github.com/terraform-providers/terraform-provider-aws/pull/6458

  • https://www.terraform.io/docs/providers/aws/d/lb.html
  • enhancement needs-triage servicelbv2

    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.

    All 9 comments

    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.

    Was this page helpful?
    0 / 5 - 0 ratings