title: Using Conditions and Parameters in CloudFormation
body: <p>I am trying to create a condition based on an optional parameter. The option is whether to run some additional installation from my userData script for an EC2 deployment.   </p>
  
  <p>The parameters and conditions look like this:</p>
  
  <pre><code>Parameters: 
    EnvType: 
      Description: Option to install New Relic Infrastructure.
      Default: apm
      Type: String
    AllowedValues: 
      - apm
      - +infra
  </code></pre>
  
  <p>Then my EC2 Resource with conditional startup scripts</p>
  
  <pre><code>Resources:
    Ec2Instance:
      Type: AWS::EC2::Instance
      Properties:
       InstanceType: t2.micro
       ImageId: ami-9c9443e3  #Amazon Linux AMI in Tokyo
       KeyName: tokyocloudformation
       IamInstanceProfile: 'S3EC2'
       SecurityGroupIds:
           - !Ref myNewSecurityGroup   
       UserData:
          Condition: apmOnly
          Fn::Base64:
            |
              #!/bin/bash
              installstuff
        Condition: addInfrastructureAgent
          Fn::Base64:
            |
             #!/bin/bash
             installstuff
             installsomeotherstuff
  </code></pre>
  
  <p>The error message I'm getting is:
  Template validation error: Template format error: Unresolved dependencies [EnvTyp]. Cannot reference resources in the Conditions block of the template</p>
  
  <p>I get what the error is saying I believe, but it doesn't seem to fit with the examples given by AWS.  </p>
  
  <p><a href="https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/conditions-section-structure.html" rel="nofollow noreferrer">https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/conditions-section-structure.html</a> . 
  This AWS example clearly uses a !Ref in the Conditions block.  </p>
  
  <pre><code>  EnvType: 
      Description: Environment type.
      Default: test
      Type: String
      AllowedValues: 
        - prod
        - test
      ConstraintDescription: must specify prod or test.
    Conditions: 
      CreateProdResources: !Equals [ !Ref EnvType, prod ]
  </code></pre>
  
  <p>Can someone provide some feedback on how to implement this conditional or why this error message is being thrown for this implementation?</p>