I am struggling to find a way to include all load balancers with certain tag value's (e.g. Shield protection = ON) in an aws account. Currently i have a map of arn's in a variable and running a for loop. This method work's but not in an efficient way; since every time I have to add the ARN of a new Load balancer manually.
resource "aws_shield_protection" "this" {
for_each = var.listofarn
name = "shield protection".each.key
resource_arn = each.key
}
variable listofarn {
type = map(string)
default = {
appx_alb="arn::xxxxx"
appy_alb="arn:yyyyy"
}
}
Is there a way to use data resource "aws_lb". thanks.
Using data source wouldn't help much. aws_lb
data source can only return one alb. You can't use it to get information about all your ALBs. You would have to run the aws_lb
data source in a for_loop with tags or some ALB id.
But you could overcome your issue through development of an external data source. Since its a fully custom data source, it can return information about all your ALBs in the form you want.