|
1 | 1 | # Integration Test for cloudflare_logpull_retention v4 → v5 Migration |
2 | | -# This file tests ALL Terraform patterns as required by subtask 08 |
3 | | - |
4 | | -# ============================================================================ |
5 | | -# Pattern Group 1: Variables & Locals (Required by Subtask 08) |
6 | | -# ============================================================================ |
7 | | - |
8 | | -variable "cloudflare_account_id" { |
9 | | - description = "Cloudflare account ID" |
10 | | - type = string |
11 | | -} |
| 2 | +# Simplified to single resource since logpull_retention is a zone-level setting |
12 | 3 |
|
13 | 4 | variable "cloudflare_zone_id" { |
14 | 5 | description = "Cloudflare zone ID" |
15 | 6 | type = string |
16 | 7 | } |
17 | 8 |
|
18 | | -locals { |
19 | | - common_zone = var.cloudflare_zone_id |
20 | | - name_prefix = "test-integration" |
21 | | - tags = ["test", "migration", "v4_to_v5"] |
22 | | - enable_feature = true |
23 | | - enable_test = false |
24 | | - zone_count = 3 |
25 | | -} |
26 | | - |
27 | | -# ============================================================================ |
28 | | -# Pattern Group 2: for_each with Maps (3-5 resources) |
29 | | -# ============================================================================ |
30 | | - |
31 | | -resource "cloudflare_logpull_retention" "map_example" { |
32 | | - for_each = { |
33 | | - "zone1" = { |
34 | | - zone_id = var.cloudflare_zone_id |
35 | | - enabled = true |
36 | | - } |
37 | | - "zone2" = { |
38 | | - zone_id = var.cloudflare_zone_id |
39 | | - enabled = false |
40 | | - } |
41 | | - "zone3" = { |
42 | | - zone_id = var.cloudflare_zone_id |
43 | | - enabled = true |
44 | | - } |
45 | | - "zone4" = { |
46 | | - zone_id = var.cloudflare_zone_id |
47 | | - enabled = false |
48 | | - } |
49 | | - } |
50 | | - |
51 | | - zone_id = each.value.zone_id |
52 | | - flag = each.value.enabled |
53 | | -} |
54 | | - |
55 | | -# ============================================================================ |
56 | | -# Pattern Group 3: for_each with Sets (3-5 items) |
57 | | -# ============================================================================ |
58 | | - |
59 | | -resource "cloudflare_logpull_retention" "set_example" { |
60 | | - for_each = toset([ |
61 | | - "alpha", |
62 | | - "beta", |
63 | | - "gamma", |
64 | | - "delta" |
65 | | - ]) |
66 | | - |
67 | | - zone_id = var.cloudflare_zone_id |
68 | | - flag = each.key == "alpha" || each.key == "gamma" ? true : false |
69 | | -} |
70 | | - |
71 | | -# ============================================================================ |
72 | | -# Pattern Group 4: count-based Resources (at least 3) |
73 | | -# ============================================================================ |
74 | | - |
75 | | -resource "cloudflare_logpull_retention" "counted" { |
76 | | - count = 3 |
77 | | - |
78 | | - zone_id = var.cloudflare_zone_id |
79 | | - flag = count.index % 2 == 0 ? true : false |
80 | | -} |
81 | | - |
82 | | -# ============================================================================ |
83 | | -# Pattern Group 5: Conditional Creation |
84 | | -# ============================================================================ |
85 | | - |
86 | | -resource "cloudflare_logpull_retention" "conditional_enabled" { |
87 | | - count = local.enable_feature ? 1 : 0 |
88 | | - |
89 | | - zone_id = var.cloudflare_zone_id |
90 | | - flag = true |
91 | | -} |
92 | | - |
93 | | -resource "cloudflare_logpull_retention" "conditional_disabled" { |
94 | | - count = local.enable_test ? 1 : 0 |
95 | | - |
96 | | - zone_id = var.cloudflare_zone_id |
97 | | - flag = false |
98 | | -} |
99 | | - |
100 | | -# ============================================================================ |
101 | | -# Pattern Group 6: Terraform Functions |
102 | | -# ============================================================================ |
103 | | - |
104 | | -resource "cloudflare_logpull_retention" "with_functions" { |
105 | | - zone_id = var.cloudflare_zone_id |
106 | | - flag = true |
107 | | -} |
108 | | - |
109 | | -resource "cloudflare_logpull_retention" "with_interpolation" { |
110 | | - zone_id = "${var.cloudflare_zone_id}" # String interpolation |
111 | | - flag = false |
112 | | -} |
113 | | - |
114 | | -# ============================================================================ |
115 | | -# Pattern Group 7: Lifecycle Meta-Arguments |
116 | | -# ============================================================================ |
117 | | - |
118 | | -resource "cloudflare_logpull_retention" "with_lifecycle" { |
119 | | - zone_id = var.cloudflare_zone_id |
120 | | - |
121 | | - lifecycle { |
122 | | - create_before_destroy = true |
123 | | - } |
124 | | - flag = true |
125 | | -} |
126 | | - |
127 | | -resource "cloudflare_logpull_retention" "with_ignore_changes" { |
128 | | - zone_id = local.common_zone |
129 | | - |
130 | | - lifecycle { |
131 | | - ignore_changes = [flag] |
132 | | - } |
133 | | - flag = false |
134 | | -} |
135 | | - |
136 | | -resource "cloudflare_logpull_retention" "with_prevent_destroy" { |
137 | | - zone_id = var.cloudflare_zone_id |
138 | | - |
139 | | - lifecycle { |
140 | | - prevent_destroy = false # Set to false for testing |
141 | | - } |
142 | | - flag = true |
143 | | -} |
144 | | - |
145 | | -# ============================================================================ |
146 | | -# Pattern Group 8: Edge Cases |
147 | | -# ============================================================================ |
148 | | - |
149 | | -# Minimal resource (only required fields) |
150 | | -resource "cloudflare_logpull_retention" "minimal" { |
151 | | - zone_id = var.cloudflare_zone_id |
152 | | - flag = true |
153 | | -} |
154 | | - |
155 | | -# Using locals reference |
156 | | -resource "cloudflare_logpull_retention" "with_local" { |
157 | | - zone_id = local.common_zone |
158 | | - flag = local.enable_feature |
159 | | -} |
160 | | - |
161 | | -# Complex conditional expression |
162 | | -resource "cloudflare_logpull_retention" "complex_conditional" { |
163 | | - zone_id = var.cloudflare_zone_id |
164 | | - flag = local.enable_feature && !local.enable_test ? true : false |
| 9 | +variable "cloudflare_account_id" { |
| 10 | + description = "Cloudflare account ID" |
| 11 | + type = string |
165 | 12 | } |
166 | 13 |
|
167 | | -# ============================================================================ |
168 | | -# Pattern Group 9: Additional Real-World Patterns |
169 | | -# ============================================================================ |
170 | | - |
171 | | -# Testing enabled=true explicitly |
172 | | -resource "cloudflare_logpull_retention" "enabled_explicit" { |
| 14 | +# Single logpull retention resource |
| 15 | +# Tests the basic enabled → flag migration |
| 16 | +resource "cloudflare_logpull_retention" "basic" { |
173 | 17 | zone_id = var.cloudflare_zone_id |
174 | 18 | flag = true |
175 | 19 | } |
176 | | - |
177 | | -# Testing enabled=false explicitly |
178 | | -resource "cloudflare_logpull_retention" "disabled_explicit" { |
179 | | - zone_id = var.cloudflare_zone_id |
180 | | - flag = false |
181 | | -} |
182 | | - |
183 | | -# Using ternary operator |
184 | | -resource "cloudflare_logpull_retention" "ternary_true" { |
185 | | - zone_id = var.cloudflare_zone_id |
186 | | - flag = 1 == 1 ? true : false |
187 | | -} |
188 | | - |
189 | | -resource "cloudflare_logpull_retention" "ternary_false" { |
190 | | - zone_id = var.cloudflare_zone_id |
191 | | - flag = 1 == 2 ? true : false |
192 | | -} |
193 | | - |
194 | | -# ============================================================================ |
195 | | -# Summary: |
196 | | -# - Total resource declarations: 18 |
197 | | -# - Total instances created: |
198 | | -# - map_example: 4 instances |
199 | | -# - set_example: 4 instances |
200 | | -# - counted: 3 instances |
201 | | -# - conditional_enabled: 1 instance |
202 | | -# - conditional_disabled: 0 instances (count = 0) |
203 | | -# - Others: 11 instances |
204 | | -# TOTAL: 4 + 4 + 3 + 1 + 0 + 11 = 23 instances |
205 | | -# |
206 | | -# Patterns covered: |
207 | | -# ✓ Variables (cloudflare_account_id, cloudflare_zone_id) |
208 | | -# ✓ Locals (common_zone, enable_feature, enable_test) |
209 | | -# ✓ for_each with maps (4 resources) |
210 | | -# ✓ for_each with sets using toset() (4 resources) |
211 | | -# ✓ count-based resources (3 resources) |
212 | | -# ✓ Conditional creation with ternary operator |
213 | | -# ✓ String interpolation |
214 | | -# ✓ Lifecycle meta-arguments (create_before_destroy, ignore_changes, prevent_destroy) |
215 | | -# ✓ Terraform functions (toset()) |
216 | | -# ✓ Edge cases (minimal config, complex conditionals) |
217 | | -# ✓ Boolean values (both true and false) |
218 | | -# ============================================================================ |
0 commit comments