Skip to content

Commit c56b616

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

26 files changed

+2492
-39
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: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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+
}
Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
{
2+
"lineage": "test-load-balancer-lineage",
3+
"outputs": {},
4+
"resources": [
5+
{
6+
"instances": [
7+
{
8+
"attributes": {
9+
"id": "lb-basic-id",
10+
"zone_id": "0da42c8d2132a9ddaf714f9e7c920711",
11+
"name": "cftftest-basic-lb.cf-tf-test.com",
12+
"default_pools": ["pool-primary-id"],
13+
"fallback_pool": "pool-fallback-id",
14+
"enabled": true,
15+
"proxied": true,
16+
"ttl": null,
17+
"description": null,
18+
"steering_policy": "off",
19+
"session_affinity": "none",
20+
"session_affinity_ttl": null,
21+
"session_affinity_attributes": null,
22+
"region_pools": null,
23+
"pop_pools": null,
24+
"country_pools": null,
25+
"rules": [],
26+
"created_on": "2023-01-01T00:00:00Z",
27+
"modified_on": "2023-01-01T00:00:00Z"
28+
},
29+
"schema_version": 0
30+
}
31+
],
32+
"mode": "managed",
33+
"name": "basic",
34+
"provider": "provider[\"registry.terraform.io/cloudflare/cloudflare\"]",
35+
"type": "cloudflare_load_balancer"
36+
},
37+
{
38+
"instances": [
39+
{
40+
"attributes": {
41+
"id": "lb-ttl-id",
42+
"zone_id": "0da42c8d2132a9ddaf714f9e7c920711",
43+
"name": "cftftest-ttl-lb.cf-tf-test.com",
44+
"default_pools": ["pool-primary-id"],
45+
"fallback_pool": "pool-fallback-id",
46+
"enabled": true,
47+
"proxied": true,
48+
"ttl": 30,
49+
"description": "Load balancer with custom TTL",
50+
"steering_policy": "off",
51+
"session_affinity": "none",
52+
"session_affinity_ttl": null,
53+
"session_affinity_attributes": null,
54+
"region_pools": null,
55+
"pop_pools": null,
56+
"country_pools": null,
57+
"rules": [],
58+
"created_on": "2023-01-01T00:00:00Z",
59+
"modified_on": "2023-01-01T00:00:00Z"
60+
},
61+
"schema_version": 0
62+
}
63+
],
64+
"mode": "managed",
65+
"name": "with_ttl",
66+
"provider": "provider[\"registry.terraform.io/cloudflare/cloudflare\"]",
67+
"type": "cloudflare_load_balancer"
68+
},
69+
{
70+
"instances": [
71+
{
72+
"attributes": {
73+
"id": "lb-steering-id",
74+
"zone_id": "0da42c8d2132a9ddaf714f9e7c920711",
75+
"name": "cftftest-steering-lb.cf-tf-test.com",
76+
"default_pools": ["pool-primary-id"],
77+
"fallback_pool": "pool-fallback-id",
78+
"enabled": true,
79+
"proxied": true,
80+
"ttl": null,
81+
"description": null,
82+
"steering_policy": "geo",
83+
"session_affinity": "none",
84+
"session_affinity_ttl": null,
85+
"session_affinity_attributes": null,
86+
"region_pools": null,
87+
"pop_pools": null,
88+
"country_pools": null,
89+
"rules": [],
90+
"created_on": "2023-01-01T00:00:00Z",
91+
"modified_on": "2023-01-01T00:00:00Z"
92+
},
93+
"schema_version": 0
94+
}
95+
],
96+
"mode": "managed",
97+
"name": "with_steering",
98+
"provider": "provider[\"registry.terraform.io/cloudflare/cloudflare\"]",
99+
"type": "cloudflare_load_balancer"
100+
},
101+
{
102+
"instances": [
103+
{
104+
"attributes": {
105+
"id": "lb-affinity-id",
106+
"zone_id": "0da42c8d2132a9ddaf714f9e7c920711",
107+
"name": "cftftest-affinity-lb.cf-tf-test.com",
108+
"default_pools": ["pool-primary-id"],
109+
"fallback_pool": "pool-fallback-id",
110+
"enabled": true,
111+
"proxied": true,
112+
"ttl": null,
113+
"description": null,
114+
"steering_policy": "off",
115+
"session_affinity": "cookie",
116+
"session_affinity_ttl": 3600,
117+
"session_affinity_attributes": {
118+
"samesite": "Lax",
119+
"secure": "Always"
120+
},
121+
"region_pools": null,
122+
"pop_pools": null,
123+
"country_pools": null,
124+
"rules": [],
125+
"created_on": "2023-01-01T00:00:00Z",
126+
"modified_on": "2023-01-01T00:00:00Z"
127+
},
128+
"schema_version": 0
129+
}
130+
],
131+
"mode": "managed",
132+
"name": "with_session_affinity",
133+
"provider": "provider[\"registry.terraform.io/cloudflare/cloudflare\"]",
134+
"type": "cloudflare_load_balancer"
135+
},
136+
{
137+
"instances": [
138+
{
139+
"attributes": {
140+
"id": "lb-multi-pool-id",
141+
"zone_id": "0da42c8d2132a9ddaf714f9e7c920711",
142+
"name": "cftftest-multi-pool-lb.cf-tf-test.com",
143+
"default_pools": ["pool-primary-id", "pool-secondary-id"],
144+
"fallback_pool": "pool-fallback-id",
145+
"enabled": true,
146+
"proxied": true,
147+
"ttl": null,
148+
"description": null,
149+
"steering_policy": "off",
150+
"session_affinity": "none",
151+
"session_affinity_ttl": null,
152+
"session_affinity_attributes": null,
153+
"region_pools": null,
154+
"pop_pools": null,
155+
"country_pools": null,
156+
"rules": [],
157+
"created_on": "2023-01-01T00:00:00Z",
158+
"modified_on": "2023-01-01T00:00:00Z"
159+
},
160+
"schema_version": 0
161+
}
162+
],
163+
"mode": "managed",
164+
"name": "multi_pool",
165+
"provider": "provider[\"registry.terraform.io/cloudflare/cloudflare\"]",
166+
"type": "cloudflare_load_balancer"
167+
}
168+
],
169+
"serial": 1,
170+
"terraform_version": "1.0.0",
171+
"version": 4
172+
}

0 commit comments

Comments
 (0)