# terraform file to create dns resource in cloudflare terraform { required_version = ">= 1.8.0" required_providers { cloudflare = { source = "cloudflare/cloudflare" version = "~> 4.44" } } backend "local" { path = pathexpand("~/Backups/tfstate/cloudflare.tfstate") } } provider "cloudflare" { api_token = var.api_token } data "cloudflare_accounts" "default" {} locals { dns_records = { for index, record in distinct(var.dns_records) : # 'distint' removes duplicate values from a list tostring(index) => record } } resource "cloudflare_zone" "balsillie_net" { account_id = data.cloudflare_accounts.default.accounts[0].id zone = "balsillie.net" paused = false plan = "free" type = "full" } resource "cloudflare_zone_dnssec" "balsillie_net" { zone_id = cloudflare_zone.balsillie_net.id } resource "cloudflare_record" "dns_records" { for_each = local.dns_records zone_id = cloudflare_zone.balsillie_net.id proxied = false name = each.value.name type = each.value.type content = each.value.content ttl = each.value.ttl } # TODO update the SOA record when dns_records resource was changed