I use Terraform a mostly uniform group of servers - EC2, S3 etc. This works reasonably well, except we need to have rather different actions for the load balancers depending on the specific group, and I can't figure out how to do it.
To be more specific, this is what the common setup looks like
resource "aws_alb_listener" "listener_https" {
load_balancer_arn = aws_alb.alb.arn
port = "443"
protocol = "HTTPS"
ssl_policy = "ELBSecurityPolicy-FS-1-2-Res-2019-08"
certificate_arn = data.aws_acm_certificate.main.arn
default_action {
target_group_arn = aws_alb_target_group.group.arn
type = "forward"
}
}
but in a couple of cases I need the default action to be a redirect, rather than a forward.
I thought using a dynamic "default_action"
block could help, but I can't seem to find a way to set both the name of the fields and the value (which could mean it's not the correct approach, in which case I'd love to know what the correct one is).
I guess my question could also be generalized to "(how) can I define all the values of a given resource as a single value and then apply them" (equivalent to what I'd do in python by preparing a dict with the values I need and then creating the object with **dict
)