Skip to content

Commit 744c362

Browse files
August Reinigvsin12
authored andcommitted
Bug Fix - Fix handling of backend max connections in load balancer provider.
1 parent b47e032 commit 744c362

File tree

6 files changed

+41
-25
lines changed

6 files changed

+41
-25
lines changed

examples/load_balancer/lb_full/lb_full.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ variable "availability_domain" {
6565
}
6666

6767
provider "oci" {
68-
#version = "6.0.0"
68+
// version = "6.9.0" // published on August 27, 2024.
6969
tenancy_ocid = var.tenancy_ocid
7070
user_ocid = var.user_ocid
7171
fingerprint = var.fingerprint

examples/load_balancer/lb_private/lb_private.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,16 @@ variable "region" {
2424
}
2525

2626
provider "oci" {
27+
// version = "6.9.0" // published on August 27, 2024.
2728
tenancy_ocid = var.tenancy_ocid
2829
user_ocid = var.user_ocid
2930
fingerprint = var.fingerprint
3031
private_key_path = var.private_key_path
3132
region = var.region
3233
}
3334

34-
data "oci_identity_availability_domain" "ad" {
35-
compartment_id = var.tenancy_ocid
35+
data "oci_identity_availability_domain" "ad1" {
36+
compartment_id = var.compartment_ocid // needs to be compartment_ocid if not using root compartment
3637
ad_number = 1
3738
}
3839

@@ -46,7 +47,7 @@ resource "oci_core_vcn" "vcn1" {
4647
}
4748

4849
resource "oci_core_subnet" "subnet1" {
49-
availability_domain = data.oci_identity_availability_domain.ad.name
50+
availability_domain = data.oci_identity_availability_domain.ad1.name
5051
cidr_block = "10.1.20.0/24"
5152
display_name = "subnet1"
5253
dns_label = "subnet1"
@@ -127,4 +128,3 @@ resource "oci_core_network_security_group" "test_network_security_group" {
127128
output "lb_private_ip" {
128129
value = [oci_load_balancer.lb1.ip_address_details]
129130
}
130-

internal/integrationtest/load_balancer_backend_set_test.go

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ func TestLoadBalancerBackendSetResourceOciCerts_basic(t *testing.T) {
217217
"drain": "true",
218218
"ip_address": "10.0.0.3",
219219
"name": "10.0.0.3:10",
220-
"max_connections": "400",
220+
"max_connections": "450",
221221
"offline": "true",
222222
"port": "10",
223223
"weight": "11",
@@ -273,7 +273,7 @@ func TestLoadBalancerBackendSetResourceOciCerts_basic(t *testing.T) {
273273
resource.TestCheckResourceAttr(datasourceName, "backendsets.0.backend.0.offline", "true"),
274274
resource.TestCheckResourceAttr(datasourceName, "backendsets.0.backend.0.port", "10"),
275275
resource.TestCheckResourceAttr(datasourceName, "backendsets.0.backend.0.weight", "11"),
276-
resource.TestCheckResourceAttr(datasourceName, "backendsets.0.backend.0.max_connections", "0"),
276+
resource.TestCheckResourceAttr(datasourceName, "backendsets.0.backend.0.max_connections", "450"),
277277
resource.TestCheckResourceAttr(datasourceName, "backendsets.0.health_checker.#", "1"),
278278
resource.TestCheckResourceAttr(datasourceName, "backendsets.0.health_checker.0.interval_ms", "2000"),
279279
resource.TestCheckResourceAttr(datasourceName, "backendsets.0.health_checker.0.port", "11"),
@@ -308,7 +308,8 @@ func TestLoadBalancerBackendSetResourceOciCerts_basic(t *testing.T) {
308308
// verify update with LB session persistence
309309
{
310310
Config: config + compartmentIdVariableStr + BackendSetResourceDependencies +
311-
acctest.GenerateResourceFromRepresentationMap("oci_load_balancer_backend_set", "test_backend_set", acctest.Optional, acctest.Create, backendSetLBRepresentationOciCerts), // +
311+
acctest.GenerateResourceFromRepresentationMap("oci_load_balancer_backend_set", "test_backend_set", acctest.Optional, acctest.Create, backendSetLBRepresentationOciCerts) +
312+
acctest.GenerateResourceFromRepresentationMap("oci_load_balancer_backend", "test_backend", acctest.Optional, acctest.Update, backendRepresentation),
312313
Check: resource.ComposeAggregateTestCheckFunc(
313314
resource.TestCheckResourceAttr(resourceName, "health_checker.#", "1"),
314315
resource.TestCheckResourceAttr(resourceName, "health_checker.0.interval_ms", "1000"),
@@ -407,7 +408,7 @@ func TestLoadBalancerBackendSetResourceOciCerts_basic(t *testing.T) {
407408
"drain": "true",
408409
"ip_address": "10.0.0.3",
409410
"name": "10.0.0.3:10",
410-
"max_connections": "400",
411+
"max_connections": "450",
411412
"offline": "true",
412413
"port": "10",
413414
"weight": "11",
@@ -467,7 +468,7 @@ func TestLoadBalancerBackendSetResourceOciCerts_basic(t *testing.T) {
467468
"drain": "true",
468469
"ip_address": "10.0.0.3",
469470
"name": "10.0.0.3:10",
470-
"max_connections": "0",
471+
"max_connections": "450",
471472
"offline": "true",
472473
"port": "10",
473474
"weight": "11",
@@ -600,7 +601,7 @@ func TestLoadBalancerBackendSetResourceLB_basic(t *testing.T) {
600601
"ip_address": "10.0.0.3",
601602
"name": "10.0.0.3:10",
602603
"offline": "true",
603-
"max_connections": "400",
604+
"max_connections": "450",
604605
"port": "10",
605606
"weight": "11",
606607
},
@@ -652,7 +653,7 @@ func TestLoadBalancerBackendSetResourceLB_basic(t *testing.T) {
652653
resource.TestCheckResourceAttr(datasourceName, "backendsets.0.backend.0.backup", "true"),
653654
resource.TestCheckResourceAttr(datasourceName, "backendsets.0.backend.0.drain", "true"),
654655
resource.TestCheckResourceAttr(datasourceName, "backendsets.0.backend.0.ip_address", "10.0.0.3"),
655-
resource.TestCheckResourceAttr(datasourceName, "backendsets.0.backend.0.max_connections", "0"),
656+
resource.TestCheckResourceAttr(datasourceName, "backendsets.0.backend.0.max_connections", "450"),
656657
resource.TestCheckResourceAttr(datasourceName, "backendsets.0.backend.0.offline", "true"),
657658
resource.TestCheckResourceAttr(datasourceName, "backendsets.0.backend.0.port", "10"),
658659
resource.TestCheckResourceAttr(datasourceName, "backendsets.0.backend.0.weight", "11"),
@@ -690,7 +691,8 @@ func TestLoadBalancerBackendSetResourceLB_basic(t *testing.T) {
690691
// verify Update with LB session persistence
691692
{
692693
Config: config + compartmentIdVariableStr + BackendSetResourceDependencies +
693-
acctest.GenerateResourceFromRepresentationMap("oci_load_balancer_backend_set", "test_backend_set", acctest.Optional, acctest.Create, backendSetLBRepresentation), // +
694+
acctest.GenerateResourceFromRepresentationMap("oci_load_balancer_backend_set", "test_backend_set", acctest.Optional, acctest.Create, backendSetLBRepresentation) +
695+
acctest.GenerateResourceFromRepresentationMap("oci_load_balancer_backend", "test_backend", acctest.Optional, acctest.Update, backendRepresentation),
694696
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
695697
resource.TestCheckResourceAttr(resourceName, "health_checker.#", "1"),
696698
resource.TestCheckResourceAttr(resourceName, "health_checker.0.interval_ms", "1000"),
@@ -792,7 +794,7 @@ func TestLoadBalancerBackendSetResourceLB_basic(t *testing.T) {
792794
"drain": "true",
793795
"ip_address": "10.0.0.3",
794796
"name": "10.0.0.3:10",
795-
"max_connections": "400",
797+
"max_connections": "450",
796798
"offline": "true",
797799
"port": "10",
798800
"weight": "11",
@@ -854,7 +856,7 @@ func TestLoadBalancerBackendSetResourceLB_basic(t *testing.T) {
854856
"drain": "true",
855857
"ip_address": "10.0.0.3",
856858
"name": "10.0.0.3:10",
857-
"max_connections": "0",
859+
"max_connections": "450",
858860
"offline": "true",
859861
"port": "10",
860862
"weight": "11",
@@ -984,7 +986,7 @@ func TestLoadBalancerBackendSetResourceLBCertToOciCerts_combo(t *testing.T) {
984986
"drain": "true",
985987
"ip_address": "10.0.0.3",
986988
"name": "10.0.0.3:10",
987-
"max_connections": "400",
989+
"max_connections": "450",
988990
"offline": "true",
989991
"port": "10",
990992
"weight": "11",
@@ -1028,6 +1030,10 @@ func TestLoadBalancerBackendSetResourceOciCertsToLBCert_combo(t *testing.T) {
10281030
httpreplay.SetScenario("TestLoadBalancerBackendSetResource_basic")
10291031
defer httpreplay.SaveScenario()
10301032

1033+
// provider added to avoid load_balancer_backend_set_test.go:1046: Test validation error:
1034+
// TestStep 1/2 validation error: Providers must be specified at the TestCase level or in all TestStep
1035+
//--- FAIL: TestLoadBalancerBackendSetResourceOciCertsToLBCert_combo (0.00s)
1036+
provider := acctest.TestAccProvider
10311037
config := acctest.ProviderTestConfig()
10321038

10331039
compartmentId := utils.GetEnvSettingWithBlankDefault("compartment_ocid")
@@ -1042,7 +1048,10 @@ func TestLoadBalancerBackendSetResourceOciCertsToLBCert_combo(t *testing.T) {
10421048
acctest.GenerateResourceFromRepresentationMap("oci_load_balancer_backend_set", "test_backend_set", acctest.Optional, acctest.Create, backendSetRepresentationOciCerts), "loadbalancer", "backendSet", t)
10431049

10441050
resource.Test(t, resource.TestCase{
1045-
PreCheck: func() { acctest.PreCheck(t) },
1051+
PreCheck: func() { acctest.PreCheck(t) },
1052+
Providers: map[string]*schema.Provider{ // added to avoid Providers must be specified at the TestCase level or in all TestStep
1053+
"oci": provider,
1054+
},
10461055
CheckDestroy: testAccCheckLoadBalancerBackendSetDestroy,
10471056
Steps: []resource.TestStep{
10481057
// verify create with optionals
@@ -1089,7 +1098,7 @@ func TestLoadBalancerBackendSetResourceOciCertsToLBCert_combo(t *testing.T) {
10891098
"drain": "true",
10901099
"ip_address": "10.0.0.3",
10911100
"name": "10.0.0.3:10",
1092-
"max_connections": "400",
1101+
"max_connections": "450",
10931102
"offline": "true",
10941103
"port": "10",
10951104
"weight": "11",

internal/integrationtest/load_balancer_backend_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ var (
4343
"port": acctest.Representation{RepType: acctest.Required, Create: `10`},
4444
"backup": acctest.Representation{RepType: acctest.Optional, Create: `false`, Update: `true`},
4545
"drain": acctest.Representation{RepType: acctest.Optional, Create: `false`, Update: `true`},
46-
"max_connections": acctest.Representation{RepType: acctest.Optional, Create: `375`, Update: `400`},
46+
"max_connections": acctest.Representation{RepType: acctest.Optional, Create: `375`, Update: `450`},
4747
"offline": acctest.Representation{RepType: acctest.Optional, Create: `false`, Update: `true`},
4848
"weight": acctest.Representation{RepType: acctest.Optional, Create: `10`, Update: `11`},
4949
}
@@ -132,7 +132,7 @@ func TestLoadBalancerBackendResource_basic(t *testing.T) {
132132
resource.TestCheckResourceAttr(resourceName, "drain", "true"),
133133
resource.TestCheckResourceAttr(resourceName, "ip_address", "10.0.0.3"),
134134
resource.TestCheckResourceAttrSet(resourceName, "load_balancer_id"),
135-
resource.TestCheckResourceAttr(resourceName, "max_connections", "400"),
135+
resource.TestCheckResourceAttr(resourceName, "max_connections", "450"),
136136
resource.TestCheckResourceAttrSet(resourceName, "name"),
137137
resource.TestCheckResourceAttr(resourceName, "offline", "true"),
138138
resource.TestCheckResourceAttr(resourceName, "port", "10"),
@@ -161,7 +161,7 @@ func TestLoadBalancerBackendResource_basic(t *testing.T) {
161161
resource.TestCheckResourceAttr(datasourceName, "backends.0.backup", "true"),
162162
resource.TestCheckResourceAttr(datasourceName, "backends.0.drain", "true"),
163163
resource.TestCheckResourceAttr(datasourceName, "backends.0.ip_address", "10.0.0.3"),
164-
resource.TestCheckResourceAttr(datasourceName, "backends.0.max_connections", "400"),
164+
resource.TestCheckResourceAttr(datasourceName, "backends.0.max_connections", "450"),
165165
resource.TestCheckResourceAttrSet(datasourceName, "backends.0.name"),
166166
resource.TestCheckResourceAttr(datasourceName, "backends.0.offline", "true"),
167167
resource.TestCheckResourceAttr(datasourceName, "backends.0.port", "10"),

internal/integrationtest/load_balancer_load_balancer_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ var (
4949
"subnet_ids": acctest.Representation{RepType: acctest.Required, Create: []string{`${oci_core_subnet.lb_test_subnet_1.id}`, `${oci_core_subnet.lb_test_subnet_2.id}`}},
5050

5151
// For laptop testing, comment this defined_tags out along with the DefinedTagsDependencies + line below
52-
// Failure to do so results in test failures: Error: Reference to undeclared resource
53-
"defined_tags": acctest.Representation{RepType: acctest.Optional, Create: `${map("${oci_identity_tag_namespace.tag-namespace1.name}.${oci_identity_tag.tag1.name}", "value")}`, Update: `${map("${oci_identity_tag_namespace.tag-namespace1.name}.${oci_identity_tag.tag1.name}", "updatedValue")}`},
52+
// Failure to do so results in test failures: Error: Reference to undeclared resource.
53+
// "defined_tags": acctest.Representation{RepType: acctest.Optional, Create: `${map("${oci_identity_tag_namespace.tag-namespace1.name}.${oci_identity_tag.tag1.name}", "value")}`, Update: `${map("${oci_identity_tag_namespace.tag-namespace1.name}.${oci_identity_tag.tag1.name}", "updatedValue")}`},
5454

5555
"freeform_tags": acctest.Representation{RepType: acctest.Optional, Create: map[string]string{"Department": "Finance"}, Update: map[string]string{"Department": "Accounting"}},
5656
"is_private": acctest.Representation{RepType: acctest.Optional, Create: `false`},
@@ -136,14 +136,14 @@ var (
136136
acctest.GenerateResourceFromRepresentationMap("oci_core_network_security_group",
137137
"test_network_security_group1", acctest.Required, acctest.Create, acctest.RepresentationCopyWithNewProperties(CoreNetworkSecurityGroupRepresentation, map[string]interface{}{
138138
"vcn_id": acctest.Representation{RepType: acctest.Required, Create: `${oci_core_vcn.test_lb_vcn.id}`},
139-
})) +
139+
})) // +
140140
// For laptop testing comment out this line
141141
// Failure to do so results in
142142
// test_helpers.go:535: Step 1/7 error: Error running apply: exit status 1
143143
// [DEBUG] Using modified User-Agent: Terraform/0.12.31 HashiCorp-terraform-exec/0.14.0
144144
// Error: 404-NotAuthorizedOrNotFound, Authorization failed or requested resource not found.
145145
// Suggestion: Either the resource has been deleted or service Identity Tag Namespace need policy to access this resource.
146-
DefinedTagsDependencies
146+
// DefinedTagsDependencies
147147
)
148148

149149
// issue-routing-tag: load_balancer/default

internal/service/load_balancer/load_balancer_backend_set_resource.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,11 @@ func (s *LoadBalancerBackendSetResourceCrud) mapToBackendDetails(fieldKeyFormat
817817
result.Weight = &tmp
818818
}
819819

820+
if maxConnections, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "max_connections")); ok {
821+
tmp := maxConnections.(int)
822+
result.MaxConnections = &tmp
823+
}
824+
820825
return result, nil
821826
}
822827

@@ -837,6 +842,8 @@ func BackendToMap(obj oci_load_balancer.Backend) map[string]interface{} {
837842

838843
if obj.MaxConnections != nil {
839844
result["max_connections"] = int(*obj.MaxConnections)
845+
} else {
846+
result["max_connections"] = 0
840847
}
841848

842849
if obj.Name != nil {

0 commit comments

Comments
 (0)