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

Dynamic list of imported resources #11

Open
ignacioalles opened this issue Nov 16, 2020 · 0 comments
Open

Dynamic list of imported resources #11

ignacioalles opened this issue Nov 16, 2020 · 0 comments

Comments

@ignacioalles
Copy link

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?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant