How do i use a condition inside a for_each such that , the below resource is created/triggered only when validation_method == “DNS” else ignores the creation of a resource. However in earlier terraform (11 versions) we can use count = var.validation_method == “DNS” ? length(var.domain_names) : 0
My var.domain_names is map(list(string)) , eg domain_names = {
“foo.com” = ["*.foo.com"]
}
Please suggest me some solutions. Using terraform 0.12.20 version
resource "aws_route53_record" "validation" {
for_each = var.validation_method == "DNS" ? var.domain_names :
name = aws_acm_certificate.certificate[each.key].domain_validation_options.0.resource_record_name
type = aws_acm_certificate.certificate[each.key].domain_validation_options.0.resource_record_type
zone_id = data.aws_route53_zone.selected[each.key].zone_id
ttl = "300"
records = [aws_acm_certificate.certificate.domain_validation_options.0.resource_record_value]
depends_on = [aws_acm_certificate.certificate.domain_name]
}