Reputation: 1369
Is it possible to manipulate beanstalk's autoscaling group and target group in terraform adding additional (internal) load balancer? If yes, how?
I want to have 2 load balancers one internal and the other one public. I found this workaround from AWS:
Is there any other smarter solution?
Upvotes: 3
Views: 1145
Reputation: 304
you can extend its TargetGroupARNs
from EB on your optionsettings,
using cloudformation syntax:
- Namespace: aws:cloudformation:template:resource:property
ResourceName: AWSEBAutoScalingGroup
OptionName: TargetGroupARNs
Value: [{\"Ref\":\"AWSEBV2LoadBalancerTargetGroup\"},"ARN_FROM_A_EXTERNAL_TARGETGROUP_LINKING_TO_ANOTHER_LOADBALANCER"}]
and, yes, I just found a reference to aws:cloudformation:template:resource:property here, there is no documentation at all
Upvotes: 0
Reputation: 10947
I think that this can be perfectly achieved, but you need a small change in the approach.
You will not have 2 load balancers inside of EB, but instead, your beanstalk will describe the infrastructure starting in the second load balancer, set as internal, and then you will add another public load balancer that is pointing to the BE load balancer.
We can achieve this in a much easier way than the one proposed in AWS blog.
For this, your BE setup will be pretty much the same that you have, but:
Now create a public load balancer:
and this will do the magic. You will need to check how to do this in terraform, but the approach is quite straightforward so I'm sure terraform will let you do it.
The advantage of this as opposed to the AWS blog (that is designed for a quite different purpose), is that here the internal load balancer is network, while the external doesn't need to be. With the NLB being the internal one, you avoid a lot of overhead in the infrastructure and also avoid dynamic logic like the lambda they propose to register IP addresses. With this approach, you get a much more declarative architecture, easier to describe in terraform and easier to maintain once in production.
Upvotes: 2
Reputation: 607
You can only associate a target group with one load balancer. Once you associate a target group to a load balancer that target group will no longer be available to associate with another ALB.
You could possibly come up with a work around using different approaches like port and security group rules, or create a second target group.
None of this is what Elastic beanstalk is designed to do. It's merely an easy way for developers to push code and remain hands off of the underlying infrastructure. When the complexity level increases its time to move away from EB.
Upvotes: 0