1
0
IaC/terraform/cloudflare/main.tf
2024-10-24 18:39:30 +13:00

55 lines
1.2 KiB
HCL

# 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" {}
# output "accounts" {
# value = data.cloudflare_accounts.default.accounts[0]
# }
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" "a_records" {
for_each = var.a_records
zone_id = cloudflare_zone.balsillie_net.id
proxied = false
type = "A"
ttl = 60
name = each.key
content = each.value
}
resource "cloudflare_record" "cname_records" {
for_each = var.cname_records
zone_id = cloudflare_zone.balsillie_net.id
proxied = false
type = "CNAME"
ttl = 60
name = each.key
content = each.value
}