Skip to content

Commit 795ac50

Browse files
committed
feat(load_balancer): v4 to v5 migration
1 parent 38eddbd commit 795ac50

File tree

25 files changed

+3058
-40
lines changed

25 files changed

+3058
-40
lines changed

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+
}
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
# E2E Test: cloudflare_load_balancer
2+
# Minimal e2e test that can be applied with real infrastructure
3+
# Creates pools and load balancers in the same module to avoid dependency issues
4+
5+
variable "cloudflare_account_id" {
6+
type = string
7+
}
8+
9+
variable "cloudflare_zone_id" {
10+
type = string
11+
}
12+
13+
variable "cloudflare_domain" {
14+
type = string
15+
description = "Domain for testing"
16+
}
17+
18+
locals {
19+
name_prefix = "cftftest"
20+
}
21+
22+
##########################
23+
# E2E TEST POOLS
24+
##########################
25+
26+
resource "cloudflare_load_balancer_pool" "lb_e2e_basic" {
27+
account_id = var.cloudflare_account_id
28+
name = "${local.name_prefix}-lb-e2e-basic-pool"
29+
minimum_origins = 1
30+
enabled = true
31+
32+
origins = [{
33+
name = "origin-1"
34+
address = "192.0.2.100"
35+
enabled = true
36+
}]
37+
}
38+
39+
resource "cloudflare_load_balancer_pool" "lb_e2e_fallback" {
40+
account_id = var.cloudflare_account_id
41+
name = "${local.name_prefix}-lb-e2e-fallback-pool"
42+
minimum_origins = 1
43+
enabled = true
44+
45+
origins = [{
46+
name = "origin-fallback"
47+
address = "192.0.2.101"
48+
enabled = true
49+
}]
50+
}
51+
52+
##########################
53+
# E2E TEST LOAD BALANCERS
54+
##########################
55+
56+
# 1. Basic load balancer (v4 syntax - will be migrated to v5)
57+
resource "cloudflare_load_balancer" "e2e_basic" {
58+
zone_id = var.cloudflare_zone_id
59+
name = "${local.name_prefix}-e2e-basic-lb.${var.cloudflare_domain}"
60+
enabled = true
61+
steering_policy = "off"
62+
ttl = 30
63+
default_pools = [cloudflare_load_balancer_pool.lb_e2e_basic.id]
64+
fallback_pool = cloudflare_load_balancer_pool.lb_e2e_fallback.id
65+
}
66+
67+
# 2. Load balancer with session_affinity_attributes (v4 syntax - will be migrated to v5)
68+
resource "cloudflare_load_balancer" "e2e_affinity" {
69+
zone_id = var.cloudflare_zone_id
70+
name = "${local.name_prefix}-e2e-affinity-lb.${var.cloudflare_domain}"
71+
session_affinity = "cookie"
72+
session_affinity_ttl = 3600
73+
74+
75+
enabled = true
76+
steering_policy = "off"
77+
ttl = 30
78+
default_pools = [cloudflare_load_balancer_pool.lb_e2e_basic.id]
79+
fallback_pool = cloudflare_load_balancer_pool.lb_e2e_fallback.id
80+
session_affinity_attributes = {
81+
samesite = "Lax"
82+
secure = "Always"
83+
}
84+
}
85+
86+
# 3. Load balancer with adaptive_routing (v4 syntax - will be migrated to v5)
87+
resource "cloudflare_load_balancer" "e2e_adaptive_routing" {
88+
zone_id = var.cloudflare_zone_id
89+
name = "${local.name_prefix}-e2e-adaptive-lb.${var.cloudflare_domain}"
90+
enabled = true
91+
steering_policy = "off"
92+
ttl = 30
93+
94+
default_pools = [cloudflare_load_balancer_pool.lb_e2e_basic.id]
95+
fallback_pool = cloudflare_load_balancer_pool.lb_e2e_fallback.id
96+
adaptive_routing = {
97+
failover_across_pools = false
98+
}
99+
}
100+
101+
# 4. Load balancer with location_strategy (v4 syntax - will be migrated to v5)
102+
resource "cloudflare_load_balancer" "e2e_location_strategy" {
103+
zone_id = var.cloudflare_zone_id
104+
name = "${local.name_prefix}-e2e-location-lb.${var.cloudflare_domain}"
105+
enabled = true
106+
steering_policy = "off"
107+
ttl = 30
108+
109+
default_pools = [cloudflare_load_balancer_pool.lb_e2e_basic.id]
110+
fallback_pool = cloudflare_load_balancer_pool.lb_e2e_fallback.id
111+
location_strategy = {
112+
prefer_ecs = "proximity"
113+
mode = "pop"
114+
}
115+
}
116+
117+
# 5. Load balancer with random_steering (v4 syntax - will be migrated to v5)
118+
resource "cloudflare_load_balancer" "e2e_random_steering" {
119+
zone_id = var.cloudflare_zone_id
120+
name = "${local.name_prefix}-e2e-random-lb.${var.cloudflare_domain}"
121+
enabled = true
122+
steering_policy = "random"
123+
ttl = 30
124+
125+
default_pools = [cloudflare_load_balancer_pool.lb_e2e_basic.id]
126+
fallback_pool = cloudflare_load_balancer_pool.lb_e2e_fallback.id
127+
random_steering = {
128+
default_weight = 0.5
129+
}
130+
}
131+
132+
# 6. Load balancer with all single-object attributes (v4 syntax - will be migrated to v5)
133+
resource "cloudflare_load_balancer" "e2e_all_attributes" {
134+
zone_id = var.cloudflare_zone_id
135+
name = "${local.name_prefix}-e2e-all-attrs-lb.${var.cloudflare_domain}"
136+
session_affinity = "cookie"
137+
session_affinity_ttl = 3600
138+
enabled = true
139+
steering_policy = "random"
140+
ttl = 30
141+
142+
143+
144+
145+
default_pools = [cloudflare_load_balancer_pool.lb_e2e_basic.id]
146+
fallback_pool = cloudflare_load_balancer_pool.lb_e2e_fallback.id
147+
session_affinity_attributes = {
148+
samesite = "Lax"
149+
secure = "Always"
150+
}
151+
adaptive_routing = {
152+
failover_across_pools = false
153+
}
154+
location_strategy = {
155+
prefer_ecs = "proximity"
156+
mode = "pop"
157+
}
158+
random_steering = {
159+
default_weight = 0.5
160+
}
161+
}

0 commit comments

Comments
 (0)