title: EC2 cloudformation template using conditions to add ebs volume
body: <p>I am trying to add EBS Volume to my EC2 resource based on a condition of EBS volume required or not. How can I make the condition work?
  Here is the snippet of code:</p>
  
  <pre><code>Conditions:
    EbsVolumeTrue: !Equals [!Ref EBS, true]
  Resources:
    Instance:
      Type: AWS::EC2::Instance
      Properties:
        ImageId: ami-xxxxxx
        !If [EbsVolumeTrue, !Ref BlockDeviceMappings, !Ref "AWS::NoValue"]
        BlockDeviceMappings: 
         - DeviceName: !Ref VolumeName
           Ebs: 
             VolumeType: !Ref VolumeType
             DeleteOnTermination: false
             VolumeSize: !Ref VolumeSize
  </code></pre>