Skip to content

Commit 914f7a8

Browse files
tamas-jozsaclaude
andauthored
Add Local Provider Testing Support for Migration E2E Tests & improve integration tests (#47)
* feat: add comprehensive e2e tests * fix: preserve schedule and match blocks with dynamic refs in device posture migration This commit fixes two critical drift issues in the zero_trust_device_posture_rule v4 to v5 migration: 1. Schedule field drift (affected 14 resources) - Removed logic that deleted schedule = "5m" from state - The v5 provider returns this value from API, so removing it caused drift - Now preserved in state to match v5 API behavior 2. Match blocks with dynamic references (affected 5+ resources) - Fixed MergeAttributeAndBlocksToObjectArray to preserve dynamic references - Previously, match blocks with each.value.platform or var.platform were completely removed - Added extractTokensFromBlock helper to preserve HCL tokens (variables, interpolations, functions) - Now correctly transforms match blocks to arrays while preserving dynamic expressions Additional changes: - Added 3 unit tests for match blocks with dynamic references - Updated integration testdata to include preserved schedule and match arrays - Added E2E test Step 4 to verify stable state after v5 apply - E2E script now exits with error if ongoing drift is detected 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * feat(e2e): add local provider support and update test expectations Add ability to test migrations with locally built provider binary, and update test data to reflect current provider behavior. Changes: - Add --provider flag to run-e2e-tests script for local provider testing - Verifies provider binary exists before running tests - Creates .terraformrc-tf-migrate with dev_overrides automatically - Applies dev overrides only to v5 tests (v4 uses registry provider) - Update zero_trust_gateway_policy migration logic for v5 schema changes - Update test expectations for logpull_retention, zero_trust_gateway_policy, and zero_trust_list to match current provider output The --provider flag enables rapid iteration when fixing provider issues: ./scripts/run-e2e-tests --provider /path/to/cloudflare-terraform-next This allows testing provider fixes during migration without waiting for provider releases, while keeping v4 tests using stable registry versions. --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 3505881 commit 914f7a8

File tree

22 files changed

+4480
-1415
lines changed

22 files changed

+4480
-1415
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
tf-migrate
2+
.terraformrc-tf-migrate
3+
4+
# Local provider dev overrides
5+
.terraformrc-tf-migrate
26

37
# E2E test files
48
# Ignore v4 directory except provider.tf and backend.hcl
Lines changed: 7 additions & 206 deletions
Original file line numberDiff line numberDiff line change
@@ -1,218 +1,19 @@
11
# 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
123

134
variable "cloudflare_zone_id" {
145
description = "Cloudflare zone ID"
156
type = string
167
}
178

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
16512
}
16613

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" {
17317
zone_id = var.cloudflare_zone_id
17418
flag = true
17519
}
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

Comments
 (0)