Skip to content

Commit 3505881

Browse files
authored
fix: add v4 to v5 inegration tests for workers_kv, workers_kv_namespace, r2_bucket (#39)
1 parent 2c44d36 commit 3505881

File tree

10 files changed

+2328
-129
lines changed

10 files changed

+2328
-129
lines changed
Lines changed: 182 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# ============================================================================
2+
# Standard Variables (Auto-provided by test infrastructure)
3+
# ============================================================================
14
variable "cloudflare_account_id" {
25
description = "Cloudflare account ID"
36
type = string
@@ -8,40 +11,203 @@ variable "cloudflare_zone_id" {
811
type = string
912
}
1013

11-
# Test Case 1: Basic R2 bucket with required fields only
12-
resource "cloudflare_r2_bucket" "basic" {
14+
# ============================================================================
15+
# Pattern Group 1: Locals for Common Values
16+
# ============================================================================
17+
locals {
18+
common_account = var.cloudflare_account_id
19+
name_prefix = "test-integration"
20+
locations = {
21+
"wnam" = "WNAM"
22+
"enam" = "ENAM"
23+
"weur" = "WEUR"
24+
"eeur" = "EEUR"
25+
"apac" = "APAC"
26+
"oc" = "OC"
27+
}
28+
enable_feature = true
29+
enable_test = false
30+
}
31+
32+
# ============================================================================
33+
# Pattern Group 2: Basic Resource Configurations
34+
# ============================================================================
35+
36+
# Test Case 1: Minimal bucket with only required fields
37+
resource "cloudflare_r2_bucket" "minimal" {
1338
account_id = var.cloudflare_account_id
14-
name = "test-bucket"
39+
name = "minimal-bucket"
1540
}
1641

17-
# Test Case 2: R2 bucket with location (uppercase - v4 style)
18-
resource "cloudflare_r2_bucket" "with_location_upper" {
42+
# Test Case 2: Bucket with all locations tested
43+
resource "cloudflare_r2_bucket" "location_wnam" {
1944
account_id = var.cloudflare_account_id
2045
name = "bucket-wnam"
2146
location = "WNAM"
2247
}
2348

24-
# Test Case 3: R2 bucket with location (must be uppercase)
25-
resource "cloudflare_r2_bucket" "with_location_lower" {
49+
resource "cloudflare_r2_bucket" "location_enam" {
50+
account_id = var.cloudflare_account_id
51+
name = "bucket-enam"
52+
location = "ENAM"
53+
}
54+
55+
resource "cloudflare_r2_bucket" "location_weur" {
56+
account_id = var.cloudflare_account_id
57+
name = "bucket-weur"
58+
location = "WEUR"
59+
}
60+
61+
resource "cloudflare_r2_bucket" "location_eeur" {
2662
account_id = var.cloudflare_account_id
2763
name = "bucket-eeur"
2864
location = "EEUR"
2965
}
3066

31-
# Test Case 4: R2 bucket with variable reference
32-
resource "cloudflare_r2_bucket" "with_variable" {
67+
resource "cloudflare_r2_bucket" "location_apac" {
3368
account_id = var.cloudflare_account_id
34-
name = "variable-bucket"
69+
name = "bucket-apac"
70+
location = "APAC"
3571
}
3672

37-
# Test Case 5: Multiple buckets with different configs
38-
resource "cloudflare_r2_bucket" "multi1" {
73+
resource "cloudflare_r2_bucket" "location_oc" {
3974
account_id = var.cloudflare_account_id
40-
name = "multi-bucket-1"
75+
name = "bucket-oc"
76+
location = "OC"
4177
}
4278

43-
resource "cloudflare_r2_bucket" "multi2" {
79+
# ============================================================================
80+
# Pattern Group 3: for_each with Maps
81+
# ============================================================================
82+
83+
resource "cloudflare_r2_bucket" "map_example" {
84+
for_each = {
85+
"data" = {
86+
name = "data-bucket"
87+
location = "WNAM"
88+
}
89+
"logs" = {
90+
name = "logs-bucket"
91+
location = "ENAM"
92+
}
93+
"backups" = {
94+
name = "backups-bucket"
95+
location = "WEUR"
96+
}
97+
}
98+
4499
account_id = var.cloudflare_account_id
45-
name = "multi-bucket-2"
46-
location = "APAC"
100+
name = each.value.name
101+
location = each.value.location
102+
}
103+
104+
# ============================================================================
105+
# Pattern Group 4: for_each with Sets
106+
# ============================================================================
107+
108+
resource "cloudflare_r2_bucket" "set_example" {
109+
for_each = toset([
110+
"alpha",
111+
"beta",
112+
"gamma",
113+
"delta",
114+
])
115+
116+
account_id = var.cloudflare_account_id
117+
name = "set-${each.value}-bucket"
118+
}
119+
120+
# ============================================================================
121+
# Pattern Group 5: count-based Resources
122+
# ============================================================================
123+
124+
resource "cloudflare_r2_bucket" "counted" {
125+
count = 3
126+
127+
account_id = var.cloudflare_account_id
128+
name = "counted-bucket-${count.index}"
129+
location = count.index == 0 ? "WNAM" : count.index == 1 ? "EEUR" : "APAC"
130+
}
131+
132+
# ============================================================================
133+
# Pattern Group 6: Conditional Creation
134+
# ============================================================================
135+
136+
resource "cloudflare_r2_bucket" "conditional_enabled" {
137+
count = local.enable_feature ? 1 : 0
138+
139+
account_id = var.cloudflare_account_id
140+
name = "conditional-enabled-bucket"
141+
location = "WNAM"
142+
}
143+
144+
resource "cloudflare_r2_bucket" "conditional_disabled" {
145+
count = local.enable_test ? 1 : 0
146+
147+
account_id = var.cloudflare_account_id
148+
name = "conditional-disabled-bucket"
149+
location = "EEUR"
150+
}
151+
152+
# ============================================================================
153+
# Pattern Group 7: Terraform Functions
154+
# ============================================================================
155+
156+
resource "cloudflare_r2_bucket" "with_functions" {
157+
account_id = var.cloudflare_account_id
158+
name = join("-", [local.name_prefix, "function", "test"])
159+
location = lookup(local.locations, "wnam", "WNAM")
160+
}
161+
162+
resource "cloudflare_r2_bucket" "with_interpolation" {
163+
account_id = local.common_account
164+
name = "${local.name_prefix}-interpolated-bucket"
165+
location = local.locations["eeur"]
166+
}
167+
168+
# ============================================================================
169+
# Pattern Group 8: Lifecycle Meta-Arguments
170+
# ============================================================================
171+
172+
resource "cloudflare_r2_bucket" "with_lifecycle" {
173+
account_id = var.cloudflare_account_id
174+
name = "lifecycle-test-bucket"
175+
location = "WNAM"
176+
177+
lifecycle {
178+
create_before_destroy = true
179+
}
180+
}
181+
182+
resource "cloudflare_r2_bucket" "with_prevent_destroy" {
183+
account_id = var.cloudflare_account_id
184+
name = "prevent-destroy-bucket"
185+
location = "EEUR"
186+
187+
lifecycle {
188+
prevent_destroy = false
189+
}
190+
}
191+
192+
# ============================================================================
193+
# Pattern Group 9: Edge Cases
194+
# ============================================================================
195+
196+
# Special characters in bucket names (hyphens and numbers)
197+
resource "cloudflare_r2_bucket" "special_chars" {
198+
account_id = var.cloudflare_account_id
199+
name = "bucket-with-dashes-and-numbers-123"
200+
}
201+
202+
# Long bucket name (testing near max length - 63 chars max)
203+
resource "cloudflare_r2_bucket" "long_name" {
204+
account_id = var.cloudflare_account_id
205+
name = "very-long-bucket-name-for-testing-migration-limits-max-len"
206+
}
207+
208+
# Bucket name with all allowed characters (lowercase, numbers, hyphens)
209+
resource "cloudflare_r2_bucket" "all_chars" {
210+
account_id = var.cloudflare_account_id
211+
name = "bucket-name-with-all-valid-chars-123-test"
212+
location = "WNAM"
47213
}

0 commit comments

Comments
 (0)