1
0
IaC/terraform/cloudflare/main.tf

55 lines
1.2 KiB
Terraform
Raw Normal View History

2024-10-23 00:22:32 -04:00
# 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" {
2024-10-24 01:39:30 -04:00
path = pathexpand("~/Backups/tfstate/cloudflare.tfstate")
2024-10-23 00:22:32 -04:00
}
}
provider "cloudflare" {
api_token = var.api_token
}
2024-10-24 01:39:30 -04:00
data "cloudflare_accounts" "default" {}
# output "accounts" {
# value = data.cloudflare_accounts.default.accounts[0]
# }
2024-10-23 00:22:32 -04:00
resource "cloudflare_zone" "balsillie_net" {
2024-10-24 01:39:30 -04:00
account_id = data.cloudflare_accounts.default.accounts[0].id
2024-10-23 00:22:32 -04:00
zone = "balsillie.net"
paused = false
plan = "free"
type = "full"
}
2024-10-24 01:39:30 -04:00
resource "cloudflare_zone_dnssec" "balsillie_net" {
2024-10-23 00:22:32 -04:00
zone_id = cloudflare_zone.balsillie_net.id
}
2024-10-24 01:39:30 -04:00
resource "cloudflare_record" "a_records" {
for_each = var.a_records
2024-10-23 00:22:32 -04:00
zone_id = cloudflare_zone.balsillie_net.id
proxied = false
type = "A"
ttl = 60
2024-10-24 01:39:30 -04:00
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
2024-10-23 00:22:32 -04:00
}