-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcloudflare.tf
96 lines (71 loc) · 2.05 KB
/
cloudflare.tf
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
# ---- Provider ----
# Cloudflare provider setup
provider "cloudflare" {
api_token = var.cloudflare_api_token
}
# ---- Resources ----
# D1 Database
resource "cloudflare_d1_database" "voting_app_database" {
account_id = var.cloudflare_account_id
name = "voting-app-sample-database"
}
# Turnstile Widget
resource "cloudflare_turnstile_widget" "voting_app_captcha" {
account_id = var.cloudflare_account_id
name = "voting-app-captcha"
domains = ["pages.dev"]
mode = "invisible"
region = "world"
}
# Pages Project
resource "cloudflare_pages_project" "voting_app" {
account_id = var.cloudflare_account_id
name = "voting-app"
source {
type = "github"
config {
owner = split("/", github_repository.demo_webapp.full_name)[0]
repo_name = split("/", github_repository.demo_webapp.full_name)[1]
pr_comments_enabled = true
deployments_enabled = true
production_deployment_enabled = true
production_branch = "main"
preview_deployment_setting = "none"
}
}
production_branch = "main"
build_config {
build_command = "npm run build"
destination_dir = "dist"
}
deployment_configs {
preview {
environment_variables = {
VITE_TURNSTILE_SITEKEY = cloudflare_turnstile_widget.voting_app_captcha.id
}
secrets = {
TURNSTILE_SECRET = cloudflare_turnstile_widget.voting_app_captcha.secret
}
d1_databases = {
DB = cloudflare_d1_database.voting_app_database.id
}
compatibility_flags = ["nodejs_compat"]
}
production {
environment_variables = {
VITE_TURNSTILE_SITEKEY = cloudflare_turnstile_widget.voting_app_captcha.id
}
secrets = {
TURNSTILE_SECRET = cloudflare_turnstile_widget.voting_app_captcha.secret
}
d1_databases = {
DB = cloudflare_d1_database.voting_app_database.id
}
compatibility_flags = ["nodejs_compat"]
}
}
}
# ---- Outputs ----
output "voting_app_url" {
value = cloudflare_pages_project.voting_app.subdomain
}