-
-
Notifications
You must be signed in to change notification settings - Fork 46
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
terraspace build creates \r\n and invalid TF code on Windows #209
Comments
Wondering if this quick fix will do the trick. https://stackoverflow.com/questions/30195652/how-to-stop-ruby-automatically-adding-carriage-returns Try throwing this at the top of: lib/terraspace.rb $\ = "\n" And then running again
Thanks for the help testing |
Sadly enough it didn't work :( It only happens with |
Where is the actual file written? I can try this perhaps: https://stackoverflow.com/a/30213816/4329 |
File is written here.
|
def write(content)
FileUtils.mkdir_p(File.dirname(dest_path))
if content.respond_to?(:path) # IO filehandle
FileUtils.cp(content.path, dest_path) # preserves permission
else # just content
my_file = Tempfile.new("tmp.tf")
my_file.binmode
my_file.print content
my_file.close
FileUtils.mv(my_file.path, dest_path)
# IO.write(dest_path, content)
end
logger.debug "Created #{Terraspace::Util.pretty_path(dest_path)}"
end This writes it out correctly :D Now to play with it if |
Sweet 🎊 Will take a look adding a write shim method that uses that for Windows and regular Note: The temp file name will have to be uniquely generated. As |
I'm trying to figure out how IO.write works :) I found: https://ruby-doc.org/core-3.0.2/IO.html#method-c-new which says we can open for But when I try
So I am trying to find what's needed to use |
I found https://ruby-doc.org/core-3.0.2/IO.html#method-c-write
Trying to get that to work now, I already know this is the wrong syntax: Learning Ruby along the way |
Got it!
That's the fix needed for Windows, nothing more ps, "binary" is a very confusing term in Ruby, it actually means this:
|
Here you go: #210 |
write files without magic conversion, fixes #209
Checklist
My Environment
Expected Behaviour
terraspace build
files exactly as they areCurrent Behavior
Files using CRLF as line endings get formatted incorrectly, causing TF to fail.
Step-by-step reproduction instructions
I have this in my
Terrafile
:One of the files looks like this in the vendor folder:
After running
terraspace build
it gets turned into this:Which causes a lot of errors:
If I run
dos2unix
on the files, it works.Solution Suggestion
Find out why Ruby does this to the files and avoid it if possible?
The text was updated successfully, but these errors were encountered: