Bundle creation and deletion of the stacks in Makefile

Make spin up and tear down of the stack easier

Feature: Issue 12445

Change-Id: I585dfb0db46b17f35a44b834e1d9f3f084e1c6be
diff --git a/single-master/Makefile b/single-master/Makefile
new file mode 100644
index 0000000..ea8d814
--- /dev/null
+++ b/single-master/Makefile
@@ -0,0 +1,66 @@
+CLUSTER_STACK_NAME:=gerrit-cluster
+CLUSTER_TEMPLATE:=cf-cluster.yml
+SERVICE_TEMPLATE:=cf-service.yml
+SERVICE_STACK_NAME:=gerrit-service
+AWS_REGION:=us-east-2
+AWS_FC_COMMAND=export AWS_PAGER=;aws cloudformation
+
+.PHONY: create-all delete-all cluster service wait-for-cluster-creation wait-for-service-creation wait-for-cluster-deletion wait-for-service-deletion
+
+create-all: cluster wait-for-cluster-creation service wait-for-service-creation
+
+cluster:
+	$(AWS_FC_COMMAND) create-stack \
+		--stack-name $(CLUSTER_STACK_NAME) \
+		--capabilities CAPABILITY_IAM  \
+		--template-body file://`pwd`/$(CLUSTER_TEMPLATE) \
+		--region $(AWS_REGION)
+
+service:
+	$(AWS_FC_COMMAND) create-stack \
+		--stack-name $(SERVICE_STACK_NAME) \
+		--capabilities CAPABILITY_IAM  \
+		--template-body file://`pwd`/$(SERVICE_TEMPLATE) \
+		--region $(AWS_REGION) \
+		--parameters ParameterKey=ClusterStackName,ParameterValue=$(CLUSTER_STACK_NAME)
+
+
+wait-for-cluster-creation:
+	@echo "*** Wait for cluster stack '$(CLUSTER_STACK_NAME)' creation"
+	$(AWS_FC_COMMAND) wait stack-create-complete \
+	--stack-name $(CLUSTER_STACK_NAME) \
+	--region $(AWS_REGION)
+	@echo "*** Cluster stack '$(CLUSTER_STACK_NAME)' created"
+
+wait-for-service-creation:
+	@echo "*** Wait for service stack '$(SERVICE_STACK_NAME)' creation"
+	$(AWS_FC_COMMAND) wait stack-create-complete \
+	--stack-name $(SERVICE_STACK_NAME) \
+	--region $(AWS_REGION)
+	@echo "*** Service stack '$(SERVICE_STACK_NAME)' created"
+
+wait-for-cluster-deletion:
+	@echo "*** Wait for cluster stack '$(CLUSTER_STACK_NAME)' deletion"
+	$(AWS_FC_COMMAND) wait stack-delete-complete \
+	--stack-name $(CLUSTER_STACK_NAME) \
+	--region $(AWS_REGION)
+	@echo "*** Cluster stack '$(CLUSTER_STACK_NAME)' deleted"
+
+wait-for-service-deletion:
+	@echo "*** Wait for service stack '$(SERVICE_STACK_NAME)' deletion"
+	$(AWS_FC_COMMAND) wait stack-delete-complete \
+	--stack-name $(SERVICE_STACK_NAME) \
+	--region $(AWS_REGION)
+	@echo "*** Service stack '$(SERVICE_STACK_NAME)' deleted"
+
+delete-cluster:
+	$(AWS_FC_COMMAND) delete-stack \
+	--stack-name $(CLUSTER_STACK_NAME) \
+	--region $(AWS_REGION)
+
+delete-service:
+	$(AWS_FC_COMMAND) delete-stack \
+	--stack-name $(SERVICE_STACK_NAME) \
+	--region $(AWS_REGION)
+
+delete-all: delete-service wait-for-service-deletion delete-cluster wait-for-cluster-deletion
diff --git a/single-master/README.md b/single-master/README.md
index 2e187c6..f3745d7 100644
--- a/single-master/README.md
+++ b/single-master/README.md
@@ -49,34 +49,26 @@
 for troubleshooting purposes. Store them in a `pem` file to use when ssh-ing into your
 instances as follow: `ssh -i yourKeyPairs.pem <ec2_instance_ip>`*
 
-* Create the cluster stack:
+* Create the cluster and service stack:
 
 ```
-aws cloudformation create-stack \
-  --stack-name gerrit-cluster \
-  --capabilities CAPABILITY_IAM  \
-  --template-body file://<full_path_to_the_template>/aws-gerrit/single-master/cf-cluster.yml
+make create-all
 ```
 
-* Create the service stack:
+By default the cluster and service name are called, respectively, `cluster-stack`
+and `service-stack`. If you want to change the name you can do it by overriding
+the *Makefile* parameters:
 
 ```
-aws cloudformation create-stack \
-  --stack-name gerrit-service \
-  --capabilities CAPABILITY_NAMED_IAM \
-  --template-body file://<full_path_to_the_template>/aws-gerrit/single-master/cf-service.yml \
-  --parameters ParameterKey=ClusterStackName,ParameterValue=gerrit-cluster
+make create-all CLUSTER_STACK_NAME=my-cluster-stack SERVICE_STACK_NAME=my-service-stack
 ```
 
-*NOTE*: the `ClusterStackName` value has to be name of the cluster stack created
-in the previous step (i.e.: `gerrit-cluster` in this case)
+Keep in mind you will have to pass the same parameters when deleting the stacks.
 
 ### Cleaning up
 
 ```
-aws cloudformation delete-stack --stack-name gerrit-cluster
-### Wait for the "gerrit-cluster" stack to be deleted
-aws cloudformation delete-stack --stack-name gerrit-service
+make delete-all
 ```
 
 ### Access your Gerrit