Module: VagrantPlugins::TerraformProvider::Util::UpdateVmState
- Included in:
- Action::HaltVM, Action::StartVM
- Defined in:
- lib/vagrant-terraform/util/update_vm_state.rb
Class Method Summary collapse
Class Method Details
.update_vm_state(file_path, new_state) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/vagrant-terraform/util/update_vm_state.rb', line 8 def update_vm_state(file_path, new_state) # Read the file contents lines = File.readlines(file_path) # Update the line containing "vm_state" updated_lines = lines.map do |line| if line.strip.start_with?("vm_state") line.gsub(/vm_state\s*=\s*".*"/, "vm_state = \"#{new_state}\"") else line end end # Write the updated contents back to the file File.open(file_path, "w") do |file| file.puts(updated_lines) end end |