Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Latest ruby-terraform causing issues with Logging config #87

Open
plukevdh opened this issue Sep 9, 2024 · 5 comments
Open

Latest ruby-terraform causing issues with Logging config #87

plukevdh opened this issue Sep 9, 2024 · 5 comments

Comments

@plukevdh
Copy link

plukevdh commented Sep 9, 2024

This may be a problem with my config rather than the library, but bumping to

  • rspec-terraform - 0.5.0.pre.9
  • ruby-terraform - 1.8.0

Causes an issue trying to run my terraform specs, form of

expected #<Logger::LogDevice:0x000000011d21fcf0 @shift_period_suffix="%Y%m%d", @shift_size=1048576, @shift_age=7, @filename="/dev/null", @dev=#<File:/dev/null>, @binmode=false, @reraise_write_errors=[], @mon_data=#<Monitor:0x0000000121a1ae88>, @mon_data_owner_object_id=4340> to respond to :to_io

where my spec_helper.rb includes the following (which worked in the rspec-terraform - 0.4.0 / ruby-terraform - 1.7.0 combo):

RSpec.configure do |config|
  config.terraform_log_level = :warn
  config.terraform_stdout = Logger::LogDevice.new(IO::NULL) unless debug?
  # ...

I think this is originating in the expectations of what MultiIO or the logging subsystem in ruby-terraform is returning now but I've not had a ton of luck trying to figure out how this changed.

If I omit the config line altogether, I get

expected #<RubyTerraform::MultiIO:0x000000012da579f8 @targets=[#<Logger::LogDevice:0x000000012a17afb8 @shift_period_suffix=nil, @shift_size=nil, @shift_age=nil, @filename=nil, @dev=#<IO:<STDOUT>>, @binmode=false, @reraise_write_errors=[], @mon_data=#<Monitor:0x000000012da59118>, @mon_data_owner_object_id=5240>]> to respond to :to_io
@tobyclemson
Copy link
Member

Hmm apologies, this looks like a regression.

I'll take a look and try and get a fix together.

@tobyclemson
Copy link
Member

@plukevdh I'm going to give some context here that may help you solve your problem while we come up with a better solution.

We recently made some large scale changes to lino which is used by ruby-terraform to build and execute child processes. The reason for those changes was to prefer issuing commands as arrays rather than strings to remove the need for complex quoting and increase security. We were also experiencing some issues with interactive shells being switched to non-interactive by lino which would cause some commands to change their behaviour when invoked via lino. To solve for these needs, we switched the default process spawning library from open4 to childprocess which allows parent streams and environment to be inherited correctly.

However, in making that switch, the requirements on provided streams have changed. It turns out open4 opens new streams for the child process and then pipes everything written to child streams to parent streams. As such, the streams provided to open4 can be anything that responds to #<< or #write. However, for true parent stream inheritance, a true instance of IO is required, rather than a duck typed instance. Specifically, the stream needs to respond to #to_io which is used in childprocess to ensure the provided stream object is a true IO instance.

A Logger::LogDevice is not a descendant of IO and that's the reason for your error. Nor is a Logger so that wouldn't solve the problem either. The requirement is now that the object provided to terraform_stdout must be a true IO, so a File, a *Socket or an IO.pipe. In your case, I think you could set it to IO::NULL and things would work as expected. I'm not sure if you will require additional rspec-terraform configuration to also override the logger in that case.

Another option is to switch back to the open4 executor since everything was working for you before with that, using:

Lino.configure do |config|
  config.executor = Lino::Executors::Open4.new
end

Let me know how it goes and we'll try and find a good solution and update the docs.
Thanks,
Toby

@plukevdh
Copy link
Author

Ah, thanks for the details here. I will look at swapping for one of the two options and try to write back here what ends up being the easiest/most convenient here. Appreciate the extensive writeup on the changes.

@plukevdh
Copy link
Author

plukevdh commented Jan 15, 2025

Back after a long time away on this. I've tried the following without success and generally the same error:
config.terraform_stdout = IO.new(IO.sysopen(IO::NULL, 'w')) returns

expected #<RubyTerraform::MultiIO:0x000000011c655910 @targets=[#<Logger::LogDevice:0x000000011c21eba8 @shift_period_suffix=nil, @shift_size=nil, @shift_age=nil, @filename=nil, @dev=#<IO:<STDERR>>, @binmode=false, @reraise_write_errors=[], @mon_data=#<Monitor:0x000000011c6569c8>, @mon_data_owner_object_id=5300>]> to respond to :to_io

However, removing the entire config for terraform options, i continue to get the same error.

@plukevdh
Copy link
Author

The Lino.configure fix does resolve however.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants