Skip to content

Commit 8c403f5

Browse files
committed
feat: Add migration logic and tests for cloudflare_pages_project resource
1 parent 3505881 commit 8c403f5

File tree

9 files changed

+3033
-3
lines changed

9 files changed

+3033
-3
lines changed

integration/v4_to_v5/integration_test.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,25 @@ import (
55
"testing"
66

77
"github.com/cloudflare/tf-migrate/integration"
8-
"github.com/cloudflare/tf-migrate/internal/registry"
8+
9+
// Explicitly import the migrations we want to test
10+
_ "github.com/cloudflare/tf-migrate/internal/resources/account_member"
11+
_ "github.com/cloudflare/tf-migrate/internal/resources/api_token"
12+
_ "github.com/cloudflare/tf-migrate/internal/resources/dns_record"
13+
_ "github.com/cloudflare/tf-migrate/internal/resources/logpull_retention"
14+
_ "github.com/cloudflare/tf-migrate/internal/resources/pages_project"
15+
_ "github.com/cloudflare/tf-migrate/internal/resources/r2_bucket"
16+
_ "github.com/cloudflare/tf-migrate/internal/resources/workers_kv"
17+
_ "github.com/cloudflare/tf-migrate/internal/resources/workers_kv_namespace"
18+
_ "github.com/cloudflare/tf-migrate/internal/resources/zero_trust_access_service_token"
19+
_ "github.com/cloudflare/tf-migrate/internal/resources/zero_trust_dlp_custom_profile"
20+
_ "github.com/cloudflare/tf-migrate/internal/resources/zero_trust_gateway_policy"
21+
_ "github.com/cloudflare/tf-migrate/internal/resources/zero_trust_list"
922
)
1023

1124
// TestMain explicitly registers migrations for this version path
1225
func TestMain(m *testing.M) {
1326
// Explicitly register the migrations for v4 to v5
14-
// This is called once before all tests in this package
15-
registry.RegisterAllMigrations()
1627

1728
// Run the tests
1829
code := m.Run()
Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
# ========================================
2+
# Variables
3+
# ========================================
4+
variable "cloudflare_account_id" {
5+
description = "Cloudflare account ID"
6+
type = string
7+
}
8+
9+
variable "cloudflare_zone_id" {
10+
description = "Cloudflare zone ID"
11+
type = string
12+
}
13+
14+
# Test Case 1: Minimal Pages Project
15+
resource "cloudflare_pages_project" "minimal" {
16+
account_id = var.cloudflare_account_id
17+
name = "minimal-project"
18+
production_branch = "main"
19+
build_config = {}
20+
deployment_configs = {
21+
preview = {
22+
compatibility_flags = []
23+
usage_model = "bundled"
24+
fail_open = false
25+
}
26+
production = {
27+
compatibility_flags = []
28+
fail_open = false
29+
usage_model = "bundled"
30+
}
31+
}
32+
}
33+
34+
# Test Case 2: Pages Project with build_config block
35+
resource "cloudflare_pages_project" "with_build_config" {
36+
account_id = var.cloudflare_account_id
37+
name = "project-with-build"
38+
production_branch = "main"
39+
40+
build_config = {
41+
build_command = "npm run build"
42+
destination_dir = "public"
43+
root_dir = "/"
44+
web_analytics_tag = "abc123"
45+
web_analytics_token = "token123"
46+
}
47+
deployment_configs = {
48+
preview = {
49+
compatibility_flags = []
50+
usage_model = "bundled"
51+
fail_open = false
52+
}
53+
production = {
54+
compatibility_flags = []
55+
fail_open = false
56+
usage_model = "bundled"
57+
}
58+
}
59+
}
60+
61+
# Test Case 3: Pages Project with source and config blocks
62+
resource "cloudflare_pages_project" "with_source" {
63+
account_id = var.cloudflare_account_id
64+
name = "project-with-source"
65+
production_branch = "main"
66+
67+
#source {
68+
# type = "github"
69+
#
70+
# config {
71+
# owner = "cloudflare"
72+
# repo_name = "test-repo"
73+
# production_branch = "main"
74+
# pr_comments_enabled = true
75+
# deployments_enabled = true
76+
# production_deployment_enabled = true
77+
# preview_deployment_setting = "custom"
78+
# preview_branch_includes = ["dev", "staging"]
79+
# preview_branch_excludes = ["temp"]
80+
# }
81+
# }
82+
build_config = {}
83+
deployment_configs = {
84+
preview = {
85+
compatibility_flags = []
86+
usage_model = "bundled"
87+
fail_open = false
88+
}
89+
production = {
90+
compatibility_flags = []
91+
fail_open = false
92+
usage_model = "bundled"
93+
}
94+
}
95+
}
96+
97+
# Test Case 4: Pages Project with deployment_configs
98+
resource "cloudflare_pages_project" "with_deployment_configs" {
99+
account_id = var.cloudflare_account_id
100+
name = "project-with-deployments"
101+
production_branch = "main"
102+
103+
build_config = {}
104+
deployment_configs = {
105+
preview = {
106+
compatibility_date = "2024-01-01"
107+
compatibility_flags = ["nodejs_compat"]
108+
usage_model = "bundled"
109+
fail_open = false
110+
placement = {
111+
mode = "smart"
112+
}
113+
}
114+
production = {
115+
compatibility_date = "2024-01-01"
116+
compatibility_flags = ["nodejs_compat", "streams_enable_constructors"]
117+
usage_model = "bundled"
118+
fail_open = false
119+
placement = {
120+
mode = "smart"
121+
}
122+
}
123+
}
124+
}
125+
126+
# Test Case 5: Full Pages Project with all features
127+
resource "cloudflare_pages_project" "full" {
128+
account_id = var.cloudflare_account_id
129+
name = "full-project"
130+
production_branch = "main"
131+
132+
133+
#source {
134+
# type = "github"
135+
#
136+
# config {
137+
# owner = "my-org"
138+
# repo_name = "my-app"
139+
# production_branch = "main"
140+
# production_deployment_enabled = true
141+
# pr_comments_enabled = true
142+
# }
143+
# }
144+
145+
build_config = {
146+
build_command = "npm run build"
147+
destination_dir = "dist"
148+
root_dir = "/app"
149+
}
150+
deployment_configs = {
151+
preview = {
152+
compatibility_date = "2024-01-01"
153+
compatibility_flags = []
154+
usage_model = "bundled"
155+
fail_open = false
156+
placement = {
157+
mode = "smart"
158+
}
159+
}
160+
production = {
161+
compatibility_date = "2024-01-01"
162+
compatibility_flags = []
163+
fail_open = false
164+
usage_model = "bundled"
165+
placement = {
166+
mode = "smart"
167+
}
168+
}
169+
}
170+
}
171+
172+
# Test Case 6: Project with only deployment configs (no build/source)
173+
resource "cloudflare_pages_project" "deployment_only" {
174+
account_id = var.cloudflare_account_id
175+
name = "deployment-only"
176+
production_branch = "main"
177+
178+
build_config = {}
179+
deployment_configs = {
180+
preview = {
181+
compatibility_date = "2024-01-15"
182+
compatibility_flags = []
183+
usage_model = "bundled"
184+
fail_open = false
185+
placement = {
186+
mode = "smart"
187+
}
188+
}
189+
production = {
190+
compatibility_date = "2024-01-15"
191+
compatibility_flags = []
192+
fail_open = false
193+
usage_model = "bundled"
194+
placement = {
195+
mode = "smart"
196+
}
197+
}
198+
}
199+
}

0 commit comments

Comments
 (0)