Files
status/deploy.tf
T
michael cf977e65da Read the apps check address from a Worker secret (#5)
A monitor's target can be secret:NAME: the worker reads the address
from the Worker secret NAME at check time, bound in deploy.tf from the
GitHub Actions secret of the same name. The address never appears in
this repository, and any error text that mentions it is scrubbed before
it's stored or shown. Apps in US East now checks a real app this way.
2026-11-23 03:35:25 -05:00

111 lines
2.8 KiB
Terraform

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
}
# Cottage: private monitor addresses (see `secret:` targets in uptime.config.ts).
variable "APPS_US_EAST_TARGET" {
# read from $TF_VAR_APPS_US_EAST_TARGET (the GitHub Actions secret of the same name)
type = string
sensitive = true
}
variable "enable_do_migration" {
type = bool
default = false
}
resource "cloudflare_d1_database" "uptimeflare_d1" {
account_id = var.CLOUDFLARE_ACCOUNT_ID
name = "uptimeflare_d1"
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
}
}
migrations = var.enable_do_migration ? {
new_tag = "v1"
new_sqlite_classes = ["RemoteChecker"]
} : null
bindings = [{
name = "REMOTE_CHECKER_DO"
class_name = "RemoteChecker"
type = "durable_object_namespace"
}, {
name = "UPTIMEFLARE_D1"
type = "d1"
id = cloudflare_d1_database.uptimeflare_d1.id
}, {
name = "APPS_US_EAST_TARGET"
type = "secret_text"
text = var.APPS_US_EAST_TARGET
}]
}
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 write counts 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 = {
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 = "/"
}
}