Enable sticky sessions for HTTP targets

Network load balancers that forward to target groups registering more
than one target need to have sticky session enabled.

This ensures that all requests from the user during the session are sent
to the same target.

Currently network load balancers are used across the board, so the only
available stickiness type is based on client IP address. This can be
changed for HTTP requests when the load balancers are updated to be
Application Load Balancers.

There are only two target groups that register multiple targets, the
replica and the primaries gerrit target groups, so stickiness has
been enabled for those only.

Bug: Issue 15126
Change-Id: Ie735ab22749e145dab6b25a5e0da37b49e3772ff
diff --git a/dual-primary/cf-cluster.yml b/dual-primary/cf-cluster.yml
index fd456ac..620dd01 100644
--- a/dual-primary/cf-cluster.yml
+++ b/dual-primary/cf-cluster.yml
@@ -328,6 +328,13 @@
       HealthCheckProtocol: HTTP
       HealthCheckPath: '/config/server/healthcheck~status'
       Name: 'primaries-gerrit-http'
+      TargetGroupAttributes:
+        - Key: 'stickiness.enabled'
+          Value: true
+        # NLB only supports source_ip. Move this to `lb_cookie` or `app_cookie`
+        # when this target group is moved behind an ALB
+        - Key: 'stickiness.type'
+          Value: 'source_ip'
 
   PrimariesGerritHTTPSListener:
     Type: AWS::ElasticLoadBalancingV2::Listener
diff --git a/dual-primary/cf-service-replica.yml b/dual-primary/cf-service-replica.yml
index 12f078a..df360e7 100644
--- a/dual-primary/cf-service-replica.yml
+++ b/dual-primary/cf-service-replica.yml
@@ -458,6 +458,13 @@
             HealthCheckProtocol: HTTP
             HealthCheckPath: '/config/server/healthcheck~status'
             Name: 'gerrit-replica-http'
+            TargetGroupAttributes:
+              - Key: 'stickiness.enabled'
+                Value: true
+              # NLB only supports source_ip. Move this to `lb_cookie` or `app_cookie`
+              # when this target group is moved behind an ALB
+              - Key: 'stickiness.type'
+                Value: 'source_ip'
 
     HTTPListener:
         Type: AWS::ElasticLoadBalancingV2::Listener
diff --git a/primary-replica/cf-service-replica.yml b/primary-replica/cf-service-replica.yml
index d02b033..bf8be87 100644
--- a/primary-replica/cf-service-replica.yml
+++ b/primary-replica/cf-service-replica.yml
@@ -458,6 +458,13 @@
             HealthCheckProtocol: HTTP
             HealthCheckPath: '/config/server/healthcheck~status'
             Name: 'gerrit-replica-http'
+            TargetGroupAttributes:
+              - Key: 'stickiness.enabled'
+                Value: true
+              # NLB only supports source_ip. Move this to `lb_cookie` or `app_cookie`
+              # when this target group is moved behind an ALB
+              - Key: 'stickiness.type'
+                Value: 'source_ip'
 
     HTTPListener:
         Type: AWS::ElasticLoadBalancingV2::Listener