title: in terraform how to set if condition for data resource
body: <p>How do I set if statement for data aws_acm_certificate. I get the following error when I add count for data aws_acm_certificate. I do not get the same error for resource &quot;aws_lb_listener&quot;.</p>
  <blockquote>
  <p>Because data.aws_acm_certificate.acm_certificate has &quot;count&quot; set, its
  attributes must be accessed on specific instances.</p>
  </blockquote>
  <pre><code>data &quot;aws_acm_certificate&quot; &quot;acm_certificate&quot; {
    count = var.protocol!=&quot;TCP&quot; ? 1 : 0
    domain   = var.certificate_domain_name
    most_recent = true
  }
  
  resource &quot;aws_lb_listener&quot; &quot;listener_https&quot; {
    count = var.protocol!=&quot;TCP&quot; ? 1 : 0
    load_balancer_arn = var.load_balancer_arn
    port              = &quot;443&quot;
    protocol          = &quot;HTTPS&quot;
    ssl_policy        = &quot;ELBSecurityPolicy-2016-08&quot;
    certificate_arn   = data.aws_acm_certificate.acm_certificate.arn
  
    default_action {
      type             = &quot;forward&quot;
      target_group_arn = var.target_group_arn
    }
  }
  </code></pre>