digitickets / terraform-aws-cli

Run the AWS CLI, with the ability to run under an assumed role, to access resources and properties missing from the Terraform AWS Provider.
28 stars 11 forks source link

`jq` dependency can be removed by using `--query` #5

Closed nitrocode closed 1 year ago

nitrocode commented 2 years ago

Nice module! It's very useful.

I believe the jq dependency could be removed by using the --query argument and jmespath. That way only the awscli would be needed to use this module.

rquadling commented 2 years ago

That is true. When I created this module, I think I was having difficulty with using --query and just avoided the issue.

If you look at the example in the README.md, would that translate without any extra work? If so, this is (I think), a relative simple upgrade. Just as long as all that you can do in jq can be done in --query. I think that's what I was mainly having an issue with.

rquadling commented 2 years ago

And if I'd bothered to remember how I wrote the code ...

jq is required as the data being passed from Terraform to the shell script (that will run the AWS CLI app) via Terraform's external data provider presents the data as a JSON object. Whilst I could decode that manually within the shell script that, that's the sort of thing that can easily be messed up.

I could also pass the required values as parameters to the shell script, but again, escaping and quoting and guaranteeing you've covered all the possible edge cases ... another thing to have to get right and deal with when it goes wrong.

So, with Terraform JSON encoding doing all the work to get all the data nicely to the shell script, and jq doing all the heavy lifting in getting the data out of the supplied JSON and into usable parameters within the shell script, I'm not tempted to change that at the moment.

But if you are able to make a PR that covers all of this, then I would certainly be interested.

rquadling commented 1 year ago

It would be nice to drop the use of jq, but there's currently a requirement for processing data from TF into the command line for aws.