Allow template S3 bucket to be configured

Before this change all recipes were pointing to the gerritforgeaws
template bucket. This was making it impossible to deploy to any AWS
account or region other than the gerritforgeaws one.

Fix this issue by allowing the S3 bucket name to be configured and
injected to the cloudformation templates.

This is now a required pre-requisite and thus the configuration has been
changed accordingly.

Bug: Issue 13096
Change-Id: Ie7cf672cec31b940636e959946ccdab4438d2438
diff --git a/Prerequisites.md b/Prerequisites.md
index 514598e..550e1c3 100644
--- a/Prerequisites.md
+++ b/Prerequisites.md
@@ -23,3 +23,7 @@
 
 * an SSL Certificate in AWS Certificate Manager (you can find more information on
   how to create and handle certificates in AWS [here](https://aws.amazon.com/certificate-manager/getting-started/)
+
+* An S3 bucket is required in order to store cloudformation templates that are used to build the stacks.
+You must edit the `common.env` file and set the `TEMPLATE_BUCKET_NAME`. The bucket will then be created
+the first time you run a deployment. Note that the at the moment the bucket accessibility is public.
diff --git a/dual-master/Makefile b/dual-master/Makefile
index 2553e09..cf6f4be 100644
--- a/dual-master/Makefile
+++ b/dual-master/Makefile
@@ -1,4 +1,5 @@
 include setup.env
+include ../common.env
 include ../Makefile.common
 
 CLUSTER_TEMPLATE:=cf-cluster.yml
@@ -50,6 +51,7 @@
 		ParameterKey=SMTPUser,ParameterValue=$(SMTP_USER) \
 		ParameterKey=SMTPDomain,ParameterValue=$(SMTP_DOMAIN) \
 		ParameterKey=ClusterStackName,ParameterValue=$(CLUSTER_STACK_NAME) \
+		ParameterKey=TemplateBucketName,ParameterValue=$(TEMPLATE_BUCKET_NAME) \
 		ParameterKey=HostedZoneName,ParameterValue=$(HOSTED_ZONE_NAME) \
 		ParameterKey=Subdomain,ParameterValue=$(MASTER1_SUBDOMAIN) \
 		ParameterKey=SlaveSubdomain,ParameterValue=$(SLAVE_SUBDOMAIN) \
@@ -88,6 +90,7 @@
 		ParameterKey=SMTPUser,ParameterValue=$(SMTP_USER) \
 		ParameterKey=SMTPDomain,ParameterValue=$(SMTP_DOMAIN) \
 		ParameterKey=ClusterStackName,ParameterValue=$(CLUSTER_STACK_NAME) \
+		ParameterKey=TemplateBucketName,ParameterValue=$(TEMPLATE_BUCKET_NAME) \
 		ParameterKey=HostedZoneName,ParameterValue=$(HOSTED_ZONE_NAME) \
 		ParameterKey=Subdomain,ParameterValue=$(MASTER2_SUBDOMAIN) \
 		ParameterKey=SlaveSubdomain,ParameterValue=$(SLAVE_SUBDOMAIN) \
@@ -123,6 +126,7 @@
 		ParameterKey=LDAPAccountBase,ParameterValue=\"$(LDAP_ACCOUNT_BASE)\" \
 		ParameterKey=LDAPGroupBase,ParameterValue=\"$(LDAP_GROUP_BASE)\" \
 		ParameterKey=ClusterStackName,ParameterValue=$(CLUSTER_STACK_NAME) \
+		ParameterKey=TemplateBucketName,ParameterValue=$(TEMPLATE_BUCKET_NAME) \
 		ParameterKey=HostedZoneName,ParameterValue=$(HOSTED_ZONE_NAME) \
 		ParameterKey=Subdomain,ParameterValue=$(SLAVE_SUBDOMAIN) \
 		ParameterKey=DockerRegistryUrl,ParameterValue=$(DOCKER_REGISTRY_URI) \
diff --git a/dual-master/cf-service-master.yml b/dual-master/cf-service-master.yml
index 955989d..f4ecec5 100644
--- a/dual-master/cf-service-master.yml
+++ b/dual-master/cf-service-master.yml
@@ -11,6 +11,9 @@
       Description: Stack name of the ECS cluster to deply the serivces
       Type: String
       Default: gerrit-cluster
+  TemplateBucketName:
+      Description: S3 bucket containing cloudformation templates
+      Type: String
   EnvironmentName:
       Description: An environment name used to build the log stream names
       Type: String
@@ -368,7 +371,7 @@
     ECSTaskExecutionRoleStack:
       Type: AWS::CloudFormation::Stack
       Properties:
-        TemplateURL: https://aws-gerrit-cf-templates.s3.amazonaws.com/cf-gerrit-task-execution-role.yml
+        TemplateURL: !Join [ '', ['https://', !Ref TemplateBucketName, '.s3.amazonaws.com/cf-gerrit-task-execution-role.yml'] ]
         TimeoutInMinutes: '5'
 
 Outputs:
diff --git a/dual-master/cf-service-slave.yml b/dual-master/cf-service-slave.yml
index 18aee8e..02ef28c 100644
--- a/dual-master/cf-service-slave.yml
+++ b/dual-master/cf-service-slave.yml
@@ -14,6 +14,9 @@
       Description: Stack name of the ECS cluster to deply the serivces
       Type: String
       Default: gerrit-cluster
+  TemplateBucketName:
+      Description: S3 bucket containing cloudformation templates
+      Type: String
   EnvironmentName:
       Description: An environment name used to build the log stream names
       Type: String
@@ -416,7 +419,7 @@
     ECSTaskExecutionRoleStack:
       Type: AWS::CloudFormation::Stack
       Properties:
-        TemplateURL: https://aws-gerrit-cf-templates.s3.amazonaws.com/cf-gerrit-task-execution-role.yml
+        TemplateURL: !Join [ '', ['https://', !Ref TemplateBucketName, '.s3.amazonaws.com/cf-gerrit-task-execution-role.yml'] ]
         TimeoutInMinutes: '5'
 
 Outputs:
diff --git a/master-slave/Makefile b/master-slave/Makefile
index efe396d..a49ff92 100644
--- a/master-slave/Makefile
+++ b/master-slave/Makefile
@@ -1,5 +1,6 @@
-include ../Makefile.common
 include setup.env
+include ../common.env
+include ../Makefile.common
 
 CLUSTER_TEMPLATE:=cf-cluster.yml
 SERVICE_MASTER_TEMPLATE:=cf-service-master.yml
@@ -46,6 +47,7 @@
 		ParameterKey=SMTPUser,ParameterValue=$(SMTP_USER) \
 		ParameterKey=SMTPDomain,ParameterValue=$(SMTP_DOMAIN) \
 		ParameterKey=ClusterStackName,ParameterValue=$(CLUSTER_STACK_NAME) \
+		ParameterKey=TemplateBucketName,ParameterValue=$(TEMPLATE_BUCKET_NAME) \
 		ParameterKey=HostedZoneName,ParameterValue=$(HOSTED_ZONE_NAME) \
 		ParameterKey=Subdomain,ParameterValue=$(MASTER_SUBDOMAIN) \
 		ParameterKey=SlaveSubdomain,ParameterValue=$(SLAVE_SUBDOMAIN) \
@@ -71,6 +73,7 @@
 		ParameterKey=LDAPAccountBase,ParameterValue=\"$(LDAP_ACCOUNT_BASE)\" \
 		ParameterKey=LDAPGroupBase,ParameterValue=\"$(LDAP_GROUP_BASE)\" \
 		ParameterKey=ClusterStackName,ParameterValue=$(CLUSTER_STACK_NAME) \
+		ParameterKey=TemplateBucketName,ParameterValue=$(TEMPLATE_BUCKET_NAME) \
 		ParameterKey=HostedZoneName,ParameterValue=$(HOSTED_ZONE_NAME) \
 		ParameterKey=Subdomain,ParameterValue=$(SLAVE_SUBDOMAIN) \
 		ParameterKey=DockerRegistryUrl,ParameterValue=$(DOCKER_REGISTRY_URI) \
diff --git a/master-slave/cf-service-master.yml b/master-slave/cf-service-master.yml
index 85861b9..e07b5a5 100644
--- a/master-slave/cf-service-master.yml
+++ b/master-slave/cf-service-master.yml
@@ -7,6 +7,9 @@
   SlaveServiceStackName:
     Type: String
     Default: gerrit-slave
+  TemplateBucketName:
+    Description: S3 bucket containing cloudformation templates
+    Type: String
   ClusterStackName:
       Description: Stack name of the ECS cluster to deply the serivces
       Type: String
@@ -328,7 +331,7 @@
     ECSTaskExecutionRoleStack:
       Type: AWS::CloudFormation::Stack
       Properties:
-        TemplateURL: https://aws-gerrit-cf-templates.s3.amazonaws.com/cf-gerrit-task-execution-role.yml
+        TemplateURL: !Join [ '', ['https://', !Ref TemplateBucketName, '.s3.amazonaws.com/cf-gerrit-task-execution-role.yml'] ]
         TimeoutInMinutes: '5'
 
 Outputs:
diff --git a/master-slave/cf-service-slave.yml b/master-slave/cf-service-slave.yml
index 18aee8e..f02130d 100644
--- a/master-slave/cf-service-slave.yml
+++ b/master-slave/cf-service-slave.yml
@@ -14,6 +14,9 @@
       Description: Stack name of the ECS cluster to deply the serivces
       Type: String
       Default: gerrit-cluster
+  TemplateBucketName:
+    Description: S3 bucket containing cloudformation templates
+    Type: String
   EnvironmentName:
       Description: An environment name used to build the log stream names
       Type: String
@@ -416,7 +419,7 @@
     ECSTaskExecutionRoleStack:
       Type: AWS::CloudFormation::Stack
       Properties:
-        TemplateURL: https://aws-gerrit-cf-templates.s3.amazonaws.com/cf-gerrit-task-execution-role.yml
+        TemplateURL: !Join [ '', ['https://', !Ref TemplateBucketName, '.s3.amazonaws.com/cf-gerrit-task-execution-role.yml'] ]
         TimeoutInMinutes: '5'
 
 Outputs:
diff --git a/single-master/Makefile b/single-master/Makefile
index 62a7436..a77b898 100644
--- a/single-master/Makefile
+++ b/single-master/Makefile
@@ -1,4 +1,5 @@
 include setup.env
+include ../common.env
 include ../Makefile.common
 
 CLUSTER_TEMPLATE:=cf-cluster.yml
@@ -42,6 +43,7 @@
 		ParameterKey=SMTPUser,ParameterValue=$(SMTP_USER) \
 		ParameterKey=SMTPDomain,ParameterValue=$(SMTP_DOMAIN) \
 		ParameterKey=ClusterStackName,ParameterValue=$(CLUSTER_STACK_NAME) \
+		ParameterKey=TemplateBucketName,ParameterValue=$(TEMPLATE_BUCKET_NAME) \
 		ParameterKey=HostedZoneName,ParameterValue=$(HOSTED_ZONE_NAME) \
 		ParameterKey=Subdomain,ParameterValue=$(SUBDOMAIN) \
 		ParameterKey=DockerRegistryUrl,ParameterValue=$(DOCKER_REGISTRY_URI) \
diff --git a/single-master/cf-service.yml b/single-master/cf-service.yml
index d6f2681..d08ef0e 100644
--- a/single-master/cf-service.yml
+++ b/single-master/cf-service.yml
@@ -8,6 +8,9 @@
       Description: Stack name of the ECS cluster to deply the serivces
       Type: String
       Default: gerrit-cluster
+  TemplateBucketName:
+      Description: S3 bucket containing cloudformation templates
+      Type: String
   EnvironmentName:
       Description: An environment name that will be prefixed to resource names
       Type: String