Skip to content

Commit fb0c533

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

File tree

9 files changed

+2960
-3
lines changed

9 files changed

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

0 commit comments

Comments
 (0)