Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 4 additions & 18 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,8 @@ jobs:
go mod download
go mod tidy

- name: Run unit tests with coverage
run: |
go test -v -race -coverprofile=coverage.out -covermode=atomic ./internal/...
go test -v -race ./cmd/...

- name: Generate coverage report
run: |
echo "Coverage Report:"
go tool cover -func=coverage.out
- name: Run unit tests
run: make test-unit
Copy link
Collaborator

Choose a reason for hiding this comment

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

nice


lint-testdata:
name: Lint Testdata Naming
Expand Down Expand Up @@ -82,12 +75,5 @@ jobs:
go mod download
go mod tidy

- name: Build tf-migrate
run: |
make build
./bin/tf-migrate version

- name: Run integration tests for v4 to v5
run: |
cd integration/v4_to_v5
go test -v -race -timeout 10m
- name: Run integration tests
run: make test-integration
17 changes: 10 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ GO := go
MAIN_PACKAGE := ./cmd/tf-migrate
E2E_PACKAGE := ./cmd/e2e-runner

.PHONY: all build build-e2e build-all test test-e2e lint-testdata clean
.PHONY: all build build-e2e build-all test test-unit test-integration lint-testdata clean

# Default target: build all binaries
all: build-all
Expand All @@ -24,13 +24,16 @@ build-e2e:
# Build both binaries
build-all: build build-e2e

# Run tests
test:
# Run all tests (unit + e2e + integration)
test: test-unit test-integration

# Run unit tests
test-unit:
$(GO) test -v -race ./internal/...

# Run e2e-runner tests only
test-e2e:
$(GO) test -v -race ./internal/e2e-runner
# Run integration tests
test-integration:
$(GO) test -v -race ./integration/...

# Lint testdata to ensure all resources have cftftest prefix
lint-testdata:
Expand All @@ -42,4 +45,4 @@ clean:
@echo "Cleaning build artifacts..."
@rm -rf bin/
@rm -f tf-migrate e2e-runner
@echo "Clean complete"
@echo "Clean complete"
10 changes: 1 addition & 9 deletions e2e/drift-exemptions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ exemptions:
description: "Ignore attributes that refresh to 'known after apply'"
patterns:
- "(known after apply)"
- '= \{\} -> null'
enabled: true

# Ignore status changes to "active" (common for DNSSEC resources)
Expand All @@ -20,15 +21,6 @@ exemptions:
- 'status.*->.*"active"'
enabled: true

# Ignore empty nested objects being normalized to null in access policy condition elements
- name: "access_policy_empty_objects_to_null"
description: "Empty nested objects in condition elements normalized to null (terraform init behavior)"
resource_types:
- "cloudflare_zero_trust_access_policy"
patterns:
- '= \{\} -> null'
enabled: true

# Ignore nested object restructuring in access policy condition elements
- name: "access_policy_nested_object_restructuring"
description: "Nested objects in condition elements being restructured (empty object removal)"
Expand Down
2 changes: 2 additions & 0 deletions integration/v4_to_v5/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
_ "github.com/cloudflare/tf-migrate/internal/resources/custom_pages"
_ "github.com/cloudflare/tf-migrate/internal/resources/dns_record"
_ "github.com/cloudflare/tf-migrate/internal/resources/healthcheck"
_ "github.com/cloudflare/tf-migrate/internal/resources/load_balancer"
_ "github.com/cloudflare/tf-migrate/internal/resources/load_balancer_pool"
_ "github.com/cloudflare/tf-migrate/internal/resources/logpull_retention"
_ "github.com/cloudflare/tf-migrate/internal/resources/managed_transforms"
_ "github.com/cloudflare/tf-migrate/internal/resources/page_rule"
Expand Down
136 changes: 136 additions & 0 deletions integration/v4_to_v5/testdata/load_balancer/expected/load_balancer.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
# Minimal load_balancer testdata for v4 to v5 migration
# This file uses v4 schema which has major breaking changes in v5

# Variables for DRY configuration
variable "cloudflare_account_id" {
type = string
default = "f037e56e89293a057740de681ac9abbe"
}

variable "cloudflare_zone_id" {
type = string
default = "0da42c8d2132a9ddaf714f9e7c920711"
}

variable "cloudflare_domain" {
type = string
description = "Domain for testing"
}

# Locals for naming consistency
locals {
name_prefix = "cftftest"
}

# Note: Load balancer resources require load_balancer_pool resources
# These are not included here as they would need their own v4 to v5 migration
# For now, this file only tests the load_balancer resource schema changes

# 1. Basic load balancer (v4 schema)
# v4 uses: default_pool_ids, fallback_pool_id
# v5 uses: default_pools, fallback_pool
resource "cloudflare_load_balancer" "basic" {
zone_id = var.cloudflare_zone_id
name = "${local.name_prefix}-basic-lb.${var.cloudflare_domain}"
default_pools = ["pool-id-1"]
fallback_pool = "pool-id-fallback"
}

# 2. Load balancer with session_affinity_attributes (v4 block, v5 map)
resource "cloudflare_load_balancer" "with_affinity" {
zone_id = var.cloudflare_zone_id
name = "${local.name_prefix}-affinity-lb.${var.cloudflare_domain}"
session_affinity = "cookie"
session_affinity_ttl = 3600

default_pools = ["pool-id-1"]
fallback_pool = "pool-id-fallback"
session_affinity_attributes = {
samesite = "Lax"
secure = "Always"
}
}

# 3. Load balancer with region_pools (v4 blocks, v5 map)
resource "cloudflare_load_balancer" "with_region_pools" {
zone_id = var.cloudflare_zone_id
name = "${local.name_prefix}-region-lb.${var.cloudflare_domain}"


default_pools = ["pool-id-1"]
fallback_pool = "pool-id-fallback"
region_pools = {
"WNAM" = ["pool-id-1"]
"ENAM" = ["pool-id-2"]
}
}

# 4. Load balancer with adaptive_routing (v4 block, v5 single object)
resource "cloudflare_load_balancer" "with_adaptive_routing" {
zone_id = var.cloudflare_zone_id
name = "${local.name_prefix}-adaptive-lb.${var.cloudflare_domain}"

default_pools = ["pool-id-1"]
fallback_pool = "pool-id-fallback"
adaptive_routing = {
failover_across_pools = false
}
}

# 5. Load balancer with location_strategy (v4 block, v5 single object)
resource "cloudflare_load_balancer" "with_location_strategy" {
zone_id = var.cloudflare_zone_id
name = "${local.name_prefix}-location-lb.${var.cloudflare_domain}"

default_pools = ["pool-id-1"]
fallback_pool = "pool-id-fallback"
location_strategy = {
prefer_ecs = "proximity"
mode = "pop"
}
}

# 6. Load balancer with random_steering (v4 block, v5 single object)
resource "cloudflare_load_balancer" "with_random_steering" {
zone_id = var.cloudflare_zone_id
name = "${local.name_prefix}-random-lb.${var.cloudflare_domain}"
steering_policy = "random"

default_pools = ["pool-id-1"]
fallback_pool = "pool-id-fallback"
random_steering = {
default_weight = 0.5
pool_weights = {
"pool-id-1" = 0.7
}
}
}

# 7. Load balancer with all single-object attributes (comprehensive test)
resource "cloudflare_load_balancer" "with_all_attributes" {
zone_id = var.cloudflare_zone_id
name = "${local.name_prefix}-all-attrs-lb.${var.cloudflare_domain}"
session_affinity = "cookie"
session_affinity_ttl = 3600
steering_policy = "random"




default_pools = ["pool-id-1"]
fallback_pool = "pool-id-fallback"
session_affinity_attributes = {
samesite = "Lax"
secure = "Always"
}
adaptive_routing = {
failover_across_pools = false
}
location_strategy = {
prefer_ecs = "proximity"
mode = "pop"
}
random_steering = {
default_weight = 0.5
}
}
Loading
Loading