Skip to content

Commit ec074d5

Browse files
committed
fix(load_balancer_pool): fix dynamic block transformation
1 parent 1aab1a1 commit ec074d5

File tree

9 files changed

+1574
-332
lines changed

9 files changed

+1574
-332
lines changed

integration/v4_to_v5/testdata/load_balancer_pool/expected/load_balancer_pool_e2e.tf

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,28 @@ variable "cloudflare_domain" {
1616

1717
locals {
1818
name_prefix = "cftftest"
19+
20+
# List of backend origins for dynamic configuration
21+
backend_origins = [
22+
{
23+
name = "backend-1"
24+
address = "192.0.2.100"
25+
host = "api1.${var.cloudflare_domain}"
26+
weight = 1.0
27+
},
28+
{
29+
name = "backend-2"
30+
address = "192.0.2.101"
31+
host = "api2.${var.cloudflare_domain}"
32+
weight = 1.0
33+
},
34+
{
35+
name = "backend-3"
36+
address = "192.0.2.102"
37+
host = "api3.${var.cloudflare_domain}"
38+
weight = 0.5
39+
}
40+
]
1941
}
2042

2143
##########################
@@ -81,6 +103,69 @@ resource "cloudflare_load_balancer_pool" "e2e_shedding" {
81103
}
82104
}
83105

106+
# 4. Pool with dynamic origins and headers (v4 syntax - will be migrated to v5 for expression)
107+
resource "cloudflare_load_balancer_pool" "e2e_dynamic_with_headers" {
108+
account_id = var.cloudflare_account_id
109+
name = "${local.name_prefix}-e2e-dynamic-headers-pool"
110+
minimum_origins = 1
111+
enabled = true
112+
description = "Pool with dynamic origins and headers"
113+
114+
115+
origins = [for value in local.backend_origins : {
116+
name = value.name
117+
address = value.address
118+
enabled = true
119+
weight = value.weight
120+
header = { host = [value.host] }
121+
}]
122+
origin_steering = {
123+
policy = "random"
124+
}
125+
}
126+
127+
# 5. Pool with dynamic origins without headers (v4 syntax - will be migrated to v5 for expression)
128+
resource "cloudflare_load_balancer_pool" "e2e_dynamic_simple" {
129+
account_id = var.cloudflare_account_id
130+
name = "${local.name_prefix}-e2e-dynamic-simple-pool"
131+
minimum_origins = 1
132+
enabled = true
133+
134+
origins = [for value in local.backend_origins : {
135+
name = value.name
136+
address = value.address
137+
enabled = true
138+
}]
139+
}
140+
141+
# 6. Pool with static origins and headers (v4 syntax - will be migrated to v5 array)
142+
resource "cloudflare_load_balancer_pool" "e2e_static_with_headers" {
143+
account_id = var.cloudflare_account_id
144+
name = "${local.name_prefix}-e2e-static-headers-pool"
145+
minimum_origins = 1
146+
enabled = true
147+
148+
149+
150+
origins = [{
151+
name = "static-origin-1"
152+
address = "192.0.2.200"
153+
enabled = true
154+
header = { host = ["static1.${var.cloudflare_domain}"] }
155+
}, {
156+
name = "static-origin-2"
157+
address = "192.0.2.201"
158+
enabled = false
159+
header = { host = ["static2.${var.cloudflare_domain}", "static2-alt.${var.cloudflare_domain}"] }
160+
}]
161+
load_shedding = {
162+
default_percent = 75
163+
default_policy = "random"
164+
session_percent = 50
165+
session_policy = "hash"
166+
}
167+
}
168+
84169
# Output pool IDs for use by load balancers
85170
output "e2e_basic_pool_id" {
86171
value = cloudflare_load_balancer_pool.e2e_basic.id
@@ -93,3 +178,15 @@ output "e2e_multi_pool_id" {
93178
output "e2e_shedding_pool_id" {
94179
value = cloudflare_load_balancer_pool.e2e_shedding.id
95180
}
181+
182+
output "e2e_dynamic_headers_pool_id" {
183+
value = cloudflare_load_balancer_pool.e2e_dynamic_with_headers.id
184+
}
185+
186+
output "e2e_dynamic_simple_pool_id" {
187+
value = cloudflare_load_balancer_pool.e2e_dynamic_simple.id
188+
}
189+
190+
output "e2e_static_headers_pool_id" {
191+
value = cloudflare_load_balancer_pool.e2e_static_with_headers.id
192+
}

0 commit comments

Comments
 (0)