title: Cloudformation nested stack template ValidationError for child-to-child parameter
body: <p>I've made a nested cloudformation parent template that then references 4 child templates. When I try to launch the stack via the CLI command <code>aws cloudformation create-stack...</code> I get the error: </p>
  
  <pre><code>An error occurred (ValidationError) when calling the CreateStack 
  operation: Template error: instance of Fn::GetAtt references undefined 
  resource BatchScatterGatherSubmissionActivity
  </code></pre>
  
  <p>This is because I have a child template called <strong>StepFunctionResourcesStack</strong> that contains the <code>BatchScatterGatherSubmissionActivity</code> and then another child template <strong>EC2InstanceResourcesStack</strong> that references it. I made sure to add a <code>DependsOn</code> clause for the latter child template, but I still get the error. </p>
  
  <p>Here is the <strong>StepFunctionResourcesStack</strong>:</p>
  
  <hr>
  
  <pre><code>AWSTemplateFormatVersion: '2010-09-09'
  Description: step functions resources stack.
  Parameters:
    StackUID:
      Type: String 
  
  Resources:
    StatesExecutionRole:
      Type: "AWS::IAM::Role"
      Properties:
        AssumeRolePolicyDocument:
          Version: "2012-10-17"
          Statement:
            - Effect: "Allow"
              Principal:
                Service:
                  - !Sub states.${AWS::Region}.amazonaws.com
              Action: "sts:AssumeRole"
        Path: "/"
        Policies:
          - PolicyName: StatesExecutionPolicy
            PolicyDocument:
              Version: "2012-10-17"
              Statement:
                - Effect: Allow
                  Action:
                    - "lambda:InvokeFunction"
                  Resource: "*"
  
    MyStateMachine:
      Type: "AWS::StepFunctions::StateMachine"
      Properties:
        #
        # The StateMachine definition is substituted in with Jinja2
        #
        DefinitionString: !Sub
          - |
            {{ machine_json | indent(10) }}
          - {% for item in machine_args -%}
            {{ item }}
            {% endfor %}
  
        RoleArn: !GetAtt [ StatesExecutionRole, Arn ]
  
    # several of these:
  
    BatchScatterGatherSubmissionActivity:
      Type: "AWS::StepFunctions::Activity"
      Properties:
        Name:
          Fn::Join: [ "-", [ "BatchScatterGatherSubmissionActivity", Ref: StackUID] ]
  
    BatchScatterGatherPollingActivity:
      Type: "AWS::StepFunctions::Activity"
      Properties:
        Name:
          Fn::Join: [ "-", [ "BatchScatterGatherPollingActivity", Ref: StackUID] ]
  
    BatchGatherActivity:
      Type: "AWS::StepFunctions::Activity"
      Properties:
        Name:
          Fn::Join: [ "-", [ "BatchGatherActivity", Ref: StackUID] ]
  
    BatchTriodenovoActivity:
      Type: "AWS::StepFunctions::Activity"
      Properties:
        Name:
          Fn::Join: [ "-", [ "BatchTriodenovoActivity", Ref: StackUID] ]
  
    BatchHandoffActivity:
      Type: "AWS::StepFunctions::Activity"
      Properties:
        Name:
          Fn::Join: [ "-", [ "BatchHandoffActivity", Ref: StackUID] ]    
  
  Outputs:
    # These get used in the instance_resources child stack.
    BatchScatterGatherSubmissionActivity:
      Value: !Ref BatchScatterGatherSubmissionActivity
    BatchScatterGatherPollingActivity:
      Value: !Ref BatchScatterGatherPollingActivity
    BatchGatherActivity:
      Value: !Ref BatchGatherActivity
    BatchTriodenovoActivity:
      Value: !Ref BatchTriodenovoActivity
    BatchHandoffActivity:
      Value: !Ref BatchHandoffActivity
  </code></pre>
  
  <p>And here is the relevant part of the <strong>parent (nested) template</strong> where the above outputs are passed into the EC2InstanceResourcesStack:</p>
  
  <pre><code>  StepFunctionResourcesStack:
      Type: AWS::CloudFormation::Stack
      Properties:
        Parameters:
          StackUID:
            Ref: StackUID
        TemplateURL: https://s3.amazonaws.com/CFNTemplate/step_functions_resources.stack.yaml
        Timeout: "100"  
  
  
    EC2InstanceResourcesStack:
      Type: AWS::CloudFormation::Stack
      Properties:
        Parameters:
          BatchScatterGatherSubmissionActivity: 
            Fn::GetAtt: [ "BatchScatterGatherSubmissionActivity", "Outputs.StepFunctionResourcesStack" ]
          BatchScatterGatherPollingActivity: 
            Fn::GetAtt: [ "BatchScatterGatherPollingActivity", "Outputs.StepFunctionResourcesStack" ]
          BatchGatherActivity: 
            Fn::GetAtt: [ "BatchGatherActivity", "Outputs.StepFunctionResourcesStack" ]
          BatchTriodenovoActivity: 
            Fn::GetAtt: [ "BatchTriodenovoActivity", "Outputs.StepFunctionResourcesStack" ]
          BatchHandoffActivity: 
            Fn::GetAtt: [ "BatchHandoffActivity", "Outputs.StepFunctionResourcesStack" ]
          Subnet: !Ref Subnet
          GPCESSHKeyPair: !Ref GPCESSHKeyPair
          GPCESubnetAZ1: !Ref GPCESubnetAZ1
          ActivityAndHandoffAnsibleBucketName: !Ref ActivityAndHandoffAnsibleBucketName
          ActivityAndHandoffAnsibleKeyName: !Ref ActivityAndHandoffAnsibleKeyName
          ActivityAndHandoffDaemonBucketName: !Ref ActivityAndHandoffDaemonBucketName
          ActivityAndHandoffDaemonKeyName: !Ref ActivityAndHandoffDaemonKeyName
          ActivityAndHandoffDaemonRequirementsBucketName: !Ref ActivityAndHandoffDaemonRequirementsBucketName
          ActivityAndHandoffDaemonRequirementsKeyName: !Ref ActivityAndHandoffDaemonRequirementsKeyName
          Rkstr8PkgBucketName: !Ref Rkstr8PkgBucketName
          Rkstr8PkgKeyName: !Ref Rkstr8PkgKeyName
        TemplateURL: https://s3.amazonaws.com/CFNTemplate/instance_resources.stack.yaml
        Timeout: "100"
      DependsOn: StepFunctionResourcesStack
  </code></pre>
  
  <p>For my method of exporting the parameters from the child and passing them to another via the parent template, I followed the approach provided in the answer here: <a href="https://stackoverflow.com/questions/43392955/aws-cloudformation-passing-values-between-nested-stacks">AWS CloudFormation: Passing Values between Nested Stacks</a></p>