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

Update lb_listener datasource schema to match lb_listener default_action forward schema #17238

Merged
merged 1 commit into from
Jan 26, 2021

Conversation

rdelcampog
Copy link
Contributor

Community Note

  • Please vote on this pull request by adding a 👍 reaction to the original pull request comment 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 pull request followers and do not help prioritize the request

Relates #12574
Relates #10942


Bug description

When the weighted target group functionality was added back in June 2020 in #12547, the lb_listener default_action block schema was not updated.


Affected Resource(s)

aws_lb_listener (datasource)

Expected Behavior

Terraform should retrieve the specified AWS ELB listener configuration object for cases where there is a single target group configured, or weighted target groups are used on the resource.

Actual Behavior

If the aws_lb_listener datasource tries to retrieve a listener configured with a weighted target group forward default action:

data "aws_lb_listener" "example" {
  load_balancer_arn = aws_alb.example.arn
  port              = 443
}

locals {
  default_lb_listener_action = data.aws_lb_listener.example.default_action
}

output "default_lb_listener_action" {
  value = local.default_lb_listener_action
}

Terraform stops with an error:

Error: error setting default_action: Invalid address to set: []string{"default_action", "0", "forward"}

Steps to Reproduce

terraform apply

Terraform Configuration Files

This bug prevents gathering the current weight configured in the default action of an AWS ALB listener, needed for example to detect the current Target Group ARN that is currently receiving the 100% of the traffic (very useful for active side detection in blue-green deployments):

resource "aws_alb" "example" {
  name            = "example-alb"
  subnets         = module.vpc.public_subnets
  internal        = false
}

resource "aws_alb_listener" "example" {
  load_balancer_arn = aws_alb.example.arn
  port              = 443
  protocol          = "tcp"

  default_action {
    type = "forward"
    forward {
      target_group {
        arn    = "arn:aws:elasticloadbalancing:us-east-1:012345678901:targetgroup/tg-one/abcdefgh1234567"
        weight = 1
      }
      target_group {
        arn    = "arn:aws:elasticloadbalancing:us-east-1:012345678901:targetgroup/tg-two/abcdefgh1234567"
        weight = 0
      }
    }
  }
}

data "aws_lb_listener" "example" {
  load_balancer_arn = aws_alb.example.arn
  port              = 443
}

locals {
  default_lb_listener_action_targets = data.aws_lb_listener.example.default_action[0].forward[0].target_group
  lb_listener_forwarding_target_arn  = [for target_group in local.default_lb_listener_action_targets : target_group.arn if target_group.weight == 1][0]
}

output "lb_listener_forwarding_target_arn" {
  value = local.lb_listener_forwarding_target_arn
}

Release note for CHANGELOG:

* data-source/aws_lb_listener: Prevent error when retrieving a listener whose default action contains weighted target groups

Output from acceptance testing:

$ make testacc TEST=./aws TESTARGS='-run=TestAccDataSourceAWSLBListener'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -count 1 -parallel 20 -run=TestAccDataSourceAWSLBListener -timeout 120m
=== RUN   TestAccDataSourceAWSLBListener_basic
=== PAUSE TestAccDataSourceAWSLBListener_basic
=== RUN   TestAccDataSourceAWSLBListener_BackwardsCompatibility
=== PAUSE TestAccDataSourceAWSLBListener_BackwardsCompatibility
=== RUN   TestAccDataSourceAWSLBListener_https
=== PAUSE TestAccDataSourceAWSLBListener_https
=== CONT  TestAccDataSourceAWSLBListener_basic
=== CONT  TestAccDataSourceAWSLBListener_https
=== CONT  TestAccDataSourceAWSLBListener_BackwardsCompatibility
--- PASS: TestAccDataSourceAWSLBListener_basic (206.34s)
--- PASS: TestAccDataSourceAWSLBListener_https (216.49s)
--- PASS: TestAccDataSourceAWSLBListener_BackwardsCompatibility (217.41s)
PASS
ok      github.com/terraform-providers/terraform-provider-aws/aws       219.182s

@rdelcampog rdelcampog requested a review from a team as a code owner January 22, 2021 11:08
@ghost ghost added size/S Managed by automation to categorize the size of a PR. service/elbv2 Issues and PRs that pertain to the elbv2 service. labels Jan 22, 2021
@github-actions github-actions bot added the needs-triage Waiting for first response or review from a maintainer. label Jan 22, 2021
@rdelcampog
Copy link
Contributor Author

@gdavison I would be very grateful if you could take a look to this bugfix when you have a while, it is a very simple change that I think can be approved quickly. Thank you! 😄

Base automatically changed from master to main January 23, 2021 01:00
@bflad bflad added enhancement Requests to existing resources that expand the functionality or scope. bug Addresses a defect in current functionality. 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 Jan 26, 2021
Copy link
Contributor

@bflad bflad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a covering acceptance test. Thank you, @rdelcampog for this fix. 🚀

bflad added a commit that referenced this pull request Jan 26, 2021
…7238

Output from acceptance testing:

```
--- PASS: TestAccDataSourceAWSLBListener_DefaultAction_Forward (1065.87s)
```
@bflad bflad merged commit 992464a into hashicorp:main Jan 26, 2021
@github-actions github-actions bot added this to the v3.26.0 milestone Jan 26, 2021
@ghost
Copy link

ghost commented Jan 28, 2021

This has been released in version 3.26.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 for triage. Thanks!

@ghost
Copy link

ghost commented Feb 26, 2021

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 feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

@ghost ghost locked as resolved and limited conversation to collaborators Feb 26, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Addresses a defect in current functionality. service/elbv2 Issues and PRs that pertain to the elbv2 service. size/S Managed by automation to categorize the size of a PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants