Environment variable interpolation does not work with @_here_

48 Views Asked by At

I'm setting up hydra config for my python project and struggling a bit to get variable interpolation working in the following context.

Directory structure

├── config/
│   ├── config.yaml
│   ├── deployment.yaml
│   │   ├── objects.yaml
│   └── environment
│       ├── dev.yaml
│       └── prd.yaml

My config.yaml looks like this:

# config.yaml

defaults:
  - _self_
  - deployment: objects

I want to set up my objects.yaml such that it inherits config from the environment group.

THIS WORKS

# objects.yaml

defaults:
  - _self_
  - /environment/dev@_here_

file: my-file 

THIS DOES NOT WORK

When I try and get dev from an env variable, it does not work.

defaults:
  - _self_
  - /environment/${oc.env:CLUSTER_TARGET}@_here_

file: my-file 

This is the error I get

In 'deployment/objects': Could not load 'deployment/environment/dev'.

1

There are 1 best solutions below

0
Omry Yadan On BEST ANSWER

The interpolation implementation in the defaults list is a specialized implementation that behaves differently than the normal implementation.

In particular, it does not support any resolvers.

You will have to find another way to achieve your goal. One possibility is an external shell script that will forward the environment variable as an override, e.g:

python foo.py environment=$CLUSTER_TARGET

You can learn more about interpolation in the defaults list here. Although this specific restriction is not mentioned unfortunately.