-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.tf
More file actions
99 lines (87 loc) · 2.42 KB
/
Copy pathdeploy.tf
File metadata and controls
99 lines (87 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
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
}
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
}]
}
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 = "/"
}
}