Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tags argument into aws lb data source #12265

Closed
leoskyrocker opened this issue Mar 5, 2020 · 15 comments · Fixed by #6458
Closed

Add tags argument into aws lb data source #12265

leoskyrocker opened this issue Mar 5, 2020 · 15 comments · Fixed by #6458
Labels
enhancement Requests to existing resources that expand the functionality or scope. service/elbv2 Issues and PRs that pertain to the elbv2 service.
Milestone

Comments

@leoskyrocker
Copy link

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 #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

@leoskyrocker leoskyrocker added the enhancement Requests to existing resources that expand the functionality or scope. label Mar 5, 2020
@ghost ghost added the service/elbv2 Issues and PRs that pertain to the elbv2 service. label Mar 5, 2020
@github-actions github-actions bot added the needs-triage Waiting for first response or review from a maintainer. label Mar 5, 2020
@sepulvedablanco
Copy link

When will be available this feature?

@vladdy
Copy link

vladdy commented Jun 6, 2020

I would be very interested in helping getting this done if @mbyrdziak does not have time.

@fredericvl
Copy link

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.

@ofirshtrull
Copy link

any update on this?

@hameno
Copy link

hameno commented Sep 16, 2020

We also need this very urgently

@hameno
Copy link

hameno commented Sep 16, 2020

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

@jasgeo75
Copy link

@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"}
}

@hameno
Copy link

hameno commented Oct 14, 2020

@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

@jasgeo75
Copy link

@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.

@sturman
Copy link
Contributor

sturman commented Apr 28, 2021

for those who uses kubernetes terraform provider version 2.x, the @hameno suggestion will look like

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.status[0].load_balancer[0].ingress[0].hostname)["name"]
}

@kristijorgji
Copy link

kristijorgji commented May 4, 2021

Very important to be able to search by tag name, following
We can add tag names to generated load balancer easy https://kubernetes.io/docs/concepts/services-networking/service/#other-elb-annotations, but then need to be able search for the tag in this data resource

@sturman
Copy link
Contributor

sturman commented May 6, 2021

Another workaround is introduced in AWS terraform provider release 3.38.0

data "aws_resourcegroupstaggingapi_resources" "load_balancer" {
  resource_type_filters = ["elasticloadbalancing:loadbalancer"]

  tag_filter {
    key    = "environment"
    values = ["integration"]
  }

  tag_filter {
    key    = "owner"
    values = ["my-company"]
  }
}

data "aws_lb" "nlb" {
  arn = data.aws_resourcegroupstaggingapi_resources.load_balancer.resource_tag_mapping_list[0].resource_arn
}

@sht
Copy link

sht commented Jun 15, 2021

Another workaround is introduced in AWS Terraform provider release 3.38.0

data "aws_resourcegroupstaggingapi_resources" "load_balancer" {
  resource_type_filters = ["elasticloadbalancing:loadbalancer"]

  tag_filter {
    key    = "environment"
    values = ["integration"]
  }

  tag_filter {
    key    = "owner"
    values = ["my-company"]
  }
}

data "aws_lb" "nlb" {
  arn = data.aws_resourcegroupstaggingapi_resources.load_balancer.resource_tag_mapping_list[0].resource_arn
}

Thank you for suggesting this. Though I kept getting this error:

Error: error retrieving LB: ValidationError: 'arn:aws:elasticloadbalancing:eu-west-1:479242668342:loadbalancer/a522a95f121b841d3bac05ee4b02dfc8' is not a valid load balancer ARN
	status code: 400, request id: 97e4019d-c96f-6eef-9b5a-85d5b56c1937

I wanted to retrieve the DNS name of the ELB and a little bit of modification has worked for me: 👇

data "aws_elb" "kibana" {
  name = split("/", data.aws_resourcegroupstaggingapi_resources.load_balancer.resource_tag_mapping_list[0].resource_arn)[1]
}

output "aws_lb" {
  value = data.aws_elb.kibana.dns_name
}

@github-actions
Copy link

This functionality has been released in v3.52.0 of the Terraform AWS Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 29, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement Requests to existing resources that expand the functionality or scope. service/elbv2 Issues and PRs that pertain to the elbv2 service.
Projects
None yet
Development

Successfully merging a pull request may close this issue.