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 iam-roles.dev.yml file looks like this:

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

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.

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

If I take the contents of the iam-roles.dev.yml 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.