Skip to content

aws_lb_listener_rule - Ignore weights for ECS blue/green deployments #43905

@muru

Description

@muru

Description

With the new ECS Blue/Green deployment support (support added in #43434), the ALB listener rule weights will be changed by ECS when deployments occur, so these weights can no longer be managed in Terraform.

Ideally, this could have been resolved by using lifecycle { ignore_changes }, but it is not possible to ignore only the weight, because the target_groups are a set of objects, and there's no way to refer to a key in them:

action[0].forward[0].target_group.weight
╷
│ Error: Cannot index a set value
│
│   on webapps_blue_green.tf line 45, in resource "aws_lb_listener_rule" "blue_green":
│   45:       action[0].forward[0].target_group.weight,
│
│ Block type "target_group" is represented by a set of objects, and set elements do not have addressable keys. To find elements matching specific criteria, use a "for" expression with an "if"
│ clause.
╵
action[0].forward[0].target_group.*.weight (similar error for action[0].forward[0].target_group[*].weight)
╷
│ Error: Invalid expression
│
│   on webapps_blue_green.tf line 43, in resource "aws_lb_listener_rule" "blue_green":
│   43:       action[0].forward[0].target_group.*.weight,
│
│ A single static variable reference is required: only attribute access and indexing with constant keys. No calculations, function calls, template expressions, etc are allowed here.
╵
action[0].forward[0].target_group[0].weight
│ Error: Cannot index a set value
│
│   on webapps_blue_green.tf line 45, in resource "aws_lb_listener_rule" "blue_green":
│   45:       action[0].forward[0].target_group[0].weight,
│
│ Block type "target_group" is represented by a set of objects, and set elements do not have addressable keys. To find elements matching specific criteria, use a "for" expression with an "if"
│ clause.

Omitting the weight simply leads to them being set to 1. The only thing that works is ignoring target_group altogether, but if we need to update the target groups, then we will have to recreate the rule altogether (probably with a replace_triggerd_by).

It would be nice if we could indicate to the resource that weights will be set elsewhere. The weights are already optional, so maybe we could have a new attribute that will cause the weights to be treated as computed values?

Affected Resource(s) or Data Source(s)

  • aws_lb_listener_rule

Potential Terraform Configuration

resource "aws_lb_listener_rule" "blue_green" {
  action {
    type = "forward"
    forward {
      externally_managed_weights = true
      target_group {
        arn = aws_lb_target_group.blue.arn
      }
      target_group {
        arn = aws_lb_target_group.green.arn
      }
    }
  }
  

References

No response

Would you like to implement the enhancement?

No

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementRequests to existing resources that expand the functionality or scope.service/elbv2Issues and PRs that pertain to the elbv2 service.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions