Basically, for cloudflare account it is required to get zone related information by using data source in terraform, so below data source has been tried and try to generate its output using output resource:
data "cloudflare_zones" "this_zones" {
account = {
}
direction = "xxx"
name = "example.com"
status = "active"
}
output "account" {
value = data.cloudflare_zones.this_zones.result
}
This is the results that I received:
account = tolist([
{
"account" = {
"id" = "ACCOUN_ID"
"name" = "Account_Example"
}
"activated_on" = "2023-09-29T13:47:58Z"
"created_on" = "2023-09-29T13:35:34Z"
"development_mode" = 0
"id" = "xxxxxx"
"meta" = {
"cdn_only" = tobool(null)
"custom_certificate_quota" = 1
"dns_only" = tobool(null)
"foundation_dns" = tobool(null)
"page_rule_quota" = 100
"phishing_detected" = false
"step" = 2
}
"modified_on" = "2025-02-19T15:46:33Z"
"name" = "example.com"
"name_servers" = tolist([
"xxxx.ns.cloudflare.com",
"xxxx.ns.cloudflare.com",
])
"original_dnshost" = tostring(null)
"original_name_servers" = tolist([
"xxxx.ns.cloudflare.com",
"xxxx.ns.cloudflare.com",
])
"original_registrar" = ""
"owner" = {
"id" = tostring(null)
"name" = tostring(null)
"type" = "user"
}
"paused" = false
"status" = "active"
"type" = "full"
"vanity_name_servers" = tolist([])
"verification_key" = tostring(null)
},
])
Below are the concerns on this:
Example: I tried below code :
output "account" {
value = data.cloudflare_zones.this_zones.result.account
}
I am getting error:
A reference to a resource type must be followed by at least one attribute access.
How to work with this, can anyone guide me please?
datasource document available at: https://registry.terraform.io/providers/cloudflare/cloudflare/latest/docs/data-sources/zones#nestedatt--account
If you take a look at the original output you get, you will see the tolist([...]))
casting, meaning that the particular output will be a list (because that's how the provider is defining it). That further means the specific keys can be accessed fetching the index for the list first, followed by the key name and finally an attribute:
output "account" {
value = data.cloudflare_zones.this_zones.result[0].account.id
}