title: CloudFormation nested Sub with FindInMap
body: <p>What I'm trying to achieve is resolving variables stored as string in <strong>Mappings</strong>.</p>
  
  <pre><code>Mappings:
    Constants: 
      UserDataTest:
        Test: "echo ${NestedVariable}\n"
  </code></pre>
  
  <p>I would like to have it resolved in <strong>UserData</strong>.</p>
  
  <pre><code>  UserData: !Base64
      Fn::Join:
        - ''
        - - "#!/bin/bash\n"
          - Fn::Sub: 
            - !FindInMap [Constants, UserDataTest, Test]
            - NestedVariable: xyz
  </code></pre>
  
  <p>Above example wont work as first argument in <strong>Fn::Sub</strong> is expected to be String.</p>
  
  <blockquote>
    <p>An error occurred (ValidationError) when calling the CreateStack
    operation: Template error: One or more Fn::Sub intrinsic functions
    don't specify expected arguments. Specify a string as first argument,
    and an optional second argument to specify a mapping of values to
    replace in the string</p>
  </blockquote>
  
  <hr>
  
  <p>Tried something like this, but it still won't resolve nested variable:</p>
  
  <pre><code> - Fn::Sub: 
     - ${TestValue}
     - { NestedVariable: xyz, TestValue: !FindInMap [Constants, UserDataTest, Test] }
  </code></pre>
  
  <p>Result of this will be:</p>
  
  <blockquote>
    <p>echo ${NestedVariable}</p>
  </blockquote>
  
  <hr>
  
  <p>Also it seemed reasonable to try this way:</p>
  
  <pre><code>- Fn::Sub: 
    - Fn::Sub: 
      - ${TestValue}
      - TestValue: !FindInMap [Constants, UserDataTest, Test]
    - NestedVariable: xyz
  </code></pre>
  
  <p>As a result I get the same error as in first example.</p>
  
  <hr>
  
  <p>Any help would be greatly appreciated!</p>