Skip to content

Commit 71f661f

Browse files
authored
feat(load_balancer): v4 to v5 migration (#83)
1 parent 0d274ed commit 71f661f

File tree

34 files changed

+3424
-398
lines changed

34 files changed

+3424
-398
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,8 @@ jobs:
3131
go mod download
3232
go mod tidy
3333
34-
- name: Run unit tests with coverage
35-
run: |
36-
go test -v -race -coverprofile=coverage.out -covermode=atomic ./internal/...
37-
go test -v -race ./cmd/...
38-
39-
- name: Generate coverage report
40-
run: |
41-
echo "Coverage Report:"
42-
go tool cover -func=coverage.out
34+
- name: Run unit tests
35+
run: make test-unit
4336

4437
lint-testdata:
4538
name: Lint Testdata Naming
@@ -82,12 +75,5 @@ jobs:
8275
go mod download
8376
go mod tidy
8477
85-
- name: Build tf-migrate
86-
run: |
87-
make build
88-
./bin/tf-migrate version
89-
90-
- name: Run integration tests for v4 to v5
91-
run: |
92-
cd integration/v4_to_v5
93-
go test -v -race -timeout 10m
78+
- name: Run integration tests
79+
run: make test-integration

Makefile

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ GO := go
66
MAIN_PACKAGE := ./cmd/tf-migrate
77
E2E_PACKAGE := ./cmd/e2e-runner
88

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

1111
# Default target: build all binaries
1212
all: build-all
@@ -24,13 +24,16 @@ build-e2e:
2424
# Build both binaries
2525
build-all: build build-e2e
2626

27-
# Run tests
28-
test:
27+
# Run all tests (unit + e2e + integration)
28+
test: test-unit test-integration
29+
30+
# Run unit tests
31+
test-unit:
2932
$(GO) test -v -race ./internal/...
3033

31-
# Run e2e-runner tests only
32-
test-e2e:
33-
$(GO) test -v -race ./internal/e2e-runner
34+
# Run integration tests
35+
test-integration:
36+
$(GO) test -v -race ./integration/...
3437

3538
# Lint testdata to ensure all resources have cftftest prefix
3639
lint-testdata:
@@ -42,4 +45,4 @@ clean:
4245
@echo "Cleaning build artifacts..."
4346
@rm -rf bin/
4447
@rm -f tf-migrate e2e-runner
45-
@echo "Clean complete"
48+
@echo "Clean complete"

e2e/drift-exemptions.yaml

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ exemptions:
99
description: "Ignore attributes that refresh to 'known after apply'"
1010
patterns:
1111
- "(known after apply)"
12+
- '= \{\} -> null'
1213
enabled: true
1314

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

23-
# Ignore empty nested objects being normalized to null in access policy condition elements
24-
- name: "access_policy_empty_objects_to_null"
25-
description: "Empty nested objects in condition elements normalized to null (terraform init behavior)"
26-
resource_types:
27-
- "cloudflare_zero_trust_access_policy"
28-
patterns:
29-
- '= \{\} -> null'
30-
enabled: true
31-
3224
# Ignore nested object restructuring in access policy condition elements
3325
- name: "access_policy_nested_object_restructuring"
3426
description: "Nested objects in condition elements being restructured (empty object removal)"

integration/v4_to_v5/integration_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import (
1212
_ "github.com/cloudflare/tf-migrate/internal/resources/custom_pages"
1313
_ "github.com/cloudflare/tf-migrate/internal/resources/dns_record"
1414
_ "github.com/cloudflare/tf-migrate/internal/resources/healthcheck"
15+
_ "github.com/cloudflare/tf-migrate/internal/resources/load_balancer"
16+
_ "github.com/cloudflare/tf-migrate/internal/resources/load_balancer_pool"
1517
_ "github.com/cloudflare/tf-migrate/internal/resources/logpull_retention"
1618
_ "github.com/cloudflare/tf-migrate/internal/resources/managed_transforms"
1719
_ "github.com/cloudflare/tf-migrate/internal/resources/page_rule"
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
# Minimal load_balancer testdata for v4 to v5 migration
2+
# This file uses v4 schema which has major breaking changes in v5
3+
4+
# Variables for DRY configuration
5+
variable "cloudflare_account_id" {
6+
type = string
7+
default = "f037e56e89293a057740de681ac9abbe"
8+
}
9+
10+
variable "cloudflare_zone_id" {
11+
type = string
12+
default = "0da42c8d2132a9ddaf714f9e7c920711"
13+
}
14+
15+
variable "cloudflare_domain" {
16+
type = string
17+
description = "Domain for testing"
18+
}
19+
20+
# Locals for naming consistency
21+
locals {
22+
name_prefix = "cftftest"
23+
}
24+
25+
# Note: Load balancer resources require load_balancer_pool resources
26+
# These are not included here as they would need their own v4 to v5 migration
27+
# For now, this file only tests the load_balancer resource schema changes
28+
29+
# 1. Basic load balancer (v4 schema)
30+
# v4 uses: default_pool_ids, fallback_pool_id
31+
# v5 uses: default_pools, fallback_pool
32+
resource "cloudflare_load_balancer" "basic" {
33+
zone_id = var.cloudflare_zone_id
34+
name = "${local.name_prefix}-basic-lb.${var.cloudflare_domain}"
35+
default_pools = ["pool-id-1"]
36+
fallback_pool = "pool-id-fallback"
37+
}
38+
39+
# 2. Load balancer with session_affinity_attributes (v4 block, v5 map)
40+
resource "cloudflare_load_balancer" "with_affinity" {
41+
zone_id = var.cloudflare_zone_id
42+
name = "${local.name_prefix}-affinity-lb.${var.cloudflare_domain}"
43+
session_affinity = "cookie"
44+
session_affinity_ttl = 3600
45+
46+
default_pools = ["pool-id-1"]
47+
fallback_pool = "pool-id-fallback"
48+
session_affinity_attributes = {
49+
samesite = "Lax"
50+
secure = "Always"
51+
}
52+
}
53+
54+
# 3. Load balancer with region_pools (v4 blocks, v5 map)
55+
resource "cloudflare_load_balancer" "with_region_pools" {
56+
zone_id = var.cloudflare_zone_id
57+
name = "${local.name_prefix}-region-lb.${var.cloudflare_domain}"
58+
59+
60+
default_pools = ["pool-id-1"]
61+
fallback_pool = "pool-id-fallback"
62+
region_pools = {
63+
"WNAM" = ["pool-id-1"]
64+
"ENAM" = ["pool-id-2"]
65+
}
66+
}
67+
68+
# 4. Load balancer with adaptive_routing (v4 block, v5 single object)
69+
resource "cloudflare_load_balancer" "with_adaptive_routing" {
70+
zone_id = var.cloudflare_zone_id
71+
name = "${local.name_prefix}-adaptive-lb.${var.cloudflare_domain}"
72+
73+
default_pools = ["pool-id-1"]
74+
fallback_pool = "pool-id-fallback"
75+
adaptive_routing = {
76+
failover_across_pools = false
77+
}
78+
}
79+
80+
# 5. Load balancer with location_strategy (v4 block, v5 single object)
81+
resource "cloudflare_load_balancer" "with_location_strategy" {
82+
zone_id = var.cloudflare_zone_id
83+
name = "${local.name_prefix}-location-lb.${var.cloudflare_domain}"
84+
85+
default_pools = ["pool-id-1"]
86+
fallback_pool = "pool-id-fallback"
87+
location_strategy = {
88+
prefer_ecs = "proximity"
89+
mode = "pop"
90+
}
91+
}
92+
93+
# 6. Load balancer with random_steering (v4 block, v5 single object)
94+
resource "cloudflare_load_balancer" "with_random_steering" {
95+
zone_id = var.cloudflare_zone_id
96+
name = "${local.name_prefix}-random-lb.${var.cloudflare_domain}"
97+
steering_policy = "random"
98+
99+
default_pools = ["pool-id-1"]
100+
fallback_pool = "pool-id-fallback"
101+
random_steering = {
102+
default_weight = 0.5
103+
pool_weights = {
104+
"pool-id-1" = 0.7
105+
}
106+
}
107+
}
108+
109+
# 7. Load balancer with all single-object attributes (comprehensive test)
110+
resource "cloudflare_load_balancer" "with_all_attributes" {
111+
zone_id = var.cloudflare_zone_id
112+
name = "${local.name_prefix}-all-attrs-lb.${var.cloudflare_domain}"
113+
session_affinity = "cookie"
114+
session_affinity_ttl = 3600
115+
steering_policy = "random"
116+
117+
118+
119+
120+
default_pools = ["pool-id-1"]
121+
fallback_pool = "pool-id-fallback"
122+
session_affinity_attributes = {
123+
samesite = "Lax"
124+
secure = "Always"
125+
}
126+
adaptive_routing = {
127+
failover_across_pools = false
128+
}
129+
location_strategy = {
130+
prefer_ecs = "proximity"
131+
mode = "pop"
132+
}
133+
random_steering = {
134+
default_weight = 0.5
135+
}
136+
}

0 commit comments

Comments
 (0)