Terraform iterate over multiple resources and call api conditionally

Hi,

I’m using the following terraform provider: https://registry.terraform.io/providers/cloudflare/cloudflare/latest/docs/resources/custom_hostname

I’m currently building multiple resources of type cloudflare_custom_hostname. I’d like to possibly add a variable inside each resource definition, say display = true and iterate over each one of them using something like this:

data “http” “getinfo” {
count = var.display == true ? 1 : 0
url = “https://api.cloudflare.com/client/v4/zones/${var.zone_id}/custom_hostnames/${cloudflare_custom_hostname.testoutput.id}

Optional request headers

request_headers = {
X-Auth-Key = “${var.cloudflare_api_key}”
X-Auth-Email = “${var.cloudflare_email}”
Content-Type = “application/json”
}
}

The idea is that I’m trying to get some API responses back and display them only for the resources that have var.display = true.
Any clue if this can be done?

Thanks