feat: add caddy proxy
This commit is contained in:
33
modules/10-services-generic/cloudflare-dns/main.tf
Normal file
33
modules/10-services-generic/cloudflare-dns/main.tf
Normal file
@@ -0,0 +1,33 @@
|
||||
terraform {
|
||||
required_providers {
|
||||
cloudflare = {
|
||||
source = "cloudflare/cloudflare"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
locals {
|
||||
hostname_records = length(var.hostnames) > 0 ? {
|
||||
for hostname in var.hostnames :
|
||||
hostname => {
|
||||
name = split(".", hostname)[0] // Extract subdomain
|
||||
value = var.target_content
|
||||
type = var.record_type
|
||||
proxied = var.proxied
|
||||
ttl = var.ttl
|
||||
}
|
||||
} : {}
|
||||
|
||||
all_records = merge(local.hostname_records, var.dns_records)
|
||||
}
|
||||
|
||||
resource "cloudflare_record" "service" {
|
||||
for_each = local.all_records
|
||||
|
||||
zone_id = var.zone_id
|
||||
name = each.value.name
|
||||
content = each.value.value
|
||||
type = each.value.type
|
||||
proxied = each.value.proxied
|
||||
ttl = each.value.ttl
|
||||
}
|
||||
9
modules/10-services-generic/cloudflare-dns/outputs.tf
Normal file
9
modules/10-services-generic/cloudflare-dns/outputs.tf
Normal file
@@ -0,0 +1,9 @@
|
||||
output "dns_records" {
|
||||
description = "Map of DNS records created"
|
||||
value = cloudflare_record.service
|
||||
}
|
||||
|
||||
output "record_hostnames" {
|
||||
description = "List of hostnames for which DNS records were created"
|
||||
value = keys(local.all_records)
|
||||
}
|
||||
46
modules/10-services-generic/cloudflare-dns/variables.tf
Normal file
46
modules/10-services-generic/cloudflare-dns/variables.tf
Normal file
@@ -0,0 +1,46 @@
|
||||
variable "zone_id" {
|
||||
description = "Cloudflare Zone ID"
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "dns_records" {
|
||||
description = "Map of DNS records to create"
|
||||
type = map(object({
|
||||
name = string
|
||||
value = string
|
||||
type = string
|
||||
proxied = bool
|
||||
ttl = number
|
||||
}))
|
||||
default = {}
|
||||
}
|
||||
|
||||
variable "hostnames" {
|
||||
description = "List of hostnames to create DNS records for"
|
||||
type = list(string)
|
||||
default = []
|
||||
}
|
||||
|
||||
variable "target_content" {
|
||||
description = "Target content/value for the DNS records when using hostnames list"
|
||||
type = string
|
||||
default = ""
|
||||
}
|
||||
|
||||
variable "record_type" {
|
||||
description = "Record type for the DNS records when using hostnames list"
|
||||
type = string
|
||||
default = "CNAME"
|
||||
}
|
||||
|
||||
variable "proxied" {
|
||||
description = "Whether the records should be proxied through Cloudflare"
|
||||
type = bool
|
||||
default = true
|
||||
}
|
||||
|
||||
variable "ttl" {
|
||||
description = "TTL for the records (only used when proxied=false)"
|
||||
type = number
|
||||
default = 1 # Auto
|
||||
}
|
||||
Reference in New Issue
Block a user