Skip to content

Commit f22dda3

Browse files
yfodilremyleone
andauthored
fix(lb): update health_check_port when not set by user (#2135)
* fix(lb): update health_check_port when not set by user * add cassette --------- Co-authored-by: Rémy Léone <[email protected]>
1 parent e1c2568 commit f22dda3

File tree

3 files changed

+2863
-0
lines changed

3 files changed

+2863
-0
lines changed

scaleway/resource_lb_backend.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,13 @@ func resourceScalewayLbBackendUpdate(ctx context.Context, d *schema.ResourceData
613613
updateHCRequest.TCPConfig = expandLbHCTCP(d.Get("health_check_tcp"))
614614
}
615615

616+
rawConfig := d.GetRawConfig().AsValueMap()
617+
healthCheckPortValue, healthCheckPortExists := rawConfig["health_check_port"]
618+
healthCheckPortSetByUser := healthCheckPortExists && !healthCheckPortValue.IsNull()
619+
if d.HasChange("forward_port") && !healthCheckPortSetByUser {
620+
updateHCRequest.Port = int32(d.Get("forward_port").(int))
621+
}
622+
616623
_, err = lbAPI.UpdateHealthCheck(updateHCRequest, scw.WithContext(ctx))
617624
if err != nil {
618625
return diag.FromErr(err)

scaleway/resource_lb_backend_test.go

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,108 @@ func TestAccScalewayLbBackend_WithFailoverHost(t *testing.T) {
324324
})
325325
}
326326

327+
func TestAccScalewayLbBackend_HealthCheck_Port(t *testing.T) {
328+
tt := NewTestTools(t)
329+
defer tt.Cleanup()
330+
resource.ParallelTest(t, resource.TestCase{
331+
PreCheck: func() { testAccPreCheck(t) },
332+
ProviderFactories: tt.ProviderFactories,
333+
CheckDestroy: testAccCheckScalewayLbBackendDestroy(tt),
334+
Steps: []resource.TestStep{
335+
{
336+
Config: `
337+
resource scaleway_lb_ip ip01 {}
338+
resource scaleway_lb lb01 {
339+
ip_id = scaleway_lb_ip.ip01.id
340+
name = "test-lb"
341+
type = "lb-s"
342+
}
343+
344+
resource scaleway_lb_backend bkd01 {
345+
lb_id = scaleway_lb.lb01.id
346+
name = "bkd01"
347+
forward_protocol = "tcp"
348+
forward_port = "3333"
349+
}
350+
`,
351+
Check: resource.ComposeTestCheckFunc(
352+
testAccCheckScalewayLbBackendExists(tt, "scaleway_lb_backend.bkd01"),
353+
resource.TestCheckResourceAttr("scaleway_lb_backend.bkd01", "forward_port", "3333"),
354+
resource.TestCheckResourceAttr("scaleway_lb_backend.bkd01", "health_check_port", "3333"),
355+
),
356+
},
357+
{
358+
Config: `
359+
resource scaleway_lb_ip ip01 {}
360+
resource scaleway_lb lb01 {
361+
ip_id = scaleway_lb_ip.ip01.id
362+
name = "test-lb"
363+
type = "lb-s"
364+
}
365+
366+
resource scaleway_lb_backend bkd01 {
367+
lb_id = scaleway_lb.lb01.id
368+
name = "bkd01"
369+
forward_protocol = "tcp"
370+
forward_port = "4444"
371+
}
372+
`,
373+
Check: resource.ComposeTestCheckFunc(
374+
testAccCheckScalewayLbBackendExists(tt, "scaleway_lb_backend.bkd01"),
375+
resource.TestCheckResourceAttr("scaleway_lb_backend.bkd01", "forward_port", "4444"),
376+
resource.TestCheckResourceAttr("scaleway_lb_backend.bkd01", "health_check_port", "4444"),
377+
),
378+
},
379+
{
380+
Config: `
381+
resource scaleway_lb_ip ip01 {}
382+
resource scaleway_lb lb01 {
383+
ip_id = scaleway_lb_ip.ip01.id
384+
name = "test-lb"
385+
type = "lb-s"
386+
}
387+
388+
resource scaleway_lb_backend bkd01 {
389+
lb_id = scaleway_lb.lb01.id
390+
name = "bkd01"
391+
forward_protocol = "tcp"
392+
forward_port = "4444"
393+
health_check_port = "4444"
394+
}
395+
`,
396+
Check: resource.ComposeTestCheckFunc(
397+
testAccCheckScalewayLbBackendExists(tt, "scaleway_lb_backend.bkd01"),
398+
resource.TestCheckResourceAttr("scaleway_lb_backend.bkd01", "forward_port", "4444"),
399+
resource.TestCheckResourceAttr("scaleway_lb_backend.bkd01", "health_check_port", "4444"),
400+
),
401+
},
402+
{
403+
Config: `
404+
resource scaleway_lb_ip ip01 {}
405+
resource scaleway_lb lb01 {
406+
ip_id = scaleway_lb_ip.ip01.id
407+
name = "test-lb"
408+
type = "lb-s"
409+
}
410+
411+
resource scaleway_lb_backend bkd01 {
412+
lb_id = scaleway_lb.lb01.id
413+
name = "bkd01"
414+
forward_protocol = "tcp"
415+
forward_port = "5555"
416+
health_check_port = "4444"
417+
}
418+
`,
419+
Check: resource.ComposeTestCheckFunc(
420+
testAccCheckScalewayLbBackendExists(tt, "scaleway_lb_backend.bkd01"),
421+
resource.TestCheckResourceAttr("scaleway_lb_backend.bkd01", "forward_port", "5555"),
422+
resource.TestCheckResourceAttr("scaleway_lb_backend.bkd01", "health_check_port", "4444"),
423+
),
424+
},
425+
},
426+
})
427+
}
428+
327429
func testAccCheckScalewayLbBackendExists(tt *TestTools, n string) resource.TestCheckFunc {
328430
return func(state *terraform.State) error {
329431
rs, ok := state.RootModule().Resources[n]

0 commit comments

Comments
 (0)