Skip to content

Commit 805c0ca

Browse files
committed
support for LB sticky cookie
1 parent 9c3439d commit 805c0ca

8 files changed

+810
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
- Support for moving `ons_notification_topic`, `ons_subscription` resources across compartments
1111
- Support for moving `oci_load_balancer` across compartments
1212
- Support for moving `oci_kms_key` and `oci_kms_vault` Across Compartments
13+
- Support for LBaaS Cookie Insertion (Sticky Cookie)
1314

1415
## 3.33.0 (July 10, 2019)
1516

examples/load_balancer/lb_private/lb_private.tf

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,29 @@ resource "oci_load_balancer_backend_set" "lb-bes1" {
8383
}
8484
}
8585

86+
resource "oci_load_balancer_backend_set" "lb-bes2" {
87+
name = "lb-bes2"
88+
load_balancer_id = "${oci_load_balancer.lb1.id}"
89+
policy = "ROUND_ROBIN"
90+
91+
health_checker {
92+
port = "80"
93+
protocol = "HTTP"
94+
response_body_regex = ".*"
95+
url_path = "/"
96+
}
97+
98+
lb_cookie_session_persistence_configuration {
99+
cookie_name = "example_cookie"
100+
domain = "example.oracle.com"
101+
is_http_only = false
102+
is_secure = false
103+
max_age_in_seconds = 10
104+
path = "/example"
105+
disable_fallback = true
106+
}
107+
}
108+
86109
resource "oci_core_network_security_group" "test_network_security_group" {
87110
#Required
88111
compartment_id = "${var.compartment_ocid}"

oci/load_balancer_backend_set_resource.go

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,57 @@ func LoadBalancerBackendSetResource() *schema.Resource {
147147
},
148148
},
149149
},
150+
"lb_cookie_session_persistence_configuration": {
151+
Type: schema.TypeList,
152+
Optional: true,
153+
Computed: true,
154+
MaxItems: 1,
155+
MinItems: 1,
156+
Elem: &schema.Resource{
157+
Schema: map[string]*schema.Schema{
158+
// Required
159+
160+
// Optional
161+
"cookie_name": {
162+
Type: schema.TypeString,
163+
Optional: true,
164+
Computed: true,
165+
},
166+
"disable_fallback": {
167+
Type: schema.TypeBool,
168+
Optional: true,
169+
Computed: true,
170+
},
171+
"domain": {
172+
Type: schema.TypeString,
173+
Optional: true,
174+
Computed: true,
175+
},
176+
"is_http_only": {
177+
Type: schema.TypeBool,
178+
Optional: true,
179+
Computed: true,
180+
},
181+
"is_secure": {
182+
Type: schema.TypeBool,
183+
Optional: true,
184+
Computed: true,
185+
},
186+
"max_age_in_seconds": {
187+
Type: schema.TypeInt,
188+
Optional: true,
189+
Computed: true,
190+
},
191+
"path": {
192+
Type: schema.TypeString,
193+
Optional: true,
194+
Computed: true,
195+
},
196+
197+
// Computed
198+
},
199+
},
200+
},
150201
"session_persistence_configuration": {
151202
Type: schema.TypeList,
152203
Optional: true,
@@ -313,6 +364,17 @@ func (s *LoadBalancerBackendSetResourceCrud) Create() error {
313364
}
314365
}
315366

367+
if lbCookieSessionPersistenceConfiguration, ok := s.D.GetOkExists("lb_cookie_session_persistence_configuration"); ok {
368+
if tmpList := lbCookieSessionPersistenceConfiguration.([]interface{}); len(tmpList) > 0 {
369+
fieldKeyFormat := fmt.Sprintf("%s.%d.%%s", "lb_cookie_session_persistence_configuration", 0)
370+
tmp, err := s.mapToLBCookieSessionPersistenceConfigurationDetails(fieldKeyFormat)
371+
if err != nil {
372+
return err
373+
}
374+
request.LbCookieSessionPersistenceConfiguration = &tmp
375+
}
376+
}
377+
316378
if loadBalancerId, ok := s.D.GetOkExists("load_balancer_id"); ok {
317379
tmp := loadBalancerId.(string)
318380
request.LoadBalancerId = &tmp
@@ -459,6 +521,17 @@ func (s *LoadBalancerBackendSetResourceCrud) Update() error {
459521
}
460522
}
461523

524+
if lbCookieSessionPersistenceConfiguration, ok := s.D.GetOkExists("lb_cookie_session_persistence_configuration"); ok {
525+
if tmpList := lbCookieSessionPersistenceConfiguration.([]interface{}); len(tmpList) > 0 {
526+
fieldKeyFormat := fmt.Sprintf("%s.%d.%%s", "lb_cookie_session_persistence_configuration", 0)
527+
tmp, err := s.mapToLBCookieSessionPersistenceConfigurationDetails(fieldKeyFormat)
528+
if err != nil {
529+
return err
530+
}
531+
request.LbCookieSessionPersistenceConfiguration = &tmp
532+
}
533+
}
534+
462535
if loadBalancerId, ok := s.D.GetOkExists("load_balancer_id"); ok {
463536
tmp := loadBalancerId.(string)
464537
request.LoadBalancerId = &tmp
@@ -576,6 +649,12 @@ func (s *LoadBalancerBackendSetResourceCrud) SetData() error {
576649
s.D.Set("health_checker", nil)
577650
}
578651

652+
if s.Res.LbCookieSessionPersistenceConfiguration != nil {
653+
s.D.Set("lb_cookie_session_persistence_configuration", []interface{}{LBCookieSessionPersistenceConfigurationDetailsToMap(s.Res.LbCookieSessionPersistenceConfiguration)})
654+
} else {
655+
s.D.Set("lb_cookie_session_persistence_configuration", nil)
656+
}
657+
579658
if s.Res.Name != nil {
580659
s.D.Set("name", *s.Res.Name)
581660
}
@@ -773,6 +852,81 @@ func HealthCheckerToMap(obj *oci_load_balancer.HealthChecker) map[string]interfa
773852
return result
774853
}
775854

855+
func (s *LoadBalancerBackendSetResourceCrud) mapToLBCookieSessionPersistenceConfigurationDetails(fieldKeyFormat string) (oci_load_balancer.LbCookieSessionPersistenceConfigurationDetails, error) {
856+
result := oci_load_balancer.LbCookieSessionPersistenceConfigurationDetails{}
857+
858+
if cookieName, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "cookie_name")); ok {
859+
tmp := cookieName.(string)
860+
result.CookieName = &tmp
861+
}
862+
863+
if disableFallback, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "disable_fallback")); ok {
864+
tmp := disableFallback.(bool)
865+
result.DisableFallback = &tmp
866+
}
867+
868+
if domain, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "domain")); ok {
869+
tmp := domain.(string)
870+
result.Domain = &tmp
871+
}
872+
873+
if isHttpOnly, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "is_http_only")); ok {
874+
tmp := isHttpOnly.(bool)
875+
result.IsHttpOnly = &tmp
876+
}
877+
878+
if isSecure, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "is_secure")); ok {
879+
tmp := isSecure.(bool)
880+
result.IsSecure = &tmp
881+
}
882+
883+
if maxAgeInSeconds, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "max_age_in_seconds")); ok {
884+
tmp := maxAgeInSeconds.(int)
885+
result.MaxAgeInSeconds = &tmp
886+
}
887+
888+
if path, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "path")); ok {
889+
tmp := path.(string)
890+
result.Path = &tmp
891+
}
892+
893+
return result, nil
894+
}
895+
896+
func LBCookieSessionPersistenceConfigurationDetailsToMap(obj *oci_load_balancer.LbCookieSessionPersistenceConfigurationDetails) map[string]interface{} {
897+
result := map[string]interface{}{}
898+
899+
if obj.CookieName != nil {
900+
result["cookie_name"] = string(*obj.CookieName)
901+
}
902+
903+
if obj.DisableFallback != nil {
904+
result["disable_fallback"] = bool(*obj.DisableFallback)
905+
}
906+
907+
if obj.Domain != nil {
908+
result["domain"] = string(*obj.Domain)
909+
}
910+
911+
if obj.IsHttpOnly != nil {
912+
result["is_http_only"] = bool(*obj.IsHttpOnly)
913+
}
914+
915+
if obj.IsSecure != nil {
916+
result["is_secure"] = bool(*obj.IsSecure)
917+
}
918+
919+
if obj.MaxAgeInSeconds != nil {
920+
result["max_age_in_seconds"] = int(*obj.MaxAgeInSeconds)
921+
}
922+
923+
if obj.Path != nil {
924+
result["path"] = string(*obj.Path)
925+
}
926+
927+
return result
928+
}
929+
776930
func (s *LoadBalancerBackendSetResourceCrud) mapToSSLConfigurationDetails(fieldKeyFormat string) (oci_load_balancer.SslConfigurationDetails, error) {
777931
result := oci_load_balancer.SslConfigurationDetails{}
778932

0 commit comments

Comments
 (0)