@@ -11,36 +11,14 @@ provider "cloudflare" {
1111 api_token = var. cloudflare_api_token
1212}
1313
14- variable "account_id" {
15- type = string
16- }
17-
18- variable "cloudflare_api_token" {
19- type = string
20- sensitive = true
21- }
22-
23- # Add this block!
24- variable "zone_id" {
25- type = string
26- }
27-
2814# --- 1. The Documentation Site (Project A) ---
2915# Connects to the 'pywire/pywire' repo
3016resource "cloudflare_pages_project" "docs" {
3117 account_id = var. account_id
3218 name = " pywire-docs"
3319 production_branch = " main"
3420
35- source = {
36- type = " github"
37- config = {
38- owner = " pywire"
39- repo_name = " pywire"
40- production_deployment_enabled = true
41- pr_comments_enabled = true
42- }
43- }
21+
4422
4523 build_config = {
4624 root_dir = " docs"
@@ -54,15 +32,6 @@ resource "cloudflare_pages_project" "landing" {
5432 name = " pywire-landing"
5533 production_branch = " main"
5634
57- source = {
58- type = " github"
59- config = {
60- owner = " pywire"
61- repo_name = " pywire.dev"
62- production_deployment_enabled = true
63- }
64- }
65-
6635 build_config = {
6736 root_dir = " site"
6837 build_command = " pnpm run build"
@@ -79,9 +48,96 @@ resource "cloudflare_workers_script" "router" {
7948 main_module = " index.js"
8049}
8150
51+ # --- Nightly Environment ---
52+ # 1. DNS Record
53+ resource "cloudflare_dns_record" "nightly" {
54+ zone_id = var. zone_id
55+ name = " nightly"
56+ content = cloudflare_pages_project. landing . subdomain
57+ type = " CNAME"
58+ proxied = true
59+ ttl = 1
60+ }
61+
62+
63+
64+
8265# --- 4. The DNS & Routing ---
8366resource "cloudflare_workers_route" "catch_all" {
8467 zone_id = var. zone_id
8568 pattern = " pywire.dev/*"
8669 script = cloudflare_workers_script. router . script_name
8770}
71+
72+ resource "cloudflare_workers_route" "nightly" {
73+ zone_id = var. zone_id
74+ pattern = " nightly.pywire.dev/*"
75+ script = cloudflare_workers_script. router . script_name
76+ }
77+
78+ # --- 5. Email Routing Setup ---
79+
80+ resource "cloudflare_email_routing_settings" "main" {
81+ zone_id = var. zone_id
82+ }
83+
84+
85+
86+ # Destination Registration
87+ # Helper to find every unique email address across both variables
88+ locals {
89+ all_unique_emails = distinct (concat (
90+ values (var. forwarding_rules ),
91+ var. maintainer_emails
92+ ))
93+ }
94+
95+ # Register every email found in your variables
96+ resource "cloudflare_email_routing_address" "destinations" {
97+ for_each = toset (local. all_unique_emails )
98+ account_id = var. account_id
99+ email = each. value
100+ }
101+
102+ # Individual Rules
103+ resource "cloudflare_email_routing_rule" "individual_aliases" {
104+ for_each = var. forwarding_rules
105+
106+ zone_id = var. zone_id
107+ name = " Forward: ${ each . key } @"
108+ enabled = true
109+
110+ matchers = [{
111+ type = " literal"
112+ field = " to"
113+ value = " ${ each . key } @pywire.dev"
114+ }]
115+
116+ actions = [{
117+ type = " forward"
118+ # Look up the verified address resource
119+ value = [cloudflare_email_routing_address.destinations[each.value].email]
120+ }]
121+ }
122+
123+ # The Maintainers Group Rule
124+ resource "cloudflare_email_routing_rule" "maintainers_group" {
125+ zone_id = var. zone_id
126+ name = " Group: Maintainers"
127+ enabled = true
128+
129+ matchers = [{
130+ type = " literal"
131+ field = " to"
132+ value = " maintainers@pywire.dev"
133+ }]
134+
135+ actions = [{
136+ type = " forward"
137+ # Dynamically grab the verified email ID for everyone in the list
138+ value = [
139+ for email in var . maintainer_emails :
140+ cloudflare_email_routing_address.destinations[email].email
141+ ]
142+ }]
143+ }
0 commit comments