title: AWS Cloudformation: Conditionally create properties of resources
body: <p>I know that it is possible via the use of <a href="https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/conditions-section-structure.html" rel="noreferrer">Conditions</a> to conditionally (what else?) create resources.</p>
  
  <p>I am trying to find a way though to conditionally create properties of resources; </p>
  
  <p>in my case I am creating several <code>EC2</code> instances in a subnet with default public ip assignment = <code>false</code>. </p>
  
  <p>Sometimes though for debugging purposes I want my instances to get public IPs. </p>
  
  <p>Now I have to comment in/out the SG/Subnet and the <code>NetworkInterfaces</code> properties below (those do not go together)</p>
  
  <pre><code>  myEC2:
      Type: AWS::EC2::Instance
      Metadata:
        Comment: My EC2 Instance
        AWS::CloudFormation::Init:
          config:
            commands:
              01_provision:
                command:
                  !Sub |
                    sed -i "s/somestring/${somevar}/" /some/path/
      CreationPolicy:
        ResourceSignal:
          Timeout: PT4M
      Properties:
        ImageId: !FindInMap [ MyAamiMap, 'myami', amiid ]
        InstanceType: "t2.2xlarge"
        # SubnetId: !Ref SBNDemo1
        # SecurityGroupIds: [!Ref SGInternalDemo]
        NetworkInterfaces:
          - AssociatePublicIpAddress: "true"
            DeviceIndex: "0"
            GroupSet:
              - Ref: "SGInternalDemo"
            SubnetId:
              Ref: "SBNDemo1"
        UserData:
          "Fn::Base64":
            !Sub |
              #!/bin/bash -xe
              # Start cfn-init
              /usr/local/bin/cfn-init -s ${AWS::StackId} -r myEC2 --region ${AWS::Region} || echo 'Failed to run cfn-init'
              # All done so signal success
              /usr/local/bin/cfn-signal -e $? --stack ${AWS::StackId} --resource myEC2 --region ${AWS::Region}
  </code></pre>
  
  <p>Any suggestions?</p>