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

Extend aws_lb_listener data resource to output target_group_arn #10514

Open
e-moshaya opened this issue Oct 15, 2019 · 2 comments
Open

Extend aws_lb_listener data resource to output target_group_arn #10514

e-moshaya opened this issue Oct 15, 2019 · 2 comments
Labels
question A question about existing functionality; most questions are re-routed to discuss.hashicorp.com. service/elbv2 Issues and PRs that pertain to the elbv2 service.

Comments

@e-moshaya
Copy link

I have two separate blue/green target groups. I would like to use data aws_lb_listener resource to output the active target_group_arn so I can figure out if we're in blue or green target group. I can already achieve this via the cli

aws elbv2 describe-listeners --listener-arns aws_lb_listener.service.arn --query 'Listeners[].DefaultActions[].TargetGroupArn' --output text

It would be great if terraform can support this too?

@e-moshaya e-moshaya added the enhancement Requests to existing resources that expand the functionality or scope. label Oct 15, 2019
@github-actions github-actions bot added the needs-triage Waiting for first response or review from a maintainer. label Oct 15, 2019
@nijave
Copy link
Contributor

nijave commented Oct 19, 2019

Looks like it already works

provider "aws" {}

data "aws_lb_listener" "test" {
  arn = "arn:aws:elasticloadbalancing:us-east-1:12345:listener/app/my-lb/54321/abc123"
}

output "target_group" {
  value = "${data.aws_lb_listener.test.default_action.1.target_group_arn}"
}

My ALB has another rule first so I used 1 instead of 0

terraform state show data.aws_lb_listener.test will show you what attributes are available

@e-moshaya
Copy link
Author

@nijave I tried your output . target_group_arn didn't work. I got the following error:

Error: Unsupported attribute

  on ../../modules/aws-ecs-terraform-module/ecs_service.tf line 82, in resource "aws_ecs_service" "this":
  82:     target_group_arn = data.aws_lb_listener.this[0].target_group_arn

This object has no argument, nested block, or exported attribute named
"target_group_arn".

@breathingdust breathingdust added service/elbv2 Issues and PRs that pertain to the elbv2 service. question A question about existing functionality; most questions are re-routed to discuss.hashicorp.com. and removed needs-triage Waiting for first response or review from a maintainer. enhancement Requests to existing resources that expand the functionality or scope. labels Sep 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question A question about existing functionality; most questions are re-routed to discuss.hashicorp.com. service/elbv2 Issues and PRs that pertain to the elbv2 service.
Projects
None yet
Development

No branches or pull requests

3 participants