Populate instanceId for master-slave recipe

Feature: Issue 13230
Change-Id: I47877b3f8d5afa03a97c77da56e2838770df4a71
diff --git a/master-slave/Makefile b/master-slave/Makefile
index 8165414..16c217a 100644
--- a/master-slave/Makefile
+++ b/master-slave/Makefile
@@ -45,6 +45,9 @@
 ifdef LOAD_BALANCER_SCHEME
 		$(eval MASTER_SERVICE_OPTIONAL_PARAMS := $(MASTER_SERVICE_OPTIONAL_PARAMS) ParameterKey=LoadBalancerScheme,ParameterValue=$(LOAD_BALANCER_SCHEME))
 endif
+ifdef GERRIT_MASTER_INSTANCE_ID
+		$(eval MASTER_SERVICE_OPTIONAL_PARAMS := $(MASTER_SERVICE_OPTIONAL_PARAMS) ParameterKey=InstanceId,ParameterValue=$(GERRIT_MASTER_INSTANCE_ID))
+endif
 
 	$(AWS_FC_COMMAND) create-stack \
 		--stack-name $(SERVICE_MASTER_STACK_NAME) \
@@ -80,6 +83,9 @@
 ifdef LOAD_BALANCER_SCHEME
 		$(eval SLAVE_SERVICE_OPTIONAL_PARAMS := $(SLAVE_SERVICE_OPTIONAL_PARAMS) ParameterKey=LoadBalancerScheme,ParameterValue=$(LOAD_BALANCER_SCHEME))
 endif
+ifdef GERRIT_SLAVE_INSTANCE_ID
+		$(eval SLAVE_SERVICE_OPTIONAL_PARAMS := $(SLAVE_SERVICE_OPTIONAL_PARAMS) ParameterKey=InstanceId,ParameterValue=$(GERRIT_SLAVE_INSTANCE_ID))
+endif
 
 	$(AWS_FC_COMMAND) create-stack \
 		--stack-name $(SERVICE_SLAVE_STACK_NAME) \
diff --git a/master-slave/README.md b/master-slave/README.md
index 0363deb..4338ac8 100644
--- a/master-slave/README.md
+++ b/master-slave/README.md
@@ -75,6 +75,10 @@
 * `MASTER_SUBDOMAIN`: Optional. Name of the master sub domain. `gerrit-master-demo` by default.
 * `SLAVE_SUBDOMAIN`: Optional. Name of the slave sub domain. `gerrit-slave-demo` by default.
 * `CLUSTER_DESIRED_CAPACITY`: Optional. Number of EC2 instances composing the cluster. `1` by default.
+* `GERRIT_MASTER_INSTANCE_ID`: Optional. Identifier for the Gerrit master instance.
+"gerrit-master-slave-MASTER" by default.
+* `GERRIT_SLAVE_INSTANCE_ID`: Optional. Identifier for the Gerrit slave instance.
+"gerrit-master-slave-SLAVE" by default.
 
 *NOTE*: if you are planning to run the monitoring stack, set the
 `CLUSTER_DESIRED_CAPACITY` value to at least 2. The resources provided by
diff --git a/master-slave/cf-service-master.yml b/master-slave/cf-service-master.yml
index 1bee898..a38c939 100644
--- a/master-slave/cf-service-master.yml
+++ b/master-slave/cf-service-master.yml
@@ -135,6 +135,10 @@
   SMTPDomain:
       Description: Domain to be used in the From field
       Type: String
+  InstanceId:
+    Description: Optional identifier for the Gerrit instance
+    Type: String
+    Default: gerrit-master-slave-MASTER
   MetricsCloudwatchEnabled:
     Description: Whether gerrit metrics should be published to cloudwatch
     Type: String
@@ -227,6 +231,8 @@
                       Value: !Ref SMTPUser
                     - Name: SMTP_DOMAIN
                       Value: !Ref SMTPDomain
+                    - Name: GERRIT_INSTANCE_ID
+                      Value: !Ref InstanceId
                     - Name: GIT_PORT
                       Value: !Ref GitPort
                     - Name: GIT_SSH_PORT
diff --git a/master-slave/cf-service-slave.yml b/master-slave/cf-service-slave.yml
index eba0d6b..6afa666 100644
--- a/master-slave/cf-service-slave.yml
+++ b/master-slave/cf-service-slave.yml
@@ -138,6 +138,10 @@
   LDAPGroupBase:
       Description: Root of the tree containing all group objects
       Type: String
+  InstanceId:
+    Description: Optional identifier for the Gerrit instance
+    Type: String
+    Default: gerrit-master-slave-SLAVE
   MetricsCloudwatchEnabled:
     Description: Whether gerrit metrics should be published to cloudwatch
     Type: String
@@ -232,6 +236,8 @@
                       Value: !Ref LDAPAccountBase
                     - Name: LDAP_GROUP_BASE
                       Value: !Ref LDAPGroupBase
+                    - Name: GERRIT_INSTANCE_ID
+                      Value: !Ref InstanceId
                     - Name: METRICS_CLOUDWATCH_ENABLED
                       Value: !Ref MetricsCloudwatchEnabled
                     - Name: METRICS_CLOUDWATCH_NAMESPACE
diff --git a/master-slave/setup.env.template b/master-slave/setup.env.template
index 1035cf5..4a295ff 100644
--- a/master-slave/setup.env.template
+++ b/master-slave/setup.env.template
@@ -19,6 +19,9 @@
 GERRIT_HEAP_LIMIT=6g
 JGIT_CACHE_SIZE=3g
 
+GERRIT_MASTER_INSTANCE_ID=gerrit-master-slave-MASTER
+GERRIT_SLAVE_INSTANCE_ID=gerrit-master-slave-SLAVE
+
 LDAP_SERVER:=ldap://yourldap.yourcompany.com
 LDAP_USERNAME:=cn=admin,dc=example,dc=org
 LDAP_ACCOUNT_BASE:=dc=example,dc=org