hi guys
i am trying to create a listener rule in my TF code and to add sitckiness to the rule.
If i do it manually i can select 1 target and add the sitckiness but if i do from code i cannot.
checking Terraform Registry
under the forward block it says:
Forward Blocks (for forward
) support the following:
target_group
- (Required) One or more target groups block.
stickiness
- (Optional) The target group stickiness for the rule.
but if i add in code
resource "aws_lb_listener_rule" "alb_01_lis_rule_ezyuat_02" {
listener_arn = aws_lb_listener.alb_01_lis_443.arn
priority = 1
action {
type = "forward"
forward {
target_group {
arn = aws_lb_target_group.alb_01_tg_ezyuat.arn
weight = 100
}
stickiness {
enabled = true
duration = 14400
}
}
}
condition {
path_pattern {
values = ["/monitor"]
}
}
condition {
host_header {
values = ["example.com"]
}
}
}
I get
╷
│ Error: Insufficient target_group blocks
│
│ on custom.tf line 86, in resource “aws_lb_listener_rule” “alb_01_lis_rule_02”:
│ 86: forward {
│
│ At least 2 “target_group” blocks are required.
how to solve it?
kpanic9
February 24, 2022, 8:42am
2
I think this issue should be fixed when you remove weight = 100
from target group block.
Same problem here, could this be a TF bug?
Hey, I think we can have one target group only by using this more simple notation:
action {
type = "forward"
target_group_arn = aws_lb_target_group.static.arn
}
@ivanilves your solution is a quick workaround and works but it unfortunately doesn’t help with creating stickiness blocks or add weight values since those are only supported in a “forward {}” block.
Apparently adding 1 TG is an AWS API limitation as mentioned here:
hashicorp:master
← rdelcampog:f/aws_lb_listener_rule-weighted-tg
opened 06:46PM - 29 Mar 20 UTC
_**NOTE:** This PR is based on the @goodspark approach in PR #11606. I have impl… emented tests, docs, the default_action part and fix some things not working properly (like using a TypeList instead TypeSet in forward.target_group what causes showing changes in the diff output). I'm not a repo maintainer so I can't contribuite to their PR._
### Community Note
* Please vote on this pull request by adding a 👍 [reaction](https://blog.github.com/2016-03-10-add-reactions-to-pull-requests-issues-and-comments/) 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
Closes #10942
Can possibly help in #636
Release note for [CHANGELOG](https://github.com/terraform-providers/terraform-provider-aws/blob/master/CHANGELOG.md):
<!--
If change is not user facing, just write "NONE" in the release-note block below.
-->
```release-note
* resource/aws_lb_listener_rule: Add support for multiple, weighted target groups in forward rules.
* resource/aws_lb_listener: Add support for multiple, weighted target groups in default actions.
```
Output from acceptance testing:
<!--
Replace TestAccXXX with a pattern that matches the tests affected by this PR.
For more information on the `-run` flag, see the `go test` documentation at https://tip.golang.org/cmd/go/#hdr-Testing_flags.
-->
```
$ make testacc TEST=./aws TESTARGS='-run=TestAccAWSLBListenerRule_forwardWeighted'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -count 1 -parallel 20 -run=TestAccAWSLBListenerRule_forwardWeighted -timeout 120m
=== RUN TestAccAWSLBListenerRule_forwardWeighted
=== PAUSE TestAccAWSLBListenerRule_forwardWeighted
=== CONT TestAccAWSLBListenerRule_forwardWeighted
--- PASS: TestAccAWSLBListenerRule_forwardWeighted (310.22s)
PASS
ok github.com/terraform-providers/terraform-provider-aws/aws 311.692s
$ make testacc TEST=./aws TESTARGS='-run=TestAccAWSLBListener_forwardWeighted'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -count 1 -parallel 20 -run=TestAccAWSLBListener_forwardWeighted -timeout 120m
=== RUN TestAccAWSLBListener_forwardWeighted
=== PAUSE TestAccAWSLBListener_forwardWeighted
=== CONT TestAccAWSLBListener_forwardWeighted
--- PASS: TestAccAWSLBListener_forwardWeighted (285.26s)
PASS
ok github.com/terraform-providers/terraform-provider-aws/aws 286.758s
...
```