Skip to content

feat: Add migration logic and tests for cloudflare_pages_project#48

Merged
tamas-jozsa merged 1 commit intomainfrom
rotem/cloudflare-pages-project-migration
Dec 4, 2025
Merged

feat: Add migration logic and tests for cloudflare_pages_project#48
tamas-jozsa merged 1 commit intomainfrom
rotem/cloudflare-pages-project-migration

Conversation

@rotem-cloud
Copy link
Collaborator

@rotem-cloud rotem-cloud commented Dec 1, 2025

feat: Add migration logic and tests for cloudflare_pages_project resource

Summary

Implements v4 to v5 migration support for the cloudflare_pages_project resource, including comprehensive configuration and state transformations with full test coverage.

Changes

Migration Implementation

  • Configuration Transformations:

    • Converts nested blocks to attributes (build_config, source, deployment_configs)
    • Renames production_deployment_enabled to production_deployments_enabled in source.config
    • Adds default values for compatibility_flags, usage_model, fail_open, and placement in deployment_configs
    • Converts placement block to attribute syntax
    • Only includes placement when explicitly set (not empty)
  • State Transformations:

    • Converts TypeList MaxItems:1 arrays to objects for build_config, source, and deployment_configs
    • Merges environment_variables and secrets into unified env_vars with type/value structure
    • Converts service_binding blocks to services map (extracts name as key)
    • Wraps TypeMap values in objects (kv_namespaces, d1_databases, r2_buckets)
    • Populates new v5-only fields: canonical_deployment, framework, framework_version, latest_deployment, uses_functions
    • Removes deprecated fields: domains

Test Coverage

  • Unit Tests (18 test cases):

    • Config transformation tests for all resource variations
    • State transformation tests for array-to-object conversions and field merging
    • Default value handling tests for usage_model and fail_open
  • Integration Tests:

    • 6 test cases covering minimal, build_config, source, deployment_configs, full, and deployment-only scenarios
    • Input and expected output Terraform configurations
    • Input and expected output state files

Helper Functions

  • Added AttributeValueContainsKey function to check for nested keys in HCL attributes

Registry

  • Registered pages_project migrator in the migration registry

Known Limitations

  • Source block with external Git integration: The source block with GitHub/GitLab configuration is commented out in integration test files because it requires external authentication and repository access. The migration logic handles source transformations correctly (tested in unit tests), but live integration testing with actual Git repositories is not feasible in automated test environments.

Files Modified

  • internal/resources/pages_project/v4_to_v5.go (644 lines added)
  • internal/resources/pages_project/v4_to_v5_test.go (1287 lines added)
  • internal/transform/hcl/attributes.go (27 lines added)
  • internal/registry/registry.go (2 lines modified)
  • integration/v4_to_v5/integration_test.go (17 lines modified)
  • Integration test data files (pages_project input/expected .tf and .tfstate files)

Testing

All unit tests (18/18) and integration tests (6/6) pass successfully.

@rotem-cloud rotem-cloud force-pushed the rotem/cloudflare-pages-project-migration branch 2 times, most recently from 8c403f5 to 4a9eac6 Compare December 3, 2025 00:06
@rotem-cloud rotem-cloud force-pushed the rotem/cloudflare-pages-project-migration branch from 4a9eac6 to bf3a98a Compare December 3, 2025 00:34
@tamas-jozsa tamas-jozsa merged commit e6c27e0 into main Dec 4, 2025
30 of 42 checks passed
@tamas-jozsa tamas-jozsa deleted the rotem/cloudflare-pages-project-migration branch December 4, 2025 14:34
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.

3 participants