How to make a variable dependent on another or change datasource based on variable choice

Datasource: CloudWatch
Version: 5.4.2

I have an issue where i have to display a dashboard for a certain group of AWS ec2 instances.
I get the list of instances using a variable that gets populated from a tag on the instances.

ec2_instance_attribute($region, Tags.Name, {“tag:TagKey”: [“Some Tag Value”]})

I want to reuse the same dashboard to allow users to show different groups of instances.
I need to change the tag value in the variable based on a dropdown, which is OK, but the instances are in different AWS accounts which then requires the users to switch Grafana datasources by changing a second dropdown. This also reuires the users to know which group is in which account (which they do not).
This also presents an issue because you can only change one dropdown at a time and as soon as you change one, the list of instances becomes empty and the graphs display errors, until you pick the correct datasource.

Is there any way to make dropdown variable choices dependent on one another?
Or make dropdown choices have a DisplayName/Value instead of just a value?

1 Like

you can use Datasource type variables.

Thanks for the suggestion Daniel, but how can you make the Datasource variable change when another variable changes? That is what I’m trying to do.

Is it usefull for you?

Another option is a query that can create a key/value variable. The query should return two columns that are named __text and __value . The __text column value should be unique (if it is not unique then the first value is used). The options in the dropdown will have a text and value that allows you to have a friendly name as text and an id as the value. An example query with hostname as the text and id as the value:

    SELECT hostname AS __text, id AS __value FROM my_host

Thanks for the suggestion I’ll give it a try.