Skip to content

Commit f4832fa

Browse files
committed
Deploying to release from @ 77c37d5 🚀
1 parent d7cc6ce commit f4832fa

15 files changed

Lines changed: 5303 additions & 0 deletions

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
.wrangler
3+
wrangler.toml

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# api-gateway
2+

cloudflare.tf

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
resource "cloudflare_workers_domain" "worker_project_domain" {
2+
account_id = var.cloudflare_account_id
3+
hostname = "${var.project_name}.${var.environment}.${var.domain}"
4+
service = "${var.project_name}-${var.environment}"
5+
zone_id = var.cloudflare_zone_id
6+
7+
depends_on = [cloudflare_workers_script.project_script]
8+
}
9+
10+
resource "cloudflare_workers_route" "project_route" {
11+
zone_id = var.cloudflare_zone_id
12+
pattern = "${var.project_name}.${var.environment}.${var.domain}/*"
13+
script_name = cloudflare_workers_script.project_script.name
14+
}
15+
16+
resource "cloudflare_workers_kv_namespace" "settings" {
17+
account_id = var.cloudflare_account_id
18+
title = "${var.project_name}-${var.environment}-settings"
19+
}
20+
21+
resource "cloudflare_workers_script" "project_script" {
22+
account_id = var.cloudflare_account_id
23+
name = "${var.project_name}-${var.environment}"
24+
content = file("${path.module}/dist/index.mjs")
25+
compatibility_date = "2023-08-28"
26+
module = true
27+
28+
kv_namespace_binding {
29+
name = "SETTINGS"
30+
namespace_id = cloudflare_workers_kv_namespace.settings.id
31+
}
32+
33+
plain_text_binding {
34+
name = "CORS_DOMAINS"
35+
text = var.ALLOWED_HOSTS
36+
}
37+
38+
plain_text_binding {
39+
name = "DOMAIN"
40+
text = var.domain
41+
}
42+
43+
plain_text_binding {
44+
name = "ENVIRONMENT"
45+
text = var.environment
46+
}
47+
48+
plain_text_binding {
49+
name = "GCP_LOGGING_PROJECT_ID"
50+
text = var.GCP_LOGGING_PROJECT_ID
51+
}
52+
53+
plain_text_binding {
54+
name = "GCP_BIGQUERY_PROJECT_ID"
55+
text = var.GCP_BIGQUERY_PROJECT_ID
56+
}
57+
plain_text_binding {
58+
name = "LOG_NAME"
59+
text = "${var.project_name}_${var.environment}_worker_log"
60+
}
61+
62+
plain_text_binding {
63+
name = "VERSION"
64+
text = var.VERSION
65+
}
66+
67+
secret_text_binding {
68+
name = "GCP_LOGGING_CREDENTIALS"
69+
text = var.GCP_LOGGING_CREDENTIALS
70+
}
71+
72+
secret_text_binding {
73+
name = "GCP_BIGQUERY_CREDENTIALS"
74+
text = var.GCP_BIGQUERY_CREDENTIALS
75+
}
76+
77+
secret_text_binding {
78+
name = "GCP_USERINFO_CREDENTIALS"
79+
text = var.GCP_USERINFO_CREDENTIALS
80+
}
81+
82+
secret_text_binding {
83+
name = "GLOBAL_SHARED_SECRET"
84+
text = var.GLOBAL_SHARED_SECRET
85+
}
86+
87+
d1_database_binding {
88+
name = "${var.project_name}_${var.environment}_cache"
89+
database_id = "${data.local_file.load_api_gateway_cache_id.content}"
90+
}
91+
}

cloudflare_d1_ids.tf

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// api_gateway_prod_cache
2+
resource "null_resource" "d1_api_gateway_cache_id" {
3+
triggers = {
4+
always_run = timestamp()
5+
}
6+
7+
provisioner "local-exec" {
8+
command = "${path.module}/scripts/get_d1_id.sh"
9+
environment = {
10+
d1_name = "api-gateway_${var.environment}_cache"
11+
cloudflare_account_id = var.cloudflare_account_id
12+
cloudflare_token = var.cloudflare_token
13+
}
14+
}
15+
}
16+
17+
data "local_file" "load_api_gateway_cache_id" {
18+
filename = "${path.module}/api-gateway_${var.environment}_cache"
19+
depends_on = [null_resource.d1_api_gateway_cache_id]
20+
}

0 commit comments

Comments
 (0)