Fairly straightforward quest but I cannot seem to find the answer that I need anywhere.
The below is what I am using right now that works, but is not exactly what I want. Notice how I have the first part commented out, the key thing here is I have a variable in another file with a zone_id
field which is hard-coded. I'd like to make it so I no longer have to do this; however this Terraform file does work:
# data "cloudflare_zones" "zones" {
# for_each = local.healthchecks
# filter {
# account_id = "12345678912345678912345678912345"
# name = each.value.address
# }
#}
resource "cloudflare_healthcheck" "http_health_check" {
for_each = local.healthchecks
name = each.value.name
address = each.value.address
zone_id = each.value.zone_id
path = each.value.path
check_regions = ["ENAM", "WNAM"]
type = "HTTP"
port = 80
method = "GET"
expected_codes = ["2xx", "3xx"]
What I would like to do is something like this:
data "cloudflare_zones" "zones" {
for_each = local.healthchecks
filter {
account_id = "12345678912345678912345678912345"
name = each.value.address
}
}
resource "cloudflare_healthcheck" "http_health_check" {
for_each = local.healthchecks
name = each.value.name
address = each.value.address
zone_id = data.cloudflare_zones.zones[each.key].id
path = each.value.path
check_regions = ["ENAM", "WNAM"]
type = "HTTP"
port = 80
method = "GET"
expected_codes = ["2xx", "3xx"]
The key change in the above config that I would like to be able to use is the line data.cloudflare_zones.zones[each.key].id
is trying to pull data from the now uncommented top block. However, I cannot get this to work; I continue to get errors that look like this:
│ Error: error creating standalone healthcheck: Authentication error (10000)
│
│ with module.http_health_check.cloudflare_healthcheck.http_health_check["http-health-abc-xyz"],
│ on ../../modules/cloudflare_healthcheck/main.tf line 28, in resource "cloudflare_healthcheck" "http_health_check":
│ 28: resource "cloudflare_healthcheck" "http_health_check" {
I've tried different combination of trying to get this zones.id element to show right. Does anyone know what format I need to be using, or any references for this problem?
It would be helpful for me to know if this page is the equivalent API endpoint for what I am using in my config. Any ideas?
EDIT: Here is what that healthchecks
variable looks like.
locals {
check_prefix = "http_health_check"
}
locals {
healthchecks = {
"http-health-check-abc-xyz" = {
name = "${local.check_prefix}-abc-xyz"
address = "abc.xyz.com"
zone_id = "12345678912345678912345679123495"
path = "/"
}
"http-health-check-def-ghi-biz" = {
name = "${local.check_prefix}-def-ghi-biz"
address = "def.ghi.biz"
zone_id = "12345678912345678912345679123495"
path = "/"
}
...more entries like this...
EDIT2: includes the debug var structure
debugging_var = {
"http-health-check-foo-bar" = {
"filter" = tolist([
{
"account_id" = "1234567891234567891234567"
"lookup_type" = "exact"
"match" = ""
"name" = "foo.bar.com"
"paused" = false
"status" = ""
},
])
"id" = "a16a661ad719117992719292779919121688172"
"zones" = tolist([])
}
"http-health-check-foo-bar-biz" = {
"filter" = tolist([
{
"account_id" = "1234567891234567891234567"
"lookup_type" = "exact"
"match" = ""
"name" = "foo.bar.biz"
"paused" = false
"status" = ""
},
])
"id" = "a16a661ad719117992719292779919121688172"
"zones" = tolist([])
}
...more stuff like this...
}