2024-12-01 16:16:09 +08:00
|
|
|
variable "name" {
|
|
|
|
type = string
|
|
|
|
}
|
|
|
|
|
2025-01-03 22:32:05 +08:00
|
|
|
variable "hostname" {
|
|
|
|
type = list(string)
|
|
|
|
}
|
|
|
|
|
2024-12-01 16:16:09 +08:00
|
|
|
variable "script" {
|
|
|
|
type = string
|
|
|
|
}
|
|
|
|
|
|
|
|
variable "account_id" {
|
|
|
|
type = string
|
|
|
|
}
|
|
|
|
|
|
|
|
variable "zone_id" {
|
|
|
|
type = string
|
|
|
|
}
|
|
|
|
|
|
|
|
terraform {
|
|
|
|
required_providers {
|
|
|
|
cloudflare = {
|
2024-12-21 22:32:43 +08:00
|
|
|
source = "cloudflare/cloudflare"
|
2024-12-01 16:16:09 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "cloudflare_workers_route" "workers" {
|
2025-01-03 22:32:05 +08:00
|
|
|
for_each = toset(var.hostname)
|
2024-12-01 16:16:09 +08:00
|
|
|
script_name = cloudflare_workers_script.workers.name
|
2025-01-03 22:32:05 +08:00
|
|
|
pattern = "${each.value}/*"
|
2024-12-01 16:16:09 +08:00
|
|
|
zone_id = var.zone_id
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "cloudflare_workers_script" "workers" {
|
|
|
|
name = var.name
|
|
|
|
content = var.script
|
|
|
|
account_id = var.account_id
|
|
|
|
module = true
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "cloudflare_custom_hostname" "workers" {
|
2025-01-03 22:32:05 +08:00
|
|
|
for_each = toset(var.hostname)
|
2024-12-01 16:16:09 +08:00
|
|
|
zone_id = var.zone_id
|
2025-01-03 22:32:05 +08:00
|
|
|
hostname = each.value
|
2024-12-01 16:16:09 +08:00
|
|
|
ssl {
|
|
|
|
method = "http"
|
|
|
|
}
|
|
|
|
}
|