105 lines
2.6 KiB
HCL
105 lines
2.6 KiB
HCL
terraform {
|
|
required_providers {
|
|
cloudflare = {
|
|
source = "cloudflare/cloudflare"
|
|
version = "~> 5"
|
|
}
|
|
}
|
|
}
|
|
|
|
provider "cloudflare" {
|
|
# read token from $CLOUDFLARE_API_TOKEN
|
|
}
|
|
|
|
variable "CLOUDFLARE_ACCOUNT_ID" {
|
|
# read account id from $TF_VAR_CLOUDFLARE_ACCOUNT_ID
|
|
type = string
|
|
}
|
|
|
|
resource "cloudflare_workers_kv_namespace" "uptimeflare_kv" {
|
|
account_id = var.CLOUDFLARE_ACCOUNT_ID
|
|
title = "uptimeflare_kv"
|
|
}
|
|
|
|
resource "cloudflare_d1_database" "uptimeflare_d1" {
|
|
account_id = var.CLOUDFLARE_ACCOUNT_ID
|
|
name = "uptimeflare_d1"
|
|
primary_location_hint = "wnam"
|
|
read_replication = {
|
|
mode = "auto"
|
|
}
|
|
}
|
|
|
|
resource "cloudflare_workers_script" "uptimeflare_worker" {
|
|
account_id = var.CLOUDFLARE_ACCOUNT_ID
|
|
script_name = "uptimeflare_worker"
|
|
main_module = "worker/dist/index.js"
|
|
content_file = "worker/dist/index.js"
|
|
content_sha256 = filesha256("worker/dist/index.js")
|
|
compatibility_date = "2025-04-02"
|
|
compatibility_flags = ["nodejs_compat"]
|
|
|
|
observability = {
|
|
enabled = true
|
|
logs = {
|
|
enabled = true
|
|
invocation_logs = true
|
|
}
|
|
}
|
|
|
|
bindings = [{
|
|
name = "REMOTE_CHECKER_DO"
|
|
class_name = "RemoteChecker"
|
|
type = "durable_object_namespace"
|
|
}, {
|
|
name = "UPTIMEFLARE_STATE"
|
|
type = "kv_namespace"
|
|
namespace_id = cloudflare_workers_kv_namespace.uptimeflare_kv.id
|
|
}, {
|
|
name = "UPTIMEFLARE_D1"
|
|
type = "d1"
|
|
id = cloudflare_d1_database.uptimeflare_d1.id
|
|
}]
|
|
}
|
|
|
|
resource "cloudflare_workers_cron_trigger" "uptimeflare_worker_cron" {
|
|
account_id = var.CLOUDFLARE_ACCOUNT_ID
|
|
script_name = cloudflare_workers_script.uptimeflare_worker.script_name
|
|
schedules = [{
|
|
cron = "* * * * *" # every 1 minute, you can reduce the KV write by increase the worker settings of `kvWriteCooldownMinutes`
|
|
}]
|
|
}
|
|
|
|
resource "cloudflare_pages_project" "uptimeflare" {
|
|
account_id = var.CLOUDFLARE_ACCOUNT_ID
|
|
name = "uptimeflare"
|
|
production_branch = "main"
|
|
|
|
deployment_configs = {
|
|
# SMH Cloudflare provider will throw an error without preview config
|
|
preview = {
|
|
fail_open = false
|
|
}
|
|
production = {
|
|
kv_namespaces = {
|
|
UPTIMEFLARE_STATE = {
|
|
namespace_id = cloudflare_workers_kv_namespace.uptimeflare_kv.id
|
|
}
|
|
}
|
|
d1_databases = {
|
|
UPTIMEFLARE_D1 = {
|
|
id = cloudflare_d1_database.uptimeflare_d1.id
|
|
}
|
|
}
|
|
compatibility_date = "2025-04-02"
|
|
compatibility_flags = ["nodejs_compat"]
|
|
fail_open = false
|
|
}
|
|
}
|
|
|
|
# SMH it will error without this build_config
|
|
build_config = {
|
|
root_dir = "/"
|
|
}
|
|
}
|