How do I programmatically select a datasource based on a query value?

I have a query variable that allows the user to select which environment’s data to view. Specifcally:

Variable name: environment
Possible values: dev, int or prod

Based on the users selection my variable will end up containing one of the 3 environments specified above.

Now, what I’d like to do is select a specific ElasticSearch database based on one of these environments. The reality is that I have two data sources. One is for the dev/int environments and the other is for the prod environments.

So if a user selects “dev” or “int” I want to point to the dev datasource and if they select “prod” I want to select the prod datasource.

How can I do this? There must be a way.

I use lookup feature of https://yesoreyeram.github.io/grafana-infinity-datasource/wiki/template-variables.html#legacy-mode-variable

Give a try. Though it is not ideal way of doing, it just works.

Thanks! I haven’t gotten a chance to look at this yet. I will over the weekend.

Why is this not an ideal way of doing it? Is there a better way of doing what I’m trying to do?