Shorten resource names

Naming resources helps to quickly identify them via aws-cli and via the
AWS console UI, so that their intent is clear.

However AWS requires that resource names be no longer than 32
characters.

Given the current naming, it is quite easy to reach that threshold
since the name concatenates the stack name and a significantly long
string name.

For example, with the current naming convention, for a stack named
simply 'production', the name of the capacity provider name would
end up being:

production-replica-CapacityProvider

The above is already 37 characters long and thus it would violate the 32
characters constraint.

Mitigate this issue by:
- Removing obvious suffixes: i.e. capacity providers names do not need
  'CapcityProvider' suffix, since they can already be found under the
  'CapacityProvider' section.

- Sacrifice a bit of clarity by using the following convention:
 * R - Replica
 * P - Primary
 * H - HTTP protocol
 * S - SSH protocol
 * G - GIT protocol

Bug: Issue 15235
Change-Id: I7496450e9f03050a79b1395d7d475aea1a5bc710
diff --git a/README.md b/README.md
index ff94659..1ace590 100644
--- a/README.md
+++ b/README.md
@@ -65,6 +65,38 @@
 All recipes stream every log to CloudWatch. This always includes `sshd_log`,
 `httpd_log` and `gc_log`.
 
+## Resource names
+
+When possible AWS resources are explicitly named so that they can be easily
+distinguished when querying them via the aws-cli, or the AWS UI console, so that
+their intent is clear.
+
+However, AWS requires that resource names be no longer than 32 characters. For
+this reason we adopt a naming-convention that trades off a bit of clarity in
+favour of a more economical usage of characters.
+
+* R - Replica
+* P - Primary
+* H - HTTP protocol
+* S - SSH protocol
+* G - GIT protocol
+
+Some examples:
+
+* In the `Load Balancers` section:
+    - `production-P-H` stands
+      for `Load Balancer serving HTTP traffic to the Primary Gerrit`
+    - `production-R-S` stands
+      for `Load Balancer serving SSH traffic to the Gerrit Replica`
+    - `production-Ps-H` stands
+      for `Load Balancer serving SSH traffic to both Gerrit primary instances`
+
+* In the `Target Groups` section:
+    - `production-P1-H` stands
+      for `Target Group registering the Primary1 Gerrit instance listening over HTTP`
+    - `production-R-GS` stands
+      for `Target Group registering the Replica Gerrit instances listening over Git and SSH`
+
 #### error_log
 The 'error_log' might or might not be available depending on which version of
 gerrit is being deployed.
diff --git a/dual-primary/cf-cluster.yml b/dual-primary/cf-cluster.yml
index 787d7a5..8a1caa0 100644
--- a/dual-primary/cf-cluster.yml
+++ b/dual-primary/cf-cluster.yml
@@ -197,7 +197,7 @@
   ReplicaCapacityProvider:
     Type: AWS::ECS::CapacityProvider
     Properties:
-      Name: !Sub '${AWS::StackName}-ReplicaCapacityProvider'
+      Name: !Sub '${AWS::StackName}-R'
       AutoScalingGroupProvider:
         AutoScalingGroupArn: !Ref ReplicaECSAutoScalingGroup
         ManagedTerminationProtection: ENABLED
@@ -271,7 +271,7 @@
     Properties:
       VpcId: !If [NetworkStackNeeded, !GetAtt ECSTaskNetworkStack.Outputs.VPCRef, !Ref VPCIdProp]
       GroupDescription: "Allow public HTTPS traffic to primaries gerrit"
-      GroupName: !Sub '${AWS::StackName}-primaries-http'
+      GroupName: !Sub '${AWS::StackName}-Ps-H'
       SecurityGroupIngress:
         - IpProtocol: 'tcp'
           FromPort: !FindInMap ['Gerrit', 'Port', 'HTTPS']
@@ -287,7 +287,7 @@
   PrimariesHTTPGerritLoadBalancer:
     Type: AWS::ElasticLoadBalancingV2::LoadBalancer
     Properties:
-      Name: !Sub '${AWS::StackName}-http-primaries'
+      Name: !Sub '${AWS::StackName}-P-H'
       Type: application
       Scheme: !Ref PrimariesGerritLoadBalancerScheme
       SecurityGroups:
@@ -301,7 +301,7 @@
     Properties:
       Type: network
       Scheme: !Ref PrimariesGerritLoadBalancerScheme
-      Name: !Sub '${AWS::StackName}-ssh-primaries'
+      Name: !Sub '${AWS::StackName}-Ps-S'
       LoadBalancerAttributes:
         - Key: 'load_balancing.cross_zone.enabled'
           Value: true
@@ -319,7 +319,7 @@
       HealthCheckPort: !FindInMap ['Gerrit', 'Port', 'HTTP']
       HealthCheckProtocol: HTTP
       HealthCheckPath: '/config/server/healthcheck~status'
-      Name: !Sub '${AWS::StackName}-primaries-http'
+      Name: !Sub '${AWS::StackName}-Ps-H'
       TargetGroupAttributes:
         - Key: 'stickiness.enabled'
           Value: true
@@ -348,7 +348,7 @@
       HealthCheckPort: !FindInMap ['Gerrit', 'Port', 'HTTP']
       HealthCheckProtocol: HTTP
       HealthCheckPath: '/config/server/healthcheck~status'
-      Name: !Sub '${AWS::StackName}-primaries-ssh'
+      Name: !Sub '${AWS::StackName}-Ps-S'
 
   PrimariesGerritSSHListener:
     Type: AWS::ElasticLoadBalancingV2::Listener
diff --git a/dual-primary/cf-service-primary.yml b/dual-primary/cf-service-primary.yml
index 70b2a50..6bcd1f6 100644
--- a/dual-primary/cf-service-primary.yml
+++ b/dual-primary/cf-service-primary.yml
@@ -413,7 +413,7 @@
           Fn::ImportValue:
             !Join [':', [!Ref 'ClusterStackName', 'VPCId']]
         GroupDescription: "Allow public HTTP traffic to primary Gerrit"
-        GroupName: !Sub '${ClusterStackName}-primary${GerritInstanceNumber}-http'
+        GroupName: !Sub '${ClusterStackName}-P${GerritInstanceNumber}-H'
         SecurityGroupIngress:
           - IpProtocol: 'tcp'
             FromPort: !FindInMap ['Gerrit', 'Port', 'HTTP']
@@ -429,7 +429,7 @@
     GerritHTTPLoadBalancer:
       Type: AWS::ElasticLoadBalancingV2::LoadBalancer
       Properties:
-        Name: !Sub '${ClusterStackName}-primary${GerritInstanceNumber}-http'
+        Name: !Sub '${ClusterStackName}-P${GerritInstanceNumber}-H'
         Type: application
         Scheme: !Ref 'LoadBalancerScheme'
         SecurityGroups:
@@ -446,7 +446,7 @@
     GerritSSHLoadBalancer:
         Type: AWS::ElasticLoadBalancingV2::LoadBalancer
         Properties:
-            Name: !Sub '${AWS::StackName}-primary${GerritInstanceNumber}-ssh'
+            Name: !Sub '${AWS::StackName}-P${GerritInstanceNumber}-S'
             Type: network
             Scheme: !Ref 'LoadBalancerScheme'
             LoadBalancerAttributes:
@@ -473,7 +473,7 @@
             HealthCheckPort: !FindInMap ['Gerrit', 'Port', 'HTTP']
             HealthCheckProtocol: HTTP
             HealthCheckPath: '/config/server/healthcheck~status'
-            Name: !Sub '${AWS::StackName}-primary${GerritInstanceNumber}-http'
+            Name: !Sub '${AWS::StackName}-P${GerritInstanceNumber}-H'
 
     HTTPListener:
         Type: AWS::ElasticLoadBalancingV2::Listener
@@ -498,7 +498,7 @@
             HealthCheckPort: !FindInMap ['Gerrit', 'Port', 'HTTP']
             HealthCheckProtocol: HTTP
             HealthCheckPath: '/config/server/healthcheck~status'
-            Name: !Sub '${AWS::StackName}-primary${GerritInstanceNumber}-ssh'
+            Name: !Sub '${AWS::StackName}-P${GerritInstanceNumber}-S'
 
     SSHListener:
         Type: AWS::ElasticLoadBalancingV2::Listener
diff --git a/dual-primary/cf-service-replica.yml b/dual-primary/cf-service-replica.yml
index cab9668..85eab10 100644
--- a/dual-primary/cf-service-replica.yml
+++ b/dual-primary/cf-service-replica.yml
@@ -227,7 +227,7 @@
               Fn::ImportValue:
                   !Join [':', [!Ref 'ClusterStackName', 'ClusterName']]
             CapacityProviderStrategy:
-              - CapacityProvider: !Sub '${ClusterStackName}-ReplicaCapacityProvider'
+              - CapacityProvider: !Sub '${ClusterStackName}-R'
                 Weight: 100
             DesiredCount: !Ref ReplicaAutoScalingDesiredCapacity
             TaskDefinition: !Ref GerritTaskDefinition
@@ -441,7 +441,7 @@
           Fn::ImportValue:
             !Join [':', [!Ref 'ClusterStackName', 'VPCId']]
         GroupDescription: "Allow public HTTPS traffic to replicas"
-        GroupName: !Sub '${ClusterStackName}-replica-http'
+        GroupName: !Sub '${ClusterStackName}-R-H'
         SecurityGroupIngress:
           - IpProtocol: 'tcp'
             FromPort: !Ref HTTPSPort
@@ -457,7 +457,7 @@
     ReplicaHTTPLoadBalancer:
       Type: AWS::ElasticLoadBalancingV2::LoadBalancer
       Properties:
-        Name: !Sub '${ClusterStackName}-replica-http'
+        Name: !Sub '${ClusterStackName}-R-H'
         Type: application
         Scheme: !Ref 'LoadBalancerScheme'
         SecurityGroups:
@@ -474,7 +474,7 @@
     ReplicaSSHLoadBalancer:
         Type: AWS::ElasticLoadBalancingV2::LoadBalancer
         Properties:
-            Name: !Sub '${ClusterStackName}-replica-ssh'
+            Name: !Sub '${ClusterStackName}-R-S'
             Type: network
             Scheme: !Ref 'LoadBalancerScheme'
             LoadBalancerAttributes:
@@ -501,7 +501,7 @@
             HealthCheckPort: !Ref HTTPHostPort
             HealthCheckProtocol: HTTP
             HealthCheckPath: '/config/server/healthcheck~status'
-            Name: !Sub '${AWS::StackName}-replica-http'
+            Name: !Sub '${AWS::StackName}-R-H'
             TargetGroupAttributes:
               - Key: 'stickiness.enabled'
                 Value: true
@@ -532,7 +532,7 @@
             HealthCheckPort: !Ref HTTPHostPort
             HealthCheckProtocol: HTTP
             HealthCheckPath: '/config/server/healthcheck~status'
-            Name: !Sub '${AWS::StackName}-replica-ssh'
+            Name: !Sub '${AWS::StackName}-R-S'
 
     SSHListener:
         Type: AWS::ElasticLoadBalancingV2::Listener
@@ -553,7 +553,7 @@
                   !Join [':', [!Ref 'ClusterStackName', 'VPCId']]
             Port: !Ref GitPort
             Protocol: TCP
-            Name: !Sub '${AWS::StackName}-replica-git'
+            Name: !Sub '${AWS::StackName}-R-G'
 
     GitListener:
         Type: AWS::ElasticLoadBalancingV2::Listener
@@ -574,7 +574,7 @@
                   !Join [':', [!Ref 'ClusterStackName', 'VPCId']]
             Port: !Ref GitSSHPort
             Protocol: TCP
-            Name: !Sub '${AWS::StackName}-replica-gitssh'
+            Name: !Sub '${AWS::StackName}-R-GS'
 
     GitSSHListener:
         Type: AWS::ElasticLoadBalancingV2::Listener
diff --git a/primary-replica/cf-cluster.yml b/primary-replica/cf-cluster.yml
index f80166e..f7a2e18 100644
--- a/primary-replica/cf-cluster.yml
+++ b/primary-replica/cf-cluster.yml
@@ -154,7 +154,7 @@
   ReplicaCapacityProvider:
     Type: AWS::ECS::CapacityProvider
     Properties:
-      Name: !Sub '${AWS::StackName}-ReplicaCapacityProvider'
+      Name: !Sub '${AWS::StackName}-R'
       AutoScalingGroupProvider:
         AutoScalingGroupArn: !Ref ReplicaASG
         ManagedTerminationProtection: ENABLED
diff --git a/primary-replica/cf-service-primary.yml b/primary-replica/cf-service-primary.yml
index 10a0642..6dc2a74 100644
--- a/primary-replica/cf-service-primary.yml
+++ b/primary-replica/cf-service-primary.yml
@@ -347,7 +347,7 @@
           Fn::ImportValue:
             !Join [':', [!Ref 'ClusterStackName', 'VPCId']]
         GroupDescription: "Allow public HTTPS traffic to primary Gerrit"
-        GroupName: !Sub '${ClusterStackName}-gerrit-http-sg'
+        GroupName: !Sub '${ClusterStackName}-P-H'
         SecurityGroupIngress:
           - IpProtocol: 'tcp'
             FromPort: !Ref HTTPSPort
@@ -363,7 +363,7 @@
     GerritHTTPLoadBalancer:
       Type: AWS::ElasticLoadBalancingV2::LoadBalancer
       Properties:
-        Name: !Sub '${ClusterStackName}-primary-http'
+        Name: !Sub '${ClusterStackName}-P-H'
         Type: application
         Scheme: !Ref 'LoadBalancerScheme'
         SecurityGroups:
@@ -380,7 +380,7 @@
     GerritSSHLoadBalancer:
         Type: AWS::ElasticLoadBalancingV2::LoadBalancer
         Properties:
-            Name: !Sub '${ClusterStackName}-primary-ssh'
+            Name: !Sub '${ClusterStackName}-P-S'
             Type: network
             Scheme: !Ref 'LoadBalancerScheme'
             LoadBalancerAttributes:
@@ -407,7 +407,7 @@
             HealthCheckProtocol: HTTP
             HealthCheckPort: !Ref HTTPPort
             HealthCheckPath: '/config/server/healthcheck~status'
-            Name: !Sub '${ClusterStackName}-primary-http'
+            Name: !Sub '${ClusterStackName}-P-H'
 
     HTTPListener:
         Type: AWS::ElasticLoadBalancingV2::Listener
@@ -433,7 +433,7 @@
             HealthCheckProtocol: HTTP
             HealthCheckPort: !Ref HTTPPort
             HealthCheckPath: '/config/server/healthcheck~status'
-            Name: !Sub '${ClusterStackName}-primary-ssh'
+            Name: !Sub '${ClusterStackName}-P-S'
 
     SSHListener:
         Type: AWS::ElasticLoadBalancingV2::Listener
diff --git a/primary-replica/cf-service-replica.yml b/primary-replica/cf-service-replica.yml
index e7a75df..281db8b 100644
--- a/primary-replica/cf-service-replica.yml
+++ b/primary-replica/cf-service-replica.yml
@@ -227,7 +227,7 @@
               Fn::ImportValue:
                   !Join [':', [!Ref 'ClusterStackName', 'ClusterName']]
             CapacityProviderStrategy:
-              - CapacityProvider: !Sub '${ClusterStackName}-ReplicaCapacityProvider'
+              - CapacityProvider: !Sub '${ClusterStackName}-R'
                 Weight: 100
             DesiredCount: !Ref ReplicaAutoScalingDesiredCapacity
             TaskDefinition: !Ref GerritTaskDefinition
@@ -441,7 +441,7 @@
           Fn::ImportValue:
             !Join [':', [!Ref 'ClusterStackName', 'VPCId']]
         GroupDescription: "Allow public HTTPS traffic to replicas"
-        GroupName: !Sub '${ClusterStackName}-replica-http-sg'
+        GroupName: !Sub '${ClusterStackName}-R-H'
         SecurityGroupIngress:
           - IpProtocol: 'tcp'
             FromPort: !Ref HTTPSPort
@@ -457,7 +457,7 @@
     ReplicaHTTPLoadBalancer:
       Type: AWS::ElasticLoadBalancingV2::LoadBalancer
       Properties:
-        Name: !Sub '${ClusterStackName}-replica-http'
+        Name: !Sub '${ClusterStackName}-R-H'
         Type: application
         Scheme: !Ref 'LoadBalancerScheme'
         SecurityGroups:
@@ -474,7 +474,7 @@
     ReplicaSSHLoadBalancer:
         Type: AWS::ElasticLoadBalancingV2::LoadBalancer
         Properties:
-            Name: !Sub '${ClusterStackName}-replica-ssh'
+            Name: !Sub '${ClusterStackName}-R-S'
             Type: network
             Scheme: !Ref 'LoadBalancerScheme'
             LoadBalancerAttributes:
@@ -501,7 +501,7 @@
             HealthCheckPort: !Ref HTTPHostPort
             HealthCheckProtocol: HTTP
             HealthCheckPath: '/config/server/healthcheck~status'
-            Name: !Sub '${ClusterStackName}-replica-http'
+            Name: !Sub '${ClusterStackName}-R-H'
             TargetGroupAttributes:
               - Key: 'stickiness.enabled'
                 Value: true
@@ -532,7 +532,7 @@
             HealthCheckPort: !Ref HTTPHostPort
             HealthCheckProtocol: HTTP
             HealthCheckPath: '/config/server/healthcheck~status'
-            Name: !Sub '${ClusterStackName}-replica-ssh'
+            Name: !Sub '${ClusterStackName}-R-S'
 
     SSHListener:
         Type: AWS::ElasticLoadBalancingV2::Listener
diff --git a/single-primary/cf-service.yml b/single-primary/cf-service.yml
index 7b9fb06..72994a5 100644
--- a/single-primary/cf-service.yml
+++ b/single-primary/cf-service.yml
@@ -325,7 +325,7 @@
           Fn::ImportValue:
             !Join [':', [!Ref 'ClusterStackName', 'VPCId']]
         GroupDescription: "Allow public HTTPS traffic"
-        GroupName: !Sub '${ClusterStackName}-primary-http'
+        GroupName: !Sub '${ClusterStackName}-P-H'
         SecurityGroupIngress:
           - IpProtocol: 'tcp'
             FromPort: !Ref HTTPSPort
@@ -342,7 +342,7 @@
     GerritHTTPLoadBalancer:
       Type: AWS::ElasticLoadBalancingV2::LoadBalancer
       Properties:
-        Name: !Sub '${ClusterStackName}-primary-http'
+        Name: !Sub '${ClusterStackName}-P-H'
         Type: application
         Scheme: !Ref 'LoadBalancerScheme'
         SecurityGroups:
@@ -359,7 +359,7 @@
     GerritSSHLoadBalancer:
         Type: AWS::ElasticLoadBalancingV2::LoadBalancer
         Properties:
-            Name: !Sub '${ClusterStackName}-primary-ssh'
+            Name: !Sub '${ClusterStackName}-P-S'
             Type: network
             Scheme: !Ref 'LoadBalancerScheme'
             LoadBalancerAttributes:
@@ -386,7 +386,7 @@
             HealthCheckProtocol: HTTP
             HealthCheckPort: !Ref HTTPPort
             HealthCheckPath: '/config/server/healthcheck~status'
-            Name: !Sub '${ClusterStackName}-primary-http'
+            Name: !Sub '${ClusterStackName}-P-H'
 
     HTTPListener:
         Type: AWS::ElasticLoadBalancingV2::Listener
@@ -412,7 +412,7 @@
             HealthCheckProtocol: HTTP
             HealthCheckPort: !Ref HTTPPort
             HealthCheckPath: '/config/server/healthcheck~status'
-            Name: !Sub '${ClusterStackName}-primary-ssh'
+            Name: !Sub '${ClusterStackName}-P-S'
 
     SSHListener:
         Type: AWS::ElasticLoadBalancingV2::Listener