Skip to content
This repository was archived by the owner on Feb 14, 2023. It is now read-only.
This repository was archived by the owner on Feb 14, 2023. It is now read-only.

Dynamic list of imported resources #11

@ignacioalles

Description

@ignacioalles

Is there a way to dinamically provide the list of resources to include depending on some other value (eg: provider.region) ?

I've tried several approaches but none of them worked.

  1. Use a variable in path
custom:
  import:
    - resources/resource.${self:provider.region}.yml

cannot find the file. I think is trying to import it before variable value expansion.

Cannot import resources/resource.${self:provider.region}.yml: the given file doesn't exist
  1. Relying on serverless variable expansion (it works well with other config elements)
custom:
  import: ${file(resources/resource.${self:provider.region}.yml):import}

cannot find the file either. I think it is the same reason.

Cannot import ${file(resources/resource.${self:provider.region}.yml):import}: the given module cannot be resolved
  Tried: 
   - ${file(resources/resource.${self:provider.region}.yml):import}/serverless.yml
   - ${file(resources/resource.${self:provider.region}.yml):import}/serverless.yaml
   - ${file(resources/resource.${self:provider.region}.yml):import}/serverless.js
  1. Finally I've tried using .js import (despite having to workaround .js modules not found #10)
custom:
  import: 
    - module: resources.js
      inputs:
        region: ${self:provider.region}

and resources.js being:

module.exports = ({region}) => {
    return {
        custom: {
            import: [
                `resources/resource.${region}.yml`
            ]
        }
    }
}

with the same result:

 Cause: Cannot import resources/resource.${self:provider.region}.yml: the given file doesn't exist

Does anyone know how to workaround this issue?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions