graphql-engine: [CLI] Custom environment variables don't work in metadata files

I have a remote_schemas.yaml file:

- name: api
  definition:
    url: "{{ API_GRAPHQL_ENDPOINT }}"
    timeout_seconds: 60

based on the docs here: https://hasura.io/blog/moving-from-local-development-staging-production-with-hasura/. I have the `` environment variable set, but the hasura CLI is still not happy:

❯ API_GRAPHQL_ENDPOINT=https://7asdf8.ngrok.io/graphql hasura metadata apply --admin-secret $HASURA_GRAPHQL_ADMIN_SECRET
FATA[0005] failed to apply metadata: cannot apply metadata on the database: [parse-failed] not a valid URI ($[1].remote_schemas[0].definition.url) 

And dropping the quotes

    url: {{ API_GRAPHQL_ENDPOINT }}

doesn’t work either:

❯ API_GRAPHQL_ENDPOINT=https://7asdf8.ngrok.io/graphql hasura metadata apply --admin-secret $HASURA_GRAPHQL_ADMIN_SECRET
FATA[0004] failed to apply metadata: cannot apply metadata on the database: yaml: invalid map key: map[interface {}]interface {}{"API_GRAPHQL_ENDPOINT":interface {}(nil)} 

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Comments: 18 (8 by maintainers)

Most upvoted comments

This is a very important feature for us as well. Any ETA for enabling it?

To elaborate on @John0x’ comment—we keep prod/dev/test migrations separate from the infrastructure that sets up Hasura on AWS Fargate. We also have separate remote schema URLs for prod/dev/test. We need to be able to set those URLs in the metadata without redeploying/modifying the infrastructure repository. The ideal way would be to run hasura metadata apply from the migration repository with the URLs set as environment variables on the machine running the hasura cli. Any thoughts on how we could achieve this?

Edit: For now, we use cat metadata/remote_schemas.yaml | envsubst '$PREVIEW_GRAPHQL_ENDPOINT' | tee temp.yaml && mv temp.yaml metadata/remote_schemas.yaml before runnning hasura metadata apply

Should be

- name: api
  definition:
    url_from_env: API_GRAPHQL_ENDPOINT

I’ve run into this issue - is there a solution?

In the databases.yaml file I need to have a dynamic url so would like to use the following:

database_url:
    from_env: HASURA_GRAPHQL_DATABASE_URL

But I get the following error Inconsistent object: environment variable 'HASURA_GRAPHQL_DATABASE_URL' not set. It’s unclear how this should be set.

For remote schemas, the metadata doesn’t support `{{ }}`` style env templating yet. Pls see this issue for that feature: #2483

For that the env var has to exist on the server (where hasura is running). Is there a way to only have it defined for the cli (using .env file for example) and then be replaced during the metadata apply? Like templating?