infrablocks / ruby_terraform

A simple Ruby wrapper for invoking terraform commands.
MIT License
109 stars 33 forks source link

Implementing terraform test #150

Open tijnster opened 1 year ago

tijnster commented 1 year ago

Hi!

I would like to test my terraform with terraform test, and I would like to execute that command from a function. There is no test function available yet in the current version. Would you be open to this? I think terraform test has officially left the beta stage as of terraform version 1.6. If you're open to this change, I can make a PR for it :).

tobyclemson commented 1 year ago

Hi @tijnster,

Yes, we're very open to a PR for this.

As I understand it, you are looking to define your tests using terraform's new built-in testing framework but executing those tests from within Ruby, in which case, adding support for the test command is definitely the way to go. However, for an alternative approach, we've also built rspec-terraform which works in a similar way to terraforms testing framework but allows all tests to be written in Ruby vis rspec. Examples of how to use rspec-terraform are available in any of the terraform modules hosted here on the infrablocks organisation if you are interested.

Regardless, I'm very happy to accept a PR and get it merged in and released for you. Thanks, Toby

tijnster commented 1 year ago

Hi @tobyclemson Yes, that's exactly what I'm trying to achieve. We are running the code from within a docker container, and programatically retrieving secrets from another microservice to talk with azure. Then we are setting the ARM ENV's to communicate with azure. In that perspective I don't think rspec-terraform will work (at least not for end 2 end, or actually deploying and verying infra), as there are no credentials available to communicate with azure. Or could I possible use a before hook for this? Rspec would be a good option though as it would be easier to include it in builds.

Nevertheless, I got some spare time this weekend. I've tried to look for a "way of working" for contributing, but did not find anything. Is there something like that available?