Would it be possible to attempt to find two resources and error if none of them are found?
Example:
data "aws_resourcegroupstaggingapi_resources" "elb_classic" {
resource_type_filters = ["elasticloadbalancing:loadbalancer"]
depends_on = [ ]
tag_filter {
key = "kubernetes.io/service-name"
values = ["service-name"]
}
}
data "aws_resourcegroupstaggingapi_resources" "elb_v2" {
resource_type_filters = ["elasticloadbalancing:loadbalancer"]
depends_on = [ ]
tag_filter {
key = "service.k8s.aws/stack"
values = ["service-name"]
}
}
data "aws_lb" "lb" {
arn = try(data.aws_resourcegroupstaggingapi_resources.elb_classic.resource_tag_mapping_list[0].resource_arn, try(data.aws_resourcegroupstaggingapi_resources.elb_v2.resource_tag_mapping_list[0].resource_arn, "LB not found"))
}
Is there perhaps a better way of configuring this?