Stop creating useless network stacks for primary-replica

When network resources are NOT provided via the setup.env file then a
new VPC is created with its related components, such as subnets and IGW.

However, when network resources ARE provided externally via the
setup.env file, then the network stack doesn't do much except returning
the provided input values as output, for other stacks to consume.

This causes the creation of an empty stack, with no resources created,
but just outputs.

Prevent the creation of empty network stacks by checking the existence
of VPC related input parameters and skip the creation of the stack, when
they are defined.

Change-Id: I7e360875036b46bce3816ddefa658466669f5fc0
diff --git a/primary-replica/cf-cluster.yml b/primary-replica/cf-cluster.yml
index c9cd2a7..cbd7279 100644
--- a/primary-replica/cf-cluster.yml
+++ b/primary-replica/cf-cluster.yml
@@ -72,6 +72,13 @@
     Type: Number
     Default: 10
 
+Conditions:
+  NetworkStackNeeded: !Or
+    - !Equals [!Ref VPCIdProp, ""]
+    - !And
+      - !Equals [!Ref InternetGatewayIdProp, ""]
+      - !Equals [!Ref SubnetIdProp, ""]
+
 Resources:
   # ECS Resources
   ECSCluster:
@@ -81,7 +88,7 @@
     Type: AWS::EC2::SecurityGroup
     Properties:
       GroupDescription: Access to the ECS hosts that run containers
-      VpcId: !GetAtt ECSTaskNetworkStack.Outputs.VPCRef
+      VpcId: !If [NetworkStackNeeded, !GetAtt ECSTaskNetworkStack.Outputs.VPCRef, !Ref VPCIdProp]
       SecurityGroupIngress:
           # Allow access to NLB from anywhere on the internet
           - CidrIp: 0.0.0.0/0
@@ -97,7 +104,7 @@
     Type: AWS::AutoScaling::AutoScalingGroup
     Properties:
       VPCZoneIdentifier:
-        - !GetAtt ECSTaskNetworkStack.Outputs.PublicSubnetOneRef
+        - !If [NetworkStackNeeded, !GetAtt ECSTaskNetworkStack.Outputs.PublicSubnetOneRef, !Ref SubnetIdProp]
       LaunchConfigurationName: !Ref 'PrimaryLaunchConfiguration'
       MinSize: '1'
       MaxSize: !Ref PrimaryMaxCount
@@ -215,7 +222,7 @@
     Type: AWS::AutoScaling::AutoScalingGroup
     Properties:
       VPCZoneIdentifier:
-        - !GetAtt ECSTaskNetworkStack.Outputs.PublicSubnetOneRef
+        - !If [NetworkStackNeeded, !GetAtt ECSTaskNetworkStack.Outputs.PublicSubnetOneRef, !Ref SubnetIdProp]
       LaunchConfigurationName: !Ref 'ReplicaLaunchConfiguration'
       MinSize: '1'
       MaxSize: '1'
@@ -330,6 +337,7 @@
             Resource: '*'
   ECSTaskNetworkStack:
     Type: AWS::CloudFormation::Stack
+    Condition: NetworkStackNeeded
     Properties:
       TemplateURL: !Join [ '', ['https://', !Ref TemplateBucketName, '.s3.amazonaws.com/cf-gerrit-network-stack.yml'] ]
       TimeoutInMinutes: '25'
@@ -358,12 +366,12 @@
       Name: !Join [ ':', [ !Ref 'AWS::StackName', 'ClusterName' ] ]
   VPCId:
     Description: The ID of the VPC that this stack is deployed in
-    Value: !GetAtt ECSTaskNetworkStack.Outputs.VPCRef
+    Value: !If [NetworkStackNeeded, !GetAtt ECSTaskNetworkStack.Outputs.VPCRef, !Ref VPCIdProp]
     Export:
       Name: !Join [ ':', [ !Ref 'AWS::StackName', 'VPCId' ] ]
   PublicSubnetOne:
     Description: Public subnet one
-    Value: !GetAtt ECSTaskNetworkStack.Outputs.PublicSubnetOneRef
+    Value: !If [NetworkStackNeeded, !GetAtt ECSTaskNetworkStack.Outputs.PublicSubnetOneRef, !Ref SubnetIdProp]
     Export:
       Name: !Join [ ':', [ !Ref 'AWS::StackName', 'PublicSubnetOne' ] ]
   ClusterArn: