Class: VagrantPlugins::TerraformProvider::Action::StartVM
- Inherits:
-
Object
- Object
- VagrantPlugins::TerraformProvider::Action::StartVM
- Includes:
- Util::TerraformExecute, Util::UpdateVmState
- Defined in:
- lib/vagrant-terraform/action/start_vm.rb
Overview
Just start the VM.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, env) ⇒ StartVM
constructor
A new instance of StartVM.
Methods included from Util::UpdateVmState
Methods included from Util::TerraformExecute
Constructor Details
#initialize(app, env) ⇒ StartVM
Returns a new instance of StartVM.
15 16 17 18 |
# File 'lib/vagrant-terraform/action/start_vm.rb', line 15 def initialize(app, env) @logger = Log4r::Logger.new("vagrant_terraform::action::start_vm") @app = app end |
Instance Method Details
#call(env) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/vagrant-terraform/action/start_vm.rb', line 20 def call(env) config = env[:machine].provider_config env[:ui].info(I18n.t("vagrant_terraform.starting_vm")) begin terraform_dir = env[:machine_tf_dir] terraform_main_file = "#{terraform_dir}/main.tf" update_vm_state(terraform_main_file, "running") terraform_execute(env, 'terraform apply -auto-approve') rescue Exception => e = /Error was \"\[?(.+?)\]?\".*/.match(e.)[1] rescue e. # TODO: retry in some case? # retry if e.message =~ /something/ if e. !~ /VM is running/ if config.debug raise e else raise Errors::StartVMError, :error_message => end end end @app.call(env) end |