It took me 3.5 hours to figure out the hard way that JQ supports variables in a simple but peculiar way.
I hope it really helps somebody else.
How to do it
Here’s what the data set looks like, btw:
Now, remember, bash doesn’t expand variables inside single quotes:
Hurray but still not enough, yet, because we still have to somehow jam it between two single quotes like jq likes.
Let’s see if it runs, I guess?
I mean, I’ll try it? Hold my beer
wheeeeeeee
Well, dear reader, listen close: I was definitely overthinking things. Here’s how you do it:
Easy peasy. Right? Uggh.
Why would you do that?
The most immediate application that comes to mind is if you’re looping through a list of users and want to get the IAM credentials for all of them (since that’s what I was trying to do when I went down this rabbit hole). But I imagine this will be helpful for running a jq query against any list of strings - for x in y, etc.
Caveats
The code above doesn’t grab ALL of the credentials - only the IAM creds assigned at the GCP project level. As of right now, the gcloud SDK doesn’t pull in creds inherited from folders, which is a drag. But this gist isn’t about that. Anyway, just a heads up.