Skip to content

Commit

Permalink
add terraform deployment method
Browse files Browse the repository at this point in the history
  • Loading branch information
lyc8503 committed Nov 16, 2023
1 parent c275813 commit c5e8539
Show file tree
Hide file tree
Showing 7 changed files with 1,981 additions and 1,897 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,6 @@ yarn-error.log*
# typescript
*.tsbuildinfo
next-env.d.ts

.terraform/
terraform.tfstate*
25 changes: 25 additions & 0 deletions .terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# 🕒UptimeFlare
# UptimeFlare

Another **serverless (and free!)** uptime monitoring & status page on Cloudflare Workers with more advanced features and nice UI.

## ⭐Features

- **Opensource** & Easy to deploy (in 10 minutes without local tools) & Free
- **Opensource** & Easy to deploy (in 10 minutes) & Free

#### Monitoring

Expand Down
59 changes: 59 additions & 0 deletions deploy.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
terraform {
required_providers {
cloudflare = {
source = "cloudflare/cloudflare"
version = "~> 4"
}
}
}

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_worker_script" "uptimeflare" {
account_id = var.CLOUDFLARE_ACCOUNT_ID
name = "uptimeflare_worker"
content = file("worker/dist/index.js")
module = true
compatibility_date = "2023-11-08"

kv_namespace_binding {
name = "UPTIMEFLARE_STATE"
namespace_id = cloudflare_workers_kv_namespace.uptimeflare_kv.id
}
}

resource "cloudflare_worker_cron_trigger" "uptimeflare_worker_cron" {
account_id = var.CLOUDFLARE_ACCOUNT_ID
script_name = cloudflare_worker_script.uptimeflare.name
schedules = [
"*/2 * * * *", # every 2 minutes
]
}

resource "cloudflare_pages_project" "uptimeflare" {
account_id = var.CLOUDFLARE_ACCOUNT_ID
name = "uptimeflare"
production_branch = "main"

deployment_configs {
production {
kv_namespaces = {
UPTIMEFLARE_STATE = cloudflare_workers_kv_namespace.uptimeflare_kv.id
}
compatibility_date = "2023-11-08"
compatibility_flags = ["nodejs_compat"]
}
}
}
Loading

0 comments on commit c5e8539

Please sign in to comment.