Skip to content

Add Local Provider Testing Support for Migration E2E Tests & improve integration tests#47

Merged
tamas-jozsa merged 3 commits intomainfrom
comprehensive-tests
Dec 2, 2025
Merged

Add Local Provider Testing Support for Migration E2E Tests & improve integration tests#47
tamas-jozsa merged 3 commits intomainfrom
comprehensive-tests

Conversation

@tamas-jozsa
Copy link
Collaborator

@tamas-jozsa tamas-jozsa commented Nov 28, 2025

Summary

This PR adds the ability to test v4→v5 migrations with a locally built
provider binary, enabling rapid iteration when fixing provider issues
discovered during migration testing. Additionally includes updated test
expectations to match current provider behavior.

Motivation

During migration testing, we discovered several provider issues causing
drift:

  • Device posture rule input.version not being persisted
  • Gateway policy fields showing as (known after apply)
  • Need to test provider fixes without waiting for releases

Previously, testing provider fixes required:

  1. Make provider change
  2. Publish provider to registry
  3. Update E2E tests to use new version
  4. Run tests

This was slow and cumbersome for iterative development.

Changes

1. Local Provider Testing Support

New Feature: --provider flag for run-e2e-tests script

./scripts/run-e2e-tests --provider /path/to/cloudflare-terraform-next

How it works:

  • Verifies provider binary exists (shows helpful error if not built)
  • Auto-creates .terraformrc-tf-migrate with dev overrides
  • Applies dev overrides only to v5 tests (v4 uses registry for
    compatibility)
  • Configures TF_CLI_CONFIG_FILE per-command, not globally

Benefits:

  • ✅ Test provider fixes immediately after go build
  • ✅ No manual config file management
  • ✅ v4 tests stay on stable registry versions
  • ✅ Clear visual confirmation when local provider is in use

2. Migration Logic Updates

File: internal/resources/zero_trust_gateway_policy/v4_to_v5.go

Updated migration logic to handle v5 provider schema changes for gateway
policies.

3. Test Data Updates

Updated test expectations for resources that changed behavior:

  • logpull_retention - Current provider output
  • zero_trust_gateway_policy - v5 schema changes
  • zero_trust_list - Current provider behavior

Usage Examples

Test with local provider:

  # 1. Build provider
  cd /path/to/cloudflare-terraform-next
  go build .
  # 2. Run E2E tests with local provider
  cd /path/to/tf-migrate
  ./scripts/run-e2e-tests --provider /path/to/cloudflare-terraform-next
  Test specific resource:
  ./scripts/run-e2e-tests \
    --provider ~/cloudflare-terraform-next \
    --resources zero_trust_device_posture_rule

@tamas-jozsa tamas-jozsa changed the title Comprehensive tests Add Local Provider Testing Support for Migration E2E Tests & improve integration tests Nov 28, 2025
@@ -1,218 +1,19 @@
# Integration Test for cloudflare_logpull_retention v4 → v5 Migration
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is no point in having complex test cases for this very simple resource, so I cleaned them up

@tamas-jozsa tamas-jozsa force-pushed the comprehensive-tests branch 2 times, most recently from bb701f9 to 6b67cdd Compare December 2, 2025 16:23
tamas-jozsa and others added 3 commits December 2, 2025 16:25
…osture 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>
  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.
@tamas-jozsa tamas-jozsa merged commit 914f7a8 into main Dec 2, 2025
4 checks passed
@tamas-jozsa tamas-jozsa deleted the comprehensive-tests branch December 2, 2025 16:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants