Bad indentation of a mapping entry

I’m trying to include my lambda roles in a separate file so I can have dev and prod versions.

My file looks like this:

  Type: AWS::IAM::Role
    PermissionsBoundary: arn:aws:iam::xxxxx:policy/csr-Developer-Permissions-Boundary
    Path: /my/default/path/
    RoleName: MyRole-${self:service}

When I include it in my resources->Resources area in my serverless.yml file … I get:
bad indentation of a mapping entry:

 22 |   Resources:
 23 |     ${file(../iam-roles.${opt:stage, 'dev'}.yml)}
 24 |
 25 |     ingestGraveyard:

I have tried every permutation of adding/removing spaces I can think of. When I comment out the file inclusion, I get no errors.

  ${file(../iam-roles.${opt:stage, 'dev'}.yml)}
      Type: "AWS::SQS::Queue"
        QueueName: ${file(../evn.${opt:stage, 'dev'}.json):INGEST_GRAVEYARD_NAME}
      Type: "AWS::SQS::Queue"
        QueueName: ${file(../evn.${opt:stage, 'dev'}.json):INGEST_DLQ_NAME}
          deadLetterTargetArn: !GetAtt ingestGraveyard.Arn
          maxReceiveCount: 2

If I take the contents of the file and simply include them directly in my serverless.yml file… I have no issues at all.

Every attempt I’ve seen to split resource definitions like this fails. There are many posts in the forum around different permutations of the problem. It seems like the only use of the file function is for handling properties like you have already done for the queue name.

I would try to refactor the iam-roles file into the serverless.yml file and use variables like you did with the queue name to control the properties of the role.