Class: VagrantPlugins::TerraformProvider::Action::HaltVM

Inherits:
Object
  • Object
show all
Includes:
Util::TerraformExecute, Util::UpdateVmState
Defined in:
lib/vagrant-terraform/action/halt_vm.rb

Instance Method Summary collapse

Methods included from Util::UpdateVmState

update_vm_state

Methods included from Util::TerraformExecute

terraform_execute

Constructor Details

#initialize(app, env) ⇒ HaltVM

Returns a new instance of HaltVM.



14
15
16
17
# File 'lib/vagrant-terraform/action/halt_vm.rb', line 14

def initialize(app, env)
  @logger = Log4r::Logger.new("vagrant_terraform::action::halt_vm")
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/vagrant-terraform/action/halt_vm.rb', line 19

def call(env)

  env[:ui].info(I18n.t("vagrant_terraform.halt_vm"))

  begin
    terraform_dir = ".vagrant/terraform/#{env[:machine].id}"
    terraform_main_file = "#{terraform_dir}/main.tf"
    update_vm_state(terraform_main_file, "stopped")
    terraform_execute(env, 'terraform apply -auto-approve')
  rescue Exception => e
    # TODO: need to retry in some case?
    # retry if e.message =~ /something/
    raise e
  end

  @app.call(env)
end